PXE(Preboot Execution Environment)讓客戶端通過網絡從服務器下載啟動映像並安裝作業系統。本文詳細記錄基於 CentOS 的 TFTP + DHCP 服務端配置、PXE 引導文件準備、啟動菜單定製及客戶端安裝全流程。
# 安裝核心服務 yum install tftp-server tftp dhcp # 檢查安裝 rpm -qa tftp* dhcp*
編輯 /etc/xinetd.d/tftp:
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -u nobody -s /tftpboot
disable = no # 關鍵:yes → no
per_source = 11
cps = 100 2
flags = IPv4
}
啟動:service xinetd restart
cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.confsubnet 192.168.12.0 netmask 255.255.255.0 {
option routers 192.168.12.1;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.12.1;
range dynamic-bootp 192.168.12.128 192.168.12.254;
default-lease-time 21600;
max-lease-time 43200;
# PXE 關鍵指令
next-server 192.168.12.1; # TFTP 服務器 IP
filename "pxelinux.0"; # 引導文件名
}service dhcpd restart && chkconfig dhcpd onyum install syslinuxcp /usr/share/syslinux/pxelinux.0 /tftpboot/ cp /usr/share/syslinux/menu.c32 /tftpboot/ cp /usr/share/syslinux/memdisk /tftpboot/ cp /usr/share/syslinux/mboot.c32 /tftpboot/
/tftpboot/pxelinux.cfg/default:DEFAULT menu.c32
PROMPT 0
TIMEOUT 300
MENU TITLE PXE Network Install
LABEL centos7
MENU LABEL ^1. Install CentOS 7 x64
KERNEL images/centos7/vmlinuz
APPEND initrd=images/centos7/initrd.img inst.repo=https://192.168.12.1/centos7 ks=https://192.168.12.1/ks.cfg
LABEL local
MENU LABEL ^2. Boot from local disk
LOCALBOOT 0mount -o loop CentOS-7-x86_64-DVD.iso /mnt && ln -s /mnt /var/www/html/centos7ks.cfg 實現完全無人值守安裝(分區、軟件包、網絡、root 密碼等)