安装前准备:
关闭防火墙和SELINUX,DHCP服务器静态IP
网络要求:关闭Vmware软件中的DHCP服务,基于NAT模式
注意:内存2G+ 磁盘 200G+
1、安装相关软件包并启动
dhcp-server tftp-server httpd syslinux-nonlinux(或者syslinux-tftpboot)
[root@cent8_yzil ~]# yum -y install dhcp-server tftp-server httpd syslinux-nonlinux
[root@cent8_yzil ~]# systemctl enable --now httpd tftp dhcpd
2、配置DHCP服务
[root@cent8_yzil ~]# cp /usr/share/doc/dhcp-server/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@cent8_yzil ~]# vim /etc/dhcp/dhcpd.conf
option domain-name-servers 180.76.76.76, 223.5.5.5;
default-lease-time 86400;
max-lease-time 106400;
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.150 10.0.0.160;
option routers 10.0.0.2;
next-server 10.0.0.133;
filename "pxelinux.0";
}
[root@cent8_yzil ~]# systemctl enable --now dhcpd
3、准备yum源和相关目录
[root@cent8_yzil ~]# mkdir -pv /var/www/html/centos/{7,8}/os/x86_64/
[root@cent8_yzil ~]# scandisk
[root@cent8_yzil ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─cl-root 253:0 0 17G 0 lvm /
└─cl-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 6.7G 0 rom /run/media/root/CentOS-8-BaseOS-x86_64
sr1 11:1 1 4.4G 0 rom /run/media/root/CentOS 7 x86_64
[root@cent8_yzil ~]#
[root@cent8_yzil ~]# mount /dev/sr1 /var/www/html/centos/7/os/x86_64/
[root@cent8_yzil ~]# mount /dev/sr0 /var/www/html/centos/8/os/x86_64/
通过浏览器访问验证:
4、准备kickstart文件
#centos8应答文件
[root@cent8_yzil ~]# mkdir /var/www/html/ks/
[root@cent8_yzil ~]# cp anaconda-ks.cfg /var/www/html/ks/centos8.cfg
[root@cent8_yzil ~]# vi /var/www/html/ks/centos8.cfg
[root@cent8_yzil ks]# cat centos8.cfg
ignoredisk --only-use=sda
zerombr
text
reboot
clearpart --all --initlabel
selinux --disabled
firewall --disabled
url --url=http://10.0.0.133/centos/8/os/x86_64/
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
network --hostname=yzil.example.com
rootpw --iscrypted $6$VOiiEwlRHR.Stjdu$gUfB1Tm8Uz03zv/0lLJABR/obcWOdAG50PhPHu08vFwtQZtNf1RWstodv3TCEznSQdFnFIOYT116ft.8gu6Ca/
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
#autopart --type=lvm
#part / --fstype xfs --size 1 --grow --ondisk sda
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
[root@cent8_yzil ks]#
#centos7应答文件
[root@cent8_yzil ~]# scp 10.0.0.123:anaconda-ks.cfg /var/www/html/ks/centos7.cfg
[email protected]'s password:
anaconda-ks.cfg 100% 2757 9.7KB/s 00:00
[root@cent8_yzil ~]# vi /var/www/html/ks/centos7.cfg
[root@cent8_yzil ks]# cat centos7.cfg
install
xconfig --startxonboot
keyboard --vckeymap=us --xlayouts='us'
url --url="http://10.0.0.133/centos/7/os/x86_64"
lang en_US
text
firstboot --enable
selinux --disabled
skipx
services --disabled="chronyd"
ignoredisk --only-use=sda
firewall --disabled
network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
network --hostname=yzil.example.com
rootpw --iscrypted $6$VOiiEwlRHR.Stjdu$gUfB1Tm8Uz03zv/0lLJABR/obcWOdAG50PhPHu08vFwtQZtNf1RWstodv3TCEznSQdFnFIOYT116ft.8gu6Ca/
reboot
timezone Asia/Shanghai --nontp
zerombr
#autopart --type=lvm
clearpart --all --initlabel
part swap --fstype="swap" --ondisk=sda --size=3072
part / --fstype="xfs" --ondisk=sda --size=51200
part /boot --fstype="xfs" --ondisk=sda --size=1024
part /data --fstype="xfs" --ondisk=sda --size=30720
%post
useradd wang
%end
%packages
@core
%end
[root@cent8_yzil ks]# vi centos7.cfg
注意权限问题,默认是只有root才能读写
[root@cent8_yzil ~]# ll anaconda-ks.cfg
-rw-------. 1 root root 1237 Apr 9 15:53 anaconda-ks.cfg
[root@cent8_yzil ~]#
[root@cent8_yzil ~]# cd /var/www/html/ks/
[root@cent8_yzil ks]# ls
centos7.cfg centos8.cfg
[root@cent8_yzil ks]# chmod 644 *
[root@cent8_yzil ks]# ll
total 8
-rw-r--r--. 1 root root 841 Apr 29 04:32 centos7.cfg
-rw-r--r--. 1 root root 1386 Apr 29 06:50 centos8.cfg
[root@cent8_yzil ks]#
5、准备PXE启动相关文件
#准备centos7,8各自的内核相关文件
[root@cent8_yzil ~]# mkdir /var/lib/tftpboot/centos{7,8}
[root@cent8_yzil ~]# cp /var/www/html/centos/7/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos7
[root@cent8_yzil ~]# cp /var/www/html/centos/8/os/x86_64/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/centos8
[root@cent8_yzil ~]# cp /usr/share/syslinux/{pxelinux.0,menu.c32} /var/lib/tftpboot/
#以下三个文件是centos8安装所必须文件,centos6,7则不需要
[root@cent8_yzil ~]# cp /var/www/html/centos/8/os/x86_64/isolinux/{ldlinux.c32,libcom32.c32,libutil.c32} /var/lib/tftpboot/
#生成安装菜单文件
[root@cent8_yzil ~]# mkdir /var/lib/tftpboot/pxelinux.cfg/
[root@cent8_yzil ~]# cp /var/www/html/centos/8/os/x86_64/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
#最终目录结构如下
[root@cent8_yzil ~]# tree /var/lib/tftpboot/
/var/lib/tftpboot/
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── centos8
│ ├── initrd.img
│ └── vmlinuz
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
└── default
3 directories, 10 files
[root@cent8_yzil ~]#
6、准备启动菜单文件
[root@cent8_yzil ~]# cat /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
timeout 600
menu title Install CentOS Linux
label linux8
menu label Auto Install CentOS Linux ^8
kernel centos8/vmlinuz
append initrd=centos8/initrd.img ks=http://10.0.0.133/ks/centos8.cfg
label linux7
menu label Auto Install CentOS Linux ^7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://10.0.0.133/ks/centos7.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.133/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.133/centos/8/os/x86_64/ rescue
label local
menu default
menu label Boot from ^local drive
localboot 0xffff
[root@cent8_yzil ~]#
7、测试客户端基于PXE实现自动安装