1 基于centos8实现PXE自动安装系统
红帽官方文档:
Syslinux参考站点:
https://wiki.syslinux.org/wiki/index.php?title=PXELINUX#Description
https://wiki.archlinux.org/index.php/Syslinux_(简体中文)
1.1 安装前准备
关闭防火墙和SELINUX,DHCP服务器静态IP
网络要求:关闭Vmware软件中的DHCP服务,基于NAT模式
主机分配:将所有服务安装在同一台服务器中
实现centos8的自动安装
1.2 安装相关软件包
#安装软件包
[root@centos8 ~]# yum -y install dhcp-server tftp-server httpd syslinux-nonlinux
#启动服务
[root@centos8 ~]# systemctl enable --now httpd tftp
#查看是否启动成功
[root@centos8 ~]# ss -ntul
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 *:69 *:*
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
tcp LISTEN 0 128 *:80 *:*
tcp LISTEN 0 128 [::]:22 [::]:*
1.3 配置DHCP服务
#默认/etc下dhcp文件是空的,所以先拷贝范例配置文件便于配置
[root@centos8 ~]# cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
#配置DHCP
[root@centos8 ~]# ip a
1: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:0c:29:ed:28:61 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.100/24 scope global ens160
valid_lft forever preferred_lft forever
[root@centos8 ~]# vim /etc/dhcp/dhcpd.conf #注意不要丢失尾部分号,否则启动不了服务
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.1 10.0.0.200;
option routers 10.0.0.1;
next-server 10.0.0.100;
filename "pxelinux.0";
}
#启动dhcp服务
[root@centos8 ~]# systemctl start dhcpd
1.4 准备yum 源和相关目录
#创建文件夹
[root@centos8 ~]# mkdir -pv /var/www/html/centos/8/os/x86_64/
mkdir: created directory '/var/www/html/centos'
mkdir: created directory '/var/www/html/centos/8'
mkdir: created directory '/var/www/html/centos/8/os'
mkdir: created directory '/var/www/html/centos/8/os/x86_64/'
[root@centos8 ~]# ll /var/www/html/centos/8/os/x86_64/ -d
drwxr-xr-x. 2 root root 6 Apr 29 01:52 /var/www/html/centos/8/os/x86_64/
#挂载本地光盘
[root@centos8 ~]# mount /dev/sr0 /var/www/html/centos/8/os/x86_64/
mount: /var/www/html/centos/8/os/x86_64: WARNING: device write-protected, mounted read-only.
#这时我们可以访问http://10.0.0.100/centos/8/os/x86_64/来验证是否成功
1.5 准备PXE启动相关文件
#创建文件夹
[root@centos8 ~]# mkdir /var/lib/tftpboot/centos8
#复制内核文件至tftp目录
[root@centos8 ~]# cp /var/www/html/centos/8/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos8/
#复制syslinux相关文件至tftp
[root@centos8 ~]# cp /usr/share/syslinux/{pxelinux.0,ldlinux.c32,menu.c32,libcom32.c32,libutil.c32} /var/lib/tftpboot/
[root@centos8 ~]# ll /var/lib/tftpboot/
total 160
drwxr-xr-x. 2 root root 39 Apr 30 00:02 centos8
-rw-r--r--. 1 root root 116096 Apr 30 01:05 ldlinux.c32
-rw-r--r--. 1 root root 42791 Apr 30 01:05 pxelinux.0
#生成菜单文件
[root@centos8 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg/
[root@centos8 ~]# cp /var/www/html/centos/8/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
1.6 准备kickstart文件
[root@centos8 ~]# mkdir /var/www/html/ks
[root@centos8 ~]# cat /var/www/html/ks/centos8.cfg
ignoredisk --only-use=sda
zerombr
text
reboot
clearpart --all --initlabel
selinux --disabled
firewall --disabled
url --url=http://10.0.0.100/centos/8/os/x86_64/
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=ens160 --ipv6=auto --activate
network --hostname=centos8.magedu.com
rootpw --iscrypted $6$18lCu5Jb7ncPFxK2$xu15Q3igR6OmU71EiUxuzEv7eic7sYdSmhE7kuRfZ8VfqwCrm/0AbojEgvIz0KXg4HntKbufBmnx/dgqsSvOY.
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
part / --fstype="xfs" --ondisk=sda --size=102400
part /data --fstype="xfs" --ondisk=sda --size=51200
part swap --fstype="swap" --ondisk=sda --size=2048
part /boot --fstype="ext4" --ondisk=sda --size=1024
%packages
@^minimal-environment
kexec-tools
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
%post
useradd test1
%end
1.7 配置启动菜单文件
[root@centos8 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
[root@centos8 ~]# cat /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600
menu title CentOS Linux 8
label linux8
menu label ^Install CentOS Linux 8
kernel centos8/vmlinuz
append initrd=centos8/initrd.img ks=http://10.0.0.100/ks/centos8.cfg
label manual
menu label ^Manual Install CentOS Linux 8.0
kernel centos8/vmlinuz
append initrd=centos8/initrd.img
inst.repo=http://10.0.0.100/centos/8/os/x86_64/
label rescue
menu label ^Rescue a CentOS Linux system 8
kernel centos8/vmlinuz
append initrd=centos8/initrd.img
inst.repo=http://10.0.0.100/centos/8/os/x86_64/ rescue
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
1.8 测试客户端基于PXE实现自动安装
菜单选择界面
系统自动安装完成后查看是否成功创建test1用户