一、准备工作
1、关闭防火墙和selinux
shell
systemctl stop firewalld && systemctl disable firewalld
setenforce 0
2、配置静态ip
需要在dhcp里面填写tftp配置,所以需要固定ip
二、dhcp安装配置
作用:给客户端提供ip地址,并告诉客户端tftp地址
shell
$ yum install -y dhcp
#默认dhcp配置文件为空
$ cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
#修改dhcp配置,仅列出修改部分,未修改部分保持默认即可
next-server 172.13.11.222; #tftp-server地址
filename "pxelinux.0"; #引导文件名称
subnet 172.13.11.0 netmask 255.255.255.0 {
range 172.13.11.200 172.13.11.222;
option domain-name-servers 114.114.114.114;
option domain-name "example.com";
option routers 172.13.11.254;
option broadcast-address 172.13.11.255;
default-lease-time 600;
max-lease-time 7200;
}
$ systemctl start dhcpd && systemctl enable dhcpd
三、安装tftp-server和http
shell
$ yum install -y tftp-server xinted
$ cat /etc/xinetd.d/tftp
disable = no #将yes改为no
$ systemctl start xinetd && systemctl enable xinetd
$ yum install httpd -y
$ systemctl start httpd && systemctl enable httpd
$ mkdir /var/www/html/pub/ #用来存放系统文件
$ mkdir /var/www/html/ks/ #用来存放ks自动应答文件
四、获取系统和引导文件
4.1、准备文件
shell
yum install syslinux -y
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux.cfg/default
#挂载光盘文件
$ cat /etc/fstab
/dev/cdrom /var/www/html/pub iso9660 defaults 0 0
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 40G 1.6G 39G 4% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 8.6M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sr0 918M 918M 0 100% /var/www/html/pub
...
$ cp /var/www/html/pub/isolinux/* /var/lib/tftpboot/
4.2、修改default的配置
shell
$ cat /var/lib/tftpboot/pxelinux.cfg/default
label mini
menu label ^Install mini CentOS 7.6
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://10.139.8.222/ks/ks.cfg
五、准备ks.cfg自动应答文件
shell
#检查ks语法是否正确
ksvalidator ks.cfg
shell
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$9DaKYCjW$zHgzt87pRI6u0miUdWbvh1
# 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=static --device=eth0 --gateway=172.13.11.254 --ip=172.13.11.200 --nameserver=114.114.114.114 --netmask=255.255.255.0
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://172.13.11.222/pub"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=200
part /home --fstype="xfs" --size=1024
part / --fstype="xfs" --grow --size=1
%packages
@^minimal
@core
chrony
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end