CentOS 7.x 安裝 PXE Server

參考網頁:
Linux . 無限: 在 CentOS7/RHEL7 上架設 PXE 系統(一)
Install PXE Server On CentOS 7 | Unixmen
CentOS 7 : PXE Boot : Network Install : Server World
Install PXE Server And Configure PXE Client On CentOS 7 | Unixmen
CentOS 7 : PXE Boot : Configure PXE Server : Server World

1. 安裝所需套件
# yum install tftp-server dhcp syslinux vsftpd httpd

2. 設定 DHCP Server
# vim /etc/dhcp/dhcpd.conf
Authoritative;
default-lease-time                      259200;
max-lease-time                          518400;
option routers                          192.168.1.254;
option broadcast-address                192.168.1.255;
option subnet-mask                      255.255.255.0;
option domain-name-servers              168.95.1.1,140.111.66.1,8.8.8.8;
ddns-update-style                       interim;
ignore client-updates;
allow booting;
allow bootp;
allow unknown-clients;
server-name                             pxis;

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.56 192.168.1.60;
    option subnet-mask                  255.255.255.0;
    option domain-name                  “test.ilc.edu.tw”;
    next-server 192.168.1.41;
    filename “pxelinux.0”;

}[@more@]3. 設定 tftp Server
# cp /usr/lib/systemd/system/tftp.service /root/tftp.service.$(date +%F)
# vim /usr/lib/systemd/system/tftp.service
[Unit]
Description=Tftp Server
Requires=tftp.socket
Documentation=man:in.tftpd

[Service]
ExecStart=/usr/sbin/in.tftpd -s /tftpboot
StandardInput=socket

[Install]
Also=tftp.socket

4. 複製 syslinux 必要檔案到 tftp Server 分享的目錄
# cd /usr/share/syslinux
# cp pxelinux.0 menu.c32 memdisk mboot.c32 chain.c32 /tftpboot

5. 在 tftp Server 目錄下,建立可供 Linux 開機核心的目錄
# mkdir /tftpboot/{pxelinux.cfg,netboot}

6. 將 Linux ISO 檔內容複製到 vfftpd Server 目錄
# mount -o loop CentOS-LEMP-7.3-x86_64-1611_20170320.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
# cp -a /mnt/* /var/ftp/pub

7. 將 Linux PXE 開機核心檔案,複製到 vfftpd Server 目錄
# cd /var/ftp/pub/images/pxeboot
# cp vmlinuz initrd.img /tftpboot/netboot

8. 複製 CentOS Linux 自動安裝設定檔 ks.cfg 到 /var/ftp/pub  目錄之下
# cp /root/ks.cfg /var/ftp/pub
# chmod 644 /var/ftp/pub/ks.cfg

9. 修改 SELinux 相關設定
# yum install policycoreutils-python
# semanage fcontext -a -t public_content_t “/tftpboot(/.*)?”
# restorecon -F -R -v /tftpboot
# restorecon -R -F -v /var/ftp/pub/

10. 建立 PXE Server 開機選單
# vim /tftpboot/pxelinux.cfg/default
default menu.c32
prompt 0
timeout 30
MENU TITLE example.com PXE Menu
LABEL CentOS7_x64
MENU LABEL CentOS 7.3 x86_64
KERNEL /netboot/vmlinuz
APPEND initrd=/netboot/initrd.img inst.repo=ftp://192.168.5.104/pub ks=ftp://192.168.5.104/pub/ks.cfg

11. 啟動相關服務
# systemctl enable vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service
# systemctl start vsftpd
# systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
# systemctl start tftp
# systemctl daemon-reload
# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
# systemctl start dhcpd
# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service
# systemctl start httpd

12. 防火牆上設定
# firewall-cmd –permanent –add-service=dhcp
# firewall-cmd –permanent –add-service=ftp
# firewall-cmd –permanent –add-service=http
# firewall-cmd –permanent –add-service=tftp
# firewall-cmd –reload