一、服務器系統安裝
PXE服務器使用CentOS7-x86_64位系統。最好配置上網權限,這樣能夠用yum方便地安裝軟件包。
二、安裝TFTP服務
首先安裝tftp軟件包:yum install -y tftp-server
創建tftpboot目錄用做tftp服務器的根目錄:mkdir -p /tftpboot
編輯tftp配置文件/etc/xinetd.d/tftp:
# 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 = yes
user = root
server = /usr/sbin/in.tftpd
<span style="color:#FF0000;"> server_args = -s /tftpboot
disable = no</span>
per_source = 11
cps = 100 2
flags = IPv4
}
重啓xinetd服務:service xinetd restart三、獲得pxelinux.0文件
pxelinux.0文件在syslinux包中:
yum install -y syslinux
cp /usr/share/syslinux/pxelinux.0 /tftpboot/
四、安裝dhcp服務
首先安裝dhcp軟件包:yum install -y dhcp
編輯配置文件/etc/dhcp/dhcpd.conf:
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
#
allow booting; #定義能夠PXE啓動
allow bootp;
log-facility local4;
subnet 10.1.5.0 netmask 255.255.255.0 {
range 10.1.5.117 10.1.5.120;
option routers 10.1.1.1;
option subnet-mask 255.255.255.0;
filename "pxelinux.0";
default-lease-time 86400;
max-lease-time 172800;
host ns {
next-server 10.1.5.116;
hardware ethernet 88:51:fb:59:1c:9b;
}
}
重啓dhcpd服務:service dhcpd restart
如果range指定的IP範圍很小,在IP全部分配完畢後DHCP就不再分配IP。進行網絡引導時DHCP服務器不會分配IP並會出現:“no free leases”的LOG。解決方法是減小租約時間即,default-lease-time和max-lease-time的值,這個方法未經驗證,只是理論上應該可行。可靠的方法是清空租約文件:cat /dev/null > /var/lib/dhcpd/dhcpd.leases
五、安裝vsftpd服務
yum install -y vsftpd
禁用防火牆:systemctl stop firewalld.service
取消防火牆開機啓動:firewallsystemctl disable firewalld.service
關閉SELinux:setenforce 0;這種修改立時生效,但重啓後失效。
永久關閉SELinux:編輯/etc/selinux/config,設置:SELINUX=disabled,保存退出。這種修改只能重啓生效。
改變pub文件夾屬主,使ftp用戶能夠上傳數據:chown ftp /var/ftp/pub/
編輯/etc/vsftpd/vsftpd.conf,確保以下設置:
anonymous_enable=yes
anon_upload_enable=YES
anon_umask=022
重啓vsftpd服務:service vsftpd restart
上傳CentOS7 ISO文件到/var/ftp/pub/iso目錄下。其它目錄也可以,而且也不一定要用FTP上傳。
創建目錄用於掛載iso文件:mkdir -p /var/ftp/c7-64
掛載ISO:mount -o loop /var/ftp/pub/iso/CentOS-7-x86_64-DVD-1503-01.iso /var/ftp/c7-64/
六、準備文件
cp /var/ftp/c7-64/images/pxeboot/vmlinuz /tftpboot/vmlinuz.c7-64
cp /var/ftp/c7-64/images/pxeboot/initrd.img /tftpboot/initrd.img.c7-64
mkdir -p /tftpboot/pxelinux.cfg
編輯/tftpboot/pxelinux.cfg/default,填入如下內容:
default c7
prompt 1
timeout 100
display boot.msg
label c7
kernel vmlinuz.c7-64
append initrd=initrd.img.c7-64 method=ftp://10.1.5.116/c7-64 devfs=nomount
其中10.5.1.116是FTP服務器IP。
創建/tftpboot/boot.msg用於顯示信息:
###################################################
# #
# Input: #
# c7 to install CentOS7-64 #
# #
# Type Enter directly to install default OS #
# Default is c7 #
###################################################
七、安裝CentOS7
設置要安裝的機器啓動方式爲網絡引導,內存最好不小於2G。然後啓動:
鍵入c7,回車,或直接回車安裝默認系統,都可以安裝CentOS7。如果不做任何操作則10s後會超時安裝默認系統,現在這個默認也是CentOS7。接下來會進入CentOS7的安裝界面:
選擇完語言後繼續:
注意一定要等INSTALLATION SOURCE下面出現ftp://10.1.5.116字樣後才能選擇軟件包。雙擊SOFTWARE SELECTOIN可以選擇軟件包。然後雙擊INSTALLATION DESTINATION進行分區,完畢後就可以進行安裝了:
點擊“Begin installation”開始安裝:
雙擊ROOT PASSWORD設置root用戶密碼。普通用戶可以不設置。在Starting package installation process這步會停很長時間(大概10分鐘),要有耐心哦。