PXE启动工作原理
实现自动化安装 Centos 6 7 8系统安装
用192.168.80.120这台主机作为服务器
第一步:下载相关软件
[root@Centos8 ~]#yum -y install httpd dhcp-server tftp-server syslinux
第二步:挂载光盘和相关目录
[root@Centos8 ~]#systemctl start httpd
[root@Centos8 ~]#mkdir /var/www/html/centos/{6,7,8} -p
[root@Centos8 ~]#mount /dev/sr0 /var/www/html/centos/6
[root@Centos8 ~]#mount /dev/sr1 /var/www/html/centos/7
[root@Centos8 ~]#mount /dev/sr2 /var/www/html/centos/8
搭建好yum仓库,打开网站访问本机IP查看有没有搭建成功
第三步:准备kicksatrt文件
Centos8.cfg
[root@Centos8 ~]$ mkdir /var/www/html/ksdir/
[root@Centos8 ~]$ touch /var/www/html/ksdir/centos{6,7,8}.cfg
#version=RHEL8
ignoredisk --only-use=sda
zerombr
text
clearpart --all --initlabel
cdrom
reboot
firstboot --disable
keyboard --vckeymap=us --xlayouts='us'
lang en_US.UTF-8
selinux --disabled
firewall --disabled
url --url=http://192.168.80.120/centos/8/ #指定yum源
bootloader --append="net.ifnames=0" --location=mbr --boot-drive=sda
network --bootproto=dhcp --device=eth0 --nameserver=114.114.114.114 --onboot=off --ipv6=auto --no-activate
network --hostname=Centos8
rootpw --iscrypted $6$uK981wzjOUsnb.OY$TYcDalcuTmXcbXMrPRyFmWLPGSMksIahaVrUnCJny04f.BwFr7E/SRKQV1e/lJRhYh0rAHJTYQuCEGwDJY7BC0
#密码heshizhe 也可以设密文密码 替换成 rootpw --plaintext 密码
firstboot --enable
skipx
services --disabled="chronyd"
timezone Asia/Shanghai --isUtc --nontp
user --name=he --password=$6$RSXrFotauUaR0cUe$b.hx2jVwJR3C/5bFs4aMDjOvjkw7PrsKvB7.lK9INUQK5QEf7p4V2y1J.faV9CkYbEDLEgzFnfNgrYDnDAYHx0 --iscrypted --gecos="he"
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
vim
tree
gcc
make
bc
%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
centos7.cfg
install
keyboard 'us'
rootpw --plaintext heshizhe #明文root密码
lang en_US
auth --useshadow --passalgo=sha512
text
firstboot --disable
selinux --disabled
firewall --disabled
network --bootproto=dhcp --device=eth0
reboot
timezone Asia/Shanghai
url --url="http://192.168.80.120/centos/7/"
#bootloader --append="net.ifnames=0" --location=none
zerombr
clearpart --all --initlabel
autopart --type=lvm #采用逻辑卷方式分区
#part /boot --fstype="ext4" --size=1024
#part / --fstype="xfs" --size=100000
#part swap --fstype="swap" --size=2048
%packages
@web-server
%end
centos6.cfg
install
text
reboot
firewall --disabled
url --url="http://192.168.80.120/centos/6"
rootpw --iscrypted $1$ZxQpXd9n$etiURJV.6a..tQYDh4Xjr0
auth --useshadow --passalgo=sha512
keyboard us
lang en_US
selinux --disabled
skipx
logging --level=info
timezone Asia/Shanghai
network --bootproto=dhcp --device=eth0 --onboot=on
zerombr
bootloader --location=mbr
clearpart --all initlabel
part /boot --fstype="ext4" --size=1024
part /swap --fstype="ext4" --size=2048
part /data --fstype="ext4" --size=50000
part / --fstype="ext4" --size=100000
第四步:配置DHCP服务
/etc/dhcp/dhcpd.conf 里面是没有内容的不过/usr/share/doc/dhcp-server/dhcpd.conf.example有范例。所以重定向到/etc/dhcp/dhcpd.conf 文件里
[root@Centos8 ~]#cat /usr/share/doc/dhcp-server/dhcpd.conf.example > /etc/dhcp/dhcpd.conf
[root@Centos8 ~]#vim /etc/dhcp/dhcpd.conf
option domain-name "www.baidu.com"; #自动补全,如输入ping命令www会自动补全成www.baidu.com
option domain-name-servers 114.114.114.114, 8.8.8.8; #DNS
#本机IP的网段我是192.168.80.0网段。
subnet 192.168.80.0 netmask 255.255.255.0 {
range 192.168.80.10 192.168.80.100; #DHCP分配地址范围192.168.80.10-100之间
option routers 192.168.80.2; # 默认网关
next-server 192.168.80.120; #提供引导文件服务器IP地址
filename "pxelinux.0"; #bootloader启动文件的名称
}
[root@Centos8 ~]#systemctl enable --now dhcpd #启动dhcp服务设为开机自启
[root@centos7 ~]# dhclient -d -v
Internet Systems Consortium DHCP Client 4.2.5
Copyright 2004-2013 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/ens33/00:0c:29:e0:c3:b7
Sending on LPF/ens33/00:0c:29:e0:c3:b7
Sending on Socket/fallback
DHCPDISCOVER on ens33 to 255.255.255.255 port 67 interval 4 (xid=0x446cd60f)
DHCPREQUEST on ens33 to 255.255.255.255 port 67 (xid=0x446cd60f)
DHCPOFFER from 192.168.80.120
DHCPACK from 192.168.80.120 (xid=0x446cd60f)
bound to 192.168.80.11 -- renewal in 232 seconds.
#在Centos7系统上查看DHCP服务有没有配置好
[root@Centos8 ~]#tail -f /var/lib/dhcpd/dhcpd.leases
lease 192.168.80.11 {
starts 4 2020/09/10 02:27:51;
ends 4 2020/09/10 02:37:51;
cltt 4 2020/09/10 02:27:51;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 00:0c:29:e0:c3:b7;
}
第五步:准备PXE启动相关文件
[root@Centos8 ~]#cd /var/lib/tftpboot/
[root@Centos8 tftpboot]#mkdir centos{6,7,8}
[root@Centos8 tftpboot]#cp /var/www/html/centos/6/isolinux/vmlinuz centos6
[root@Centos8 tftpboot]#cp /var/www/html/centos/6/isolinux/initrd.img centos6
[root@Centos8 tftpboot]#cp /var/www/html/centos/7/isolinux/initrd.img centos7
[root@Centos8 tftpboot]#cp /var/www/html/centos/7/isolinux/vmlinuz centos7
[root@Centos8 tftpboot]#cp /var/www/html/centos/8/isolinux/initrd.img centos8
[root@Centos8 tftpboot]#cp /var/www/html/centos/8/isolinux/vmlinuz centos8
[root@Centos8 tftpboot]#cp /var/www/html/centos/8/isolinux/ldlinux.c32 .
[root@Centos8 tftpboot]#cp /var/www/html/centos/8/isolinux/libcom32.c32 .
[root@Centos8 tftpboot]#cp /var/www/html/centos/8/isolinux/libutil.c32 .
[root@Centos8 tftpboot]#cp /usr/share/syslinux/menu.c32 .
[root@Centos8 tftpboot]#cp /usr/share/syslinux/pxelinux.0 .
#ldlinux.c32 libcom32 libutil.c32 是Centos8需要的
[root@Centos8 tftpboot]#mkdir pxelinux.cfg
[root@Centos8 tftpboot]#cp /var/www/html/centos/8/isolinux/isolinux.cfg pxlinux.cfg
[root@Centos8 tftpboot]#cd pxelinux.cfg
[root@Centos8 pxelinux.cfg]# mv isolinux.cfg default
[root@Centos8 tftpboot]#cd ..
[root@Centos8 tftpboot]#tree
.
├── centos6
│ ├── initrd.img
│ └── vmlinuz
├── centos7
│ ├── initrd.img
│ └── vmlinuz
├── centos8
│ ├── initrd.img
│ └── vmlinuz
├── ldlinux.c32
├── libcom32.c32
├── libutil.c32
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
└── default
4 directories, 12 files
准备启动菜单文件
[root@Centos8 tftpboot]#cd pxelinux.cfg
[root@Centos8 pxelinux.cfg]#vim default
default menu.c32
timeout 600
menu title CentOS linux
label linux8
menu label Install CentOS Linux ^8
kernel centos8/vmlinuz
append initrd=centos8/initrd.img ks=http://192.168.80.120/ksdir/centos8.cfg quiet
label linux7
menu label Install CentOS Linux ^7
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.80.120/ksdir/centos7.cfg quiet
label linux6
menu label Install CentOS Linux ^6
kernel centos6/vmlinuz
append initrd=centos6/initrd.img ks=http://192.168.80.120/ksdir/centos6.cfg quiet
label rescue
menu label ^Rescue a CentOS Linux system
kernel vmlinuz
append initrd=centos8/initrd.img inst.repo=http://192.168.80.120/centos/8 rescue quiet
label local menu default
menu label Boot from ^local drive
localboot 0xfff
通过网络启动,安装Centos8就选择第一个,7第二个,6第三个。