一、构建DHCP服务器
yum -y install dhcp
cat > /etc/dhcp/dhcpd.conf <<EOF #DHCP配置文件
subnet 192.168.80.0 netmask 255.255.255.0 #分配网段
{ range 192.168.80.100 192.168.80.150; #分配IP范围
option domain-name-servers 192.168.80.10; #dns地址
option routers 192.168.80.1; #分配网关地址
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.80.10; #指定下一个服务器地址
filename "pxelinux.0"; #指定网卡引导文件名称
}
EOF
systemctl restart dhcpd
二、构建TFTP服务器(简单文件传输服务)
1.安装服务
yum -y install tftp-server
systemctl start tftp
systemctl stop firewalld
2.部署pxelinux.0文件
yum provides */pxelinux.0 #查询该文件由那个软件生成
yum -y install syslinux
rpm -ql syslinux | grep pxelinux.0 #查询文件位置
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
3.部署菜单文件
mkdir /var/lib/tftpboot/pxelinux.cfg
mount /dev/cdrom /mnt
cp /mnt/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
4.部署图形模块、背景图片、启动内核、驱动程序
cd /mnt/isolinux/
cp ./vesamenu.c32 ./splash.png ./vmlinuz ./initrd.img /var/lib/tftpboot
cd ~
三、构建web服务提供众多安装包
yum -y install httpd
mkdir /var/www/html/centos
mount /dev/cdrom /var/www/html/centos
systemctl restart httpd
四、使用system-config-kickstart 工具生成应答文件
yum -y install system-config-kickstart
system-config-kickstart #启动图形化界面,选择配置信息
cp /root/ks.cfg /var/www/html #将应答文件放在http服务共享
vim /var/lib/tftpboot/pxelinux.cfg/default
......
ks=http://192.168.80.10/ks.cfg
菜单文件
[root@localhost ~]# cat /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
timeout 600
display boot.msg
# Clear the screen when exiting the menu, instead of leaving the menu displayed.
# For vesamenu, this means the graphical background is still displayed without
# the menu itself for as long as the screen remains in graphics mode.
menu clear
menu background splash.png
menu title CentOS 7
menu vshift 8
menu rows 18
menu margin 8
#menu hidden
menu helpmsgrow 15
menu tabmsgrow 13
# Border Area
menu color border * #00000000 #00000000 none
# Selected item
menu color sel 0 #ffffffff #00000000 none
# Title bar
menu color title 0 #ff7ba3d0 #00000000 none
# Press [Tab] message
menu color tabmsg 0 #ff3a6496 #00000000 none
# Unselected menu item
menu color unsel 0 #84b8ffff #00000000 none
# Selected hotkey
menu color hotsel 0 #84b8ffff #00000000 none
# Unselected hotkey
menu color hotkey 0 #ffffffff #00000000 none
# Help text
menu color help 0 #ffffffff #00000000 none
# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none
# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none
# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none
# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
label linux
menu label ^Install CentOS 7 PXE
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.80.10/ks.cfg
应答文件
[root@localhost ~]# cat ks.cfg #生成的自动应答安装文件
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$HkS7FyXR$nFxWYEGj63PkVJD.L2mvu.
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://192.168.80.10/centos"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --fstype="xfs" --grow --size=1
%post --interpreter=/bin/bash
useradd lisi
echo 123 | passwd --stdin lisi
%end
%packages
@base
%end