PXE
PXE(preboot execute environment,預啓動執行環境)是由Intel公司開發的最新技術,工做於Client/Server的網絡模式,支持工做站經過網絡從遠端服務器下載映像,並由此支持經過網絡啓動操做系統,在啓動過程當中,終端要求服務器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)協議下載一個啓動軟件包到本機內存中執行,由這個啓動軟件包完成終端(客戶端)基本軟件設置,從而引導預先安裝在服務器中的終端操做系統。
PXE工做原理html
環境搭建
三臺虛擬機,一臺預裝centos系統,另外兩臺建立空機器就好(安裝centos7的機器最好配置1.5g以上內存),selinux關閉,iptables規則清空。
軟件需求
system-config-kickstart 圖形化的工具,生成kickstart文件(要求圖形界面centos6和7的有必定區別,最好使用兩臺有圖形的機器去生成kickstart文件)
dhcp 搭建dhcp服務器給空白機器提供ip地址以便後續的系統部署
tftp 提供基礎系統引導文件
httpd或者ftp提供軟件包和kickstart文件的存儲和支持網絡訪問
syslinux 提供pxelinux.0文件
kickstart文件生成
首先安裝kickstart圖形化工具linux
yum install system-config-kickstart -y #我這裏已經裝過了就再也不重複安裝了
安裝完成後在終端輸入算法
system-config-kickstart
6和7這個程序的界面基本相同。
由於提供了中文,所以就不在過多截圖和說明。跟着指示一步一步選擇便可,所有選擇完成後能夠選擇「文件」進行保存。centos
kickstart文件的結構分析
centos6服務器
#platform=x86, AMD64, 或 Intel EM64T #version=DEVEL # Firewall configuration firewall --disabled # Install OS instead of upgrade 指明是安裝系統仍是升級系統 install # Use network installation 使用網絡安裝系統,指明包安裝路徑 url --url="http://192.168.99.150/centos/6" # Root password 設定root密碼 rootpw --iscrypted $1$83EH4TBr$Q.b9cbOc79IC4aXYbCO3A0 # System authorization information 密鑰加密算法啓用shadow文件 auth --useshadow --passalgo=sha512 # Use text mode install 使用文本模式或者圖形模式安裝系統 text # System keyboard 鍵盤設定 keyboard us # System language 語言設定 lang en_US # SELinux configuration selinux是否關閉 selinux --disabled # Do not configure the X Window System 是否安裝圖形界面 skipx # Installation logging level 日誌級別 logging --level=info # Reboot after installation 聲明安裝完成後重啓系統 reboot # System timezone 設置時區(能夠改爲亞洲上海) timezone Africa/Abidjan # System bootloader configuration 設定BootLoader bootloader --location=mbr # Clear the Master Boot Record 清除mbr記錄 zerombr # Partition clearing information 清除所有分區 clearpart --all --initlabel # Disk partitioning information 分區設定 part /boot --fstype="ext4" --size=200 part / --fstype="ext4" --size=16000 part swap --fstype="swap" --grow --size=2048 %packages 安裝的包設定(這裏僅僅最小化安裝) @core
centos7網絡
#platform=x86, AMD64, 或 Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us' # Root password rootpw --iscrypted $1$/oxkHD8i$x9g6m.ghBq2L3Vz6ENY7i0 # Use network installation url --url="http://192.168.99.150/centos/7" # System language lang en_US # System authorization information auth --useshadow --passalgo=sha512 # Use text mode install text # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # Firewall configuration firewall --disabled # Reboot after installation reboot # System timezone timezone Africa/Abidjan # System bootloader configuration bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /boot --fstype="xfs" --size=200 part / --fstype="xfs" --size=16000 part swap --fstype="swap" --grow --size=2048 %packages 安裝包選項最小化安裝 7在選擇完包以後要添加%end表示結束 @^minimal %end
1.安裝dhcpapp
yum install dhcp -y
2.建立dhcp地址段配置文件,安裝dhcp以後會默認生成示例文件,只要對示例文件進行簡單修改便可使用。ide
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
3.修改文件,添加如下字段工具
subnet 192.168.99.0 netmask 255.255.255.0 { #設定分配的子網和掩碼 range 192.168.99.160 192.168.99.200; #設定地址範圍 option subnet-mask 255.255.255.0; #設定掩碼 option routers 192.168.99.150; #指定網關地址 default-lease-time 86400; #設定租約期,不設定話默認是全局時間 max-lease-time 864000; #最大租約期,不設定繼承全局 next-server 192.168.99.150; #指定下一個服務器地址,用來指明提供ftp或者http服務的地址 filename "pxelinux.0"; }
4.啓動服務而且設定開機啓動加密
chkconfig dhcpd on service dhcpd start #centos 7 使用systemctl enable dhcpd systemctl start dhcpd
地址分配記錄,新配置的應該不會有記錄這裏是實驗完成後的記錄。
/var/lib/dhcpd/dhcpd.leases
1.經過yum方式安裝httpd而且開機啓動
yum install httpd -y chkconfig httpd on #centos7 #systemctl enable httpd
2.建立相應目錄掛載光盤文件(使用兩個光驅掛載以便節省磁盤空間)以及存放ks文件。要注意權限,最好在掛載完成後在宿主機網頁訪問一下。
mkdir -pv /var/www/html/centos/{6,7,ks} mount /dev/sr0 /var/www/html/centos/6/ mount /dev/sr1 /var/www/html/centos/7/ mv centos6.cfg centos7.cfg /var/www/html/ks/ #以前準備好的ks文件均爲最小化安裝
1.安裝tftp服務而且配置開機啓動
yum install tftp-server -y chkconfig tftp on chkconfig xinetd on (centos 6 tftp由xinetd管理) #centos7 # systemctl enable tftp
2.準備相關的啓動文件及目錄
mkdir /var/lib/tftpboot/pxelinux.cfg mkdir -pv /var/lib/tftpboot/centos{6,7} cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ cp /var/www/html/centos/6/isolinux/vesamenu.c32 /var/lib/tftpboot/ cp /var/www/html/centos/6/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos6/ cp /var/www/html/centos/7/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7/ cp /var/www/html/centos/6/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
3.修改default菜單文件
#僅僅修改label字段 label linux7 menu label Install centos^7 kernel centos7/vmlinuz #因爲是多版本部署因此要指明對應的路徑 append initrd=centos7/initrd.img text ks=http://192.168.99.150/centos/ks/centos7.cfg label linux6 menu label Install centos^6 kernel centos6/vmlinuz append initrd=centos6/initrd.img text ks=http://192.168.99.150/centos/ks/centos6.cfg
1.重啓httpd dhcpd xinetd服務
service httpd restart service dhcpd restart service xinetd restart #centos7使用systemctl命令重啓服務,centos7再也不使用xinetd管理tftp服務 #systemctl restart tftp
2.驗證服務端口是否正常啓動
ss -tunlp
3.配置3臺主機都到vmnat2段
4.啓動2臺空白虛擬機分別安裝centos6和centos7
5.靜靜等待安裝完成
centos6
centos7
.
實驗進行基本順利,感受對pxe過程的中的坑有了比較詳細的瞭解,下篇會繼續pxe的進階cobbler的配置。