目录
点关注不迷路
PXE批量部署系统
一、PXE组件介绍
1、共享对应的系统安装文件
2、提供DHCP服务,告知tftp地址
3、提供tftp服务
2、部署ftp服务提供系统安装源
3、部署tftp服务
2)共享pxelinux.0文件
3)编辑菜单文件
4、配置DHCP
5、测试
三、添加centos 6.6安装源
1、通过FTP共享centos 6.6光盘文件
2、通过tftp共享centos 6.6内核、初始化文件
3、添加centos6菜单项
4、测试centos 6.6
四、配置kickstart文件实现系统自动安装
3、kickstart文件的获取
4、配置ks文件实现centos7.6自动安装
FTP/NFS/HTTP
1)提供系统安装源的菜单
2)共享内核vmlinuz、初始化镜像文件 initrd.img
3) .pxelinux.0
4、syslinux
pxelinu.0 tftp服务共享
提供系统引导的支持
二、PXE服务部署提供centos 7.6安装源
1、扩展根分区
[root@pxe ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@pxe ~]# vgextend centos /dev/sdb
Volume group "centos" successfully extended
[root@pxe ~]#
[root@pxe ~]# lvextend -L +50G /dev/centos/root
Size of logical volume centos/root changed from <17.51 GiB (4482 extents) to <67.51 GiB (17282 extents).
Logical volume centos/root successfully resized.
[root@pxe ~]#
[root@pxe ~]# xfs_growfs /dev/centos/root
[root@pxe ~]# yum install -y vsftpd dhcp tftp-server xinetd syslinux
[root@pxe ~]# mkdir /var/ftp/centos7.6
[root@pxe ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@pxe ~]# nohup cp -r /mnt/* /var/ftp/centos7.6/ &
[root@pxe ~]# systemctl start vsftpd
[root@pxe ~]# systemctl enable vsftpd
[root@pxe ~]# netstat -antp | grep ftp
tcp6 0 0 :::21 :::* LISTEN 7235/vsftpd
1)共享内核、初始化镜像文件、菜单文件
[root@pxe ~]# cp /mnt/isolinux/* /var/lib/tftpboot/
[root@pxe ~]# mkdir /var/lib/tftpboot/centos7.6
[root@pxe ~]# mv /var/lib/tftpboot/vmlinuz /var/lib/tftpboot/initrd.img /var/lib/tftpboot/centos7.6/
[root@pxe ~]# ls /var/lib/tftpboot/
boot.cat boot.msg centos7.6 grub.conf isolinux.bin isolinux.cfg memtest splash.png TRANS.TBL vesamenu.c32
[root@pxe ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@pxe ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@pxe ~]# mv /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
[root@pxe ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
label centos76
menu label Install CentOS7.6
kernel centos7.6/vmlinuz //以相对路径【相对于tftp的数据目录】方式指定对应菜单项的内核
append initrd=centos7.6/initrd.img inst.stage2=ftp://192.168.140.10/centos7.6 inst.repo=ftp://192.168.140.10/centos7.6
initrd= 系统初始化镜像文件,相对路径
inst.stage= 指定系统安装文件的存储位置
inst.repo= 指定软件安装包的存储位置
4)启动tftp服务
[root@pxe ~]# vim /etc/xinetd.d/tftp
disable = no
[root@pxe ~]# systemctl restart xinetd
[root@pxe ~]# systemctl enable xinetd
[root@pxe ~]# netstat -anup | grep 69
udp 0 0 0.0.0.0:69 0.0.0.0:* 1764/xinetd
[root@pxe ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.140.0 netmask 255.255.255.0 {
range 192.168.140.100 192.168.140.200;
option routers 192.168.140.2;
option domain-name-servers 114.114.114.114,223.5.5.5;
next-server 192.168.140.10;
filename "pxelinux.0";
}
[root@pxe ~]# systemctl start dhcpd
[root@pxe ~]# systemctl enable dhcpd
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
[root@pxe ~]#
[root@pxe ~]# netstat -tunlp | grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 7491/dhcpd
centos 7测试机至少2G内存
[root@pxe ~]# mount /dev/sr0 /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@pxe ~]# ls /mnt/
CentOS_BuildTag EULA images Packages repodata RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6
EFI GPL isolinux RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6 TRANS.TBL
[root@pxe ~]#
[root@pxe ~]# mkdir /var/ftp/centos6.6
[root@pxe ~]# cp -r /mnt/* /var/ftp/centos6.6
[root@pxe ~]# mkdir /var/lib/tftpboot/centos6.6
[root@pxe ~]#
[root@pxe ~]# cp /mnt/isolinux/vmlinuz /mnt/isolinux/initrd.img /var/lib/tftpboot/centos6.6
[root@pxe ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
label centos66
menu label Install CentOS6.6
kernel centos6.6/vmlinuz
append initrd=centos6.6/initrd.img
%packages
软件名称
软件名称
软件名称
@软件组名称
%end
系统安装完毕后自动执行的操作
%post
操作命令
操作命令
操作命令
%end
1)通过ftp共享ks文件
[root@pxe ~]# cp centos76_ks.cfg /var/ftp/
2)编辑菜单文件
label centos76
menu label Install CentOS7.6
kernel centos7.6/vmlinuz
append initrd=centos7.6/initrd.img inst.stage2=ftp://192.168.140.10/centos7.6 inst.repo=ftp://192.168.140.10/centos7.6 ks=ftp://192.168.140.10/centos76_ks.cfg
centos76文件参考:
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$pHhwGQlp$FnSejX6/.MBUrHVJlIUTb/
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="ftp://192.168.140.10/centos7.6"
# 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=500
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1
%packages
@core
vim-enhanced
net-tools
psmisc
lftp
wget
rsync
ntpdate
bash-completion
%end
%post
sed -ri '/^#Port/c \Port 33333' /etc/ssh/sshd_config
systemctl restart sshd
%end
centos66ks文件参考:
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$pHhwGQlp$FnSejX6/.MBUrHVJlIUTb/
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
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="ftp://192.168.140.10/centos6.6"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=500
part swap --fstype="swap" --size=2048
part / --fstype="ext4" --grow --size=1
%packages
@core
vim-enhanced
net-tools
psmisc
lftp
wget
rsync
ntpdate
%end
%post
sed -ri '/^#Port/c \Port 33333' /etc/ssh/sshd_config
service sshd restart
%end