準備:
DHCP伺服器
TFTP伺服器
FTP伺服器
Kickstart檔案
擁有PXE ROM晶片,支援網絡啟動的用戶端,即要安裝系統的裸機
Linux鏡像檔案
這裡用一台主機同時提供DHCP,TFTP,FTP三種服務,kickstart也放在這台伺服器上。
原理
遠端用戶端計算機啟動,由于BIOS設定了網卡啟動,是以網卡PXE ROM中的程式被調入記憶體執行。首先,用戶端在網絡中尋找DHCP伺服器,然後請求一個IP位址;同時DHCP伺服器聯系到TFTP伺服器為此用戶端發送一個bootstrap(引導程式)。用戶端收到bootstrap(檔案pxelinux.0)後執行,bootstrap會請求TFTP傳送bootstrap的配置檔案(pxelinux.cfg)。收到後讀配置檔案。根據配置檔案内容和客戶情況,用戶端請求TFTP傳送核心映象檔案(vmlinuz)和根檔案系統檔案(initrd.img)。最後啟動核心。這就是一個完整的pxe建構過程。然而要使網卡啟動後再繼續網絡安裝系統,則最後還需要FTP服務将系統所需安裝檔案放置FTP相應目錄中進行傳輸安裝。
安裝
#yum –disablerepo=\* --enablerepo=c5-mediainstall dchp* tftp* ftp* system-config-kickstart*
配置服務
安裝完DHCP後,其配置檔案為空。我們可以根據其文檔中的樣本修改
[r[email protected] ~]# cat/usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample >> /etc/dhcpd.conf
然後修改其内容
[[email protected] ~]# vi /etc/dhcpd.conf
ddns-update-style interim;
ignore client-updates;
allow booting; #新添加
allow bootp; #新添加
subnet 192.168.128.0 netmask 255.255.255.0{
# --- default gateway
option routers 192.168.128.1;
option subnet-mask 255.255.255.0;
option nis-domain "domain.org";
option domain-name "domain.org";
# option domain-name-servers 192.168.128.1; #注釋此行,以加快啟動
option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# --- Selects point-to-point node (defaultis hybrid). Don't change this unless
# -- you understand Netbios very well
# option netbios-node-type 2;
range dynamic-bootp 192.168.128.150 192.168.128.200;
filename "/pxelinux.0"; #指定啟動檔案
next-server 192.168.128.111; #指定伺服器IP
default-lease-time 21600;
max-lease-time 43200;
# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.redhat.com;
hardware ethernet12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}
修改TFTP的配置
[[email protected] ~]# cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves filesusing the trivial file transfer \
# protocol. The tftp protocol isoften 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 = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s/tftpboot
disable = no #将yes改為no
per_source = 11
cps = 100 2
flags = IPv4
}
FTP使用匿名登入,使用預設目錄/var/ftp,配置不做修改,隻需将linux鏡像檔案放在/var/ftp下。
[[email protected] ~]# ls /var/ftp/cdrom/
CentOS images RELEASE-NOTES-cs RELEASE-NOTES-de.html RELEASE-NOTES-en_US RELEASE-NOTES-es.html RELEASE-NOTES-ja RELEASE-NOTES-nl.html RELEASE-NOTES-ro RPM-GPG-KEY-beta
EULA isolinux RELEASE-NOTES-cs.html RELEASE-NOTES-en RELEASE-NOTES-en_US.html RELEASE-NOTES-fr RELEASE-NOTES-ja.html RELEASE-NOTES-pt_BR RELEASE-NOTES-ro.html RPM-GPG-KEY-CentOS-5
GPL NOTES RELEASE-NOTES-de RELEASE-NOTES-en.html RELEASE-NOTES-es RELEASE-NOTES-fr.html RELEASE-NOTES-nl RELEASE-NOTES-pt_BR.html repodata TRANS.TBL
在TFTP服務安裝完後,會建立一個/tftpboot目錄,這個目錄便是我們用來放置bootstrap引導程式(pxelinux.0),bootstrap配置檔案(default),核心映像(vmlinuz)和檔案系統檔案(initrd.img)的。這裡我們需要先建立一個pxelinux.cfg目錄,并将default檔案放在其下。
[[email protected] ~]# ll /tftpboot/
總計 9828
-rw-r--r-- 1 root root 8056614 04-18 00:57initrd.img
-rw-r--r-- 1 root root 13148 04-19 20:22 pxelinux.0
drwxr-xr-x 2 root root 4096 04-20 18:40 pxelinux.cfg
-rw-r--r-- 1 root root 1953660 04-19 20:21vmlinuz
[[email protected] ~]# ll /tftpboot/pxelinux.cfg/
總計 8
-rwxr-xr-x 1 root root 396 04-19 22:03default
上述四個檔案的來源:
[[email protected] ~]# cp/usr/lib/syslinux/pxelinux.0 /tftpboot/
[[email protected] ~]# cd /var/ftp/cdrom/isolinux/
[[email protected] isolinux]# pwd
/var/ftp/cdrom/isolinux
[[email protected] isolinux]# cp initrd.imgisolinux.cfg vmlinuz /tftpboot/
這裡的isolinux.cfg就是我們的default檔案,我們需要更名并放在pxelinux.cfg目錄下
[[email protected] tftpboot]# mkdir pxelinux.cfg/
[[email protected] tftpboot]# mv isolinux.cfgpxelinux.cfg/
[[email protected] tftpboot]# cd pxelinux.cfg/
[[email protected] pxelinux.cfg]# mv isolinux.cfgdefault
default檔案我們還需要一些設定
[[email protected] pxelinux.cfg]# vi default
default linux
prompt 1
timeout 600
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
# ks=ftp://192.168.128.111/ks.cfg指向的是ftp伺服器/var/ftp下的檔案,這個檔案就是linux安裝的應答檔案,即我們前面說的Kickstart檔案
append ks=ftp://192.168.128.111/ks.cfg initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest
append -
kickstart檔案的制作可以參考Kickstart的配置和使用
最後要将ks.cfg檔案放在/var/ftp下
[[email protected] ftp]# ll
總計 24
drwxr-xr-x 7 root root 4096 04-19 23:04cdrom
-rw-r--r-- 1 root root 1399 04-20 20:41ks.cfg
drwxr-xr-x 2 root root 4096 04-20 20:43 pub
啟動服務
啟動DHCP服務
[[email protected] ftp]# service dhcpd start
啟動TFTP服務
[[email protected] ftp]# service xinetd start
啟動FTP服務
[[email protected] ftp]# service vsftpd start
至此,伺服器配置完成。
将裸機選擇從網絡啟動即可。
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIyZwpmLxcTO581NzADMxkDNzMTMvwFMy8CX0AjMxAjMvw1ckF2bsBXdvwFdl5mLuR2cj5Set1yZtl2Lc9CX6MHc0RHaiojIsJye.jpg)