脚本实现PXE装机和无人值守

systemctal stop firewalld

setenforce 0

虚拟机关机在设置里给4G内存

环境配置完成

yum -y install tftp-server xinetd --- #安装软件包

vim etc/xinetd.d/tftp --- #打开配置文件

wait 改成no --- #表示多台客户机可以和主机同时一起连接

disable 改成no --- #表示开启

systemctl stop firewalld.service
setenforce 0
yum -y install tftp-server xinetd
sed -i '/wait/c wait                = no' /etc/xinetd.d/tftp
sed -i '/disable/c disable             = no' /etc/xinetd.d/tftp
systemctl start tftp
systemctl enable tftp
systemctl start xinetd
systemctl enable xinetd
sleep 5

脚本实现PXE装机和无人值守_第1张图片

开始安装dhcp

yum -y install dhcp

cd /usr/share/doc/dhcp

cp dhcp.conf.exanple /etc/dhcp/dhcpd.conf

cd /etc/dhcp

配置:

ddns-update-style none; --- #关闭dns的动态更新

next-server 20.0.0.10; ---# 指定tftp的服务器IP地址

filename ‘pxelinux.0’; --- #指定要下载的pxe引导文件名

指定网段20.0.0.0

255.255.255.0

20.0.0.100 20.0.0.110

20.0.0.10

设置本机地址否则thtp获取不到

yum -y install dhcp
cp -rf /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf

sed -i '/max-lease-time 7200;/a filename "pxelinux.0";' /etc/dhcp/dhcpd.conf
sed -i '/max-lease-time 7200;/a next-server 20.0.0.10;' /etc/dhcp/dhcpd.conf
sed -i '/max-lease-time 7200;/a ddns-update-style none;' /etc/dhcp/dhcpd.conf
sed -i '/subnet 10.254.239.0/c subnet 20.0.0.0 netmask 255.255.255.0 {' /etc/dhcp/dhcpd.conf
sed -i '/range 10.254.239.10 10.254.239.20;/c range 20.0.0.100 20.0.0.200;' /etc/dhcp/dhcpd.conf
sed -i '/option routers rtr-239-0-1.example.org,/c option routers 20.0.0.10;' /etc/dhcp/dhcpd.conf
systemctl start dhcpd
systemctl enable dhcpd

sleep 5

脚本实现PXE装机和无人值守_第2张图片

配置内核文件

mount /dev/cdrom /mnt

cd /mmnt/images/pxeboot

cp initrd.img /var/lib/tftpboot/

cp vmliuz /var/lib/tftpboot

yum -y install sysliux

cd /user/share/syslinux

cp pxeliunyx.0 /var/lib/tftpboot

cd /var/lib/tftpboot

mount /dev/sr0 /mnt
cd /mnt/images/pxeboot
cp vmlinuz /var/lib/tftpboot/
cp initrd.img /var/lib/tftpboot/

脚本实现PXE装机和无人值守_第3张图片

准备PXE引导程序

yum -y install syslinux

sleep 3

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

yum -y install syslinux

sleep 3

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

脚本实现PXE装机和无人值守_第4张图片

安装FTP服务

yum -y install vsftpd
mkdir /var/ftp/centos7
cp -rf /mnt/* /var/ftp/centos7/
systemctl start vsftpd
systemctl enable vsftpd
sleep 5
 

yum -y install vsftpd
mkdir /var/ftp/centos7
cp -rf /mnt/* /var/ftp/centos7/
systemctl start vsftpd
systemctl enable vsftpd
sleep 5

脚本实现PXE装机和无人值守_第5张图片

配置启动菜单文件

mkdir /var/lib/tftpboot/pxelinux.cfg

echo "default auto 
prompt 0 

label auto      
kernel vmlinuz
append initrd=initrd.img method=ftp://20.0.0.10/centos7

label linux text
kernel vmlinuz
append text initrd=initrd.img method=ftp://20.0.0.10/centos7

label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://20.0.0.10/centos7" > /var/lib/tftpboot/pxelinux.cfg/default

mkdir /var/lib/tftpboot/pxelinux.cfg

echo "default auto 
prompt 0 

label auto      
kernel vmlinuz
append initrd=initrd.img method=ftp://20.0.0.10/centos7

label linux text
kernel vmlinuz
append text initrd=initrd.img method=ftp://20.0.0.10/centos7

label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://20.0.0.10/centos7" > /var/lib/tftpboot/pxelinux.cfg/default

脚本实现PXE装机和无人值守_第6张图片

#实现 Kickstart 无人值守安装
yum install -y system-config-kickstart
cp /root/ks.cfg /var/ftp/

sed -i '6d' /var/lib/tftpboot/pxelinux.cfg/default
sed -i '/kernel vmlinuz/a append initrd=initrd.img method=ftp://20.0.0.10/centos7 ks=ftp://20.0.0.10/ks.cfg' /var/lib/tftpboot/pxelinux.cfg/default
 

#实现 Kickstart 无人值守安装
yum install -y system-config-kickstart
cp /root/ks.cfg /var/ftp/

sed -i '6d' /var/lib/tftpboot/pxelinux.cfg/default
sed -i '/kernel vmlinuz/a append initrd=initrd.img method=ftp://20.0.0.10/centos7 ks=ftp://20.0.0.10/ks.cfg' /var/lib/tftpboot/pxelinux.cfg/default

修改ks.cfg

脚本实现PXE装机和无人值守_第7张图片

你可能感兴趣的:(linux)