Linux系統——PXE高效能批量網路裝機
PXE:Pre-boot Excution Environment,預啟動執行環境,石油Intel公司開發的網路引導技術,工作在Client、Server模式,允許客戶機通過網路從遠端伺服器下載陰道映象,並記載安裝檔案或者整個作業系統。
搭建PXE網路體系,必須要滿足一下條件:
1. 客戶機的網絡卡支援PXE協議(整合BOOTROM晶片),且主機板支援網路引導。
2. 網路中有一臺DHCP伺服器,一邊為客戶機分配地址、指定引導檔案位置
伺服器通過TFTP簡單檔案傳輸協議提供引導映象檔案的下載。
工作過程:
工作站開機後,PXE BootROM(自啟動晶片)獲得控制權之前先做自我測試,然後以廣播形式發出一個請求FIND幀。如果伺服器收到工作站所送出的要求,就會送回DHCP迴應,內容包括使用者端的IP地址,預設通訊通道及開機應許昂檔案。否則,伺服器會忽略這個要求。工作站收到伺服器發回的響應後則會迴應一個幀,以請求傳送啟動所需檔案。之後,將有更多的訊息在工作站與伺服器之間作應答,用以決定啟動引數。BootROM由TFTP通訊協議從伺服器下載開機映像檔,這個映像檔就是軟盤的映像檔案。工作站樹勇TFTP協議接受啟動檔案後,將控制權轉交啟動快,引導作業系統,完成遠端啟動。
#### 搭建PXE遠端安裝伺服器
1. 安裝並啟動TFTP服務
```
[[email protected] ~]# mkdir -p /var/ftp/centos6
[[email protected] ~]# cd /var/ftp/centos6/
[[email protected] centos6]# cp -rp /media/cdrom/* .
[[email protected] ~]# mount /dev/sr0 /media/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# yum -y install tftp-server
[
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = no # 無需等待,同一時刻可以多個客戶端連線
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot #tftp服務的根目錄
disable = no #開啟tftp服務
per_source = 11
cps = 100 2
flags = IPv4
}
```
2. 啟動tftp
```
[[email protected] centos6]# /etc/init.d/xinetd start
Starting xinetd: [ OK ]
[[email protected] centos6]# chkconfig tftp on
```
3. 準備Linux核心、初始化映象檔案
```
[[email protected] ~]# cd /var/ftp/centos6/isolinux/
[[email protected] isolinux]# ls
boot.cat initrd.img memtest vesamenu.c32
boot.msg isolinux.bin splash.jpg vmlinuz
grub.conf isolinux.cfg TRANS.TBL
[[email protected] isolinux]# cp vmlinuz initrd.img /var/lib/tftpboot/
[[email protected] isolinux]# ls /var/lib/tftpboot/
initrd.img vmlinuz
```
4. 準備PXE載入程式、啟動選單檔案
準備載入程式
```
[[email protected] isolinux]# yum -y install syslinux
[[email protected] isolinux]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[[email protected] isolinux]# ls /var/lib/tftpboot/
initrd.img pxelinux.0 vmlinuz
[[email protected] isolinux]#
```
準備啟動選單
```
[[email protected] ~]# cp /var/ftp/centos6/isolinux/isolinux.cfg /var/lib/tftpboot/
[[email protected] ~]# cd /var/lib/tftpboot/
[[email protected] tftpboot]# chmod 644 isolinux.cfg
[[email protected] tftpboot]# vim isolinux.cfg
default linux #改個名字
prompt 0 #不進行互動
#timeout 600
display boot.msg
#menu background splash.jpg
#menu title Welcome to CentOS 6.5!
#menu color border 0 #ffffffff #00000000
#menu color sel 7 #ffffffff #ff000000
#menu color title 0 #ffffffff #00000000
#menu color tabmsg 0 #ffffffff #00000000
#menu color unsel 0 #ffffffff #00000000
#menu color hotsel 0 #ff000000 #ffffffff
#menu color hotkey 7 #ffffffff #ff000000
#menu color scrollbar 0 #ffffffff #00000000
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img
label text #對原資料進行更改
menu label Install system with ^basic video driver
kernel vmlinuz
append text initrd=initrd.img xdriver=vesa nomodeset #對原資料進行更改
label rescue
menu label ^Rescue installed system
kernel vmlinuz
append rescue initrd=initrd.img rescue #對原資料進行更改
label local
menu label Boot from ^local drive
localboot 0xffff
label memtest86
menu label ^Memory test
kernel memtest
append -
[[email protected] tftpboot]# cd /var/lib/tftpboot/
[[email protected] tftpboot]# mkdir pxelinux.cfg
[[email protected] tftpboot]# mv isolinux.cfg ./pxelinux.cfg/default
```
5. 安裝並啟動DHCP服務(pxe服務端)
```
[[email protected] tftpboot]# yum -y install dhcp
[[email protected] tftpboot]# cp /usr/share/doc/dhcp*/dhcpd.conf.sample .
[[email protected] tftpboot]# cat dhcpd.conf.sample > /etc/dhcp/dhcpd.conf
[[email protected] tftpboot]# vim /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks...
option domain-name "www.yunjisuan.com";
option domain-name-servers 192.168.239.2;
default-lease-time 21600;
max-lease-time 43200;
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
# This is a very basic subnet declaration.
subnet 192.168.239.0 netmask 255.255.255.0 {
range 192.168.239.100 192.168.239.200;
option routers 192.168.239.2;
next-server 192.168.239.132; #PXE的IP地址
filename "pxelinux.0";
}
[[email protected] tftpboot]# /etc/init.d/dhcpd start
Starting dhcpd: [ OK ]
[[email protected] tftpboot]# netstat -antup | grep 67
udp 0 0 0.0.0.0:67 0.0.0.0:* 1528/dhcpd
[[email protected] tftpboot]# yum -y install vsftpd
[[email protected] tftpboot]# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd: [ OK ]
```
6. 測試連線ftp功能(pxe客戶端)
```
[[email protected] ~]# mount /dev/sr0 /media/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# yum -y install ftp
[[email protected] ~]# ftp 192.168.239.132
Connected to 192.168.239.132 (192.168.239.132).
220 (vsFTPd 2.2.2)
Name (192.168.239.132:root): ftp
331 Please specify the password.
Password: #密碼為空
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
227 Entering Passive Mode (192,168,239,132,90,93).
150 Here comes the directory listing.
drwxr-xr-x 7 0 0 4096 Dec 02 15:32 centos6
drwxr-xr-x 2 0 0 4096 Mar 22 2017 pub
226 Directory send OK.
ftp> cd centos6
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,239,132,90,223).
150 Here comes the directory listing.
-r--r--r-- 1 0 0 14 Nov 29 2013 CentOS_BuildTag
dr-xr-xr-x 3 0 0 4096 Nov 29 2013 EFI
-r--r--r-- 1 0 0 212 Nov 27 2013 EULA
-r--r--r-- 1 0 0 18009 Nov 27 2013 GPL
dr-xr-xr-x 2 0 0 282624 Nov 29 2013 Packages
-r--r--r-- 1 0 0 1354 Nov 27 2013 RELEASE-NOTES-en-US.html
-r--r--r-- 1 0 0 1706 Nov 27 2013 RPM-GPG-KEY-CentOS-6
-r--r--r-- 1 0 0 1730 Nov 27 2013 RPM-GPG-KEY-CentOS-Debug-6
-r--r--r-- 1 0 0 1730 Nov 27 2013 RPM-GPG-KEY-CentOS-Security-6
-r--r--r-- 1 0 0 1734 Nov 27 2013 RPM-GPG-KEY-CentOS-Testing-6
-r--r--r-- 1 0 0 3380 Nov 29 2013 TRANS.TBL
dr-xr-xr-x 3 0 0 4096 Nov 29 2013 images
dr-xr-xr-x 2 0 0 4096 Nov 29 2013 isolinux
dr-xr-xr-x 2 0 0 4096 Nov 29 2013 repodata
226 Directory send OK.
ftp> exit
221 Goodbye.
```
7. 新建虛擬機器進行驗證
(1)調整BIOS,一邊從網路引導(不調整預設從網路引導)
在工具欄的【虛擬機器】選項,選擇【電源】,點選【開啟電源時進入韌體】進入BIOS介面,將network boot from Intel E1000調整到第一位
(2)自動獲取IP地址,並指向centos安裝源
在URL setup輸入ftp的URL(連線對方的IP地址),進行正常裝機
#### 實現kickstart無人值守安裝
1. 建立應答檔案
```
[[email protected] ~]# mount /dev/sr0 /media/cdrom
[[email protected] ~]# yum -y install system-config-kickstart
```