简述
preboot execute environment,预启动执行环境
通过pxe可以实现自动化批量装机
#!/bin/bash &>>/dev/null
#dhcp
IP=`ip a|grep 'ens33'|grep -w 'inet' |awk '{print $2}'|awk -F/ '{print $1}'`
WD=`ip a|grep 'ens33'|grep -w 'inet' |awk '{print $2}'|awk -F/ '{print $1}'|awk -F. '{print $1"."$2"."$3}'`
yum -y -q install dhcp
echo "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 $WD.0 netmask 255.255.255.0 {
range $WD.150 $WD.250;
option routers $IP;
filename \"pxelinux.0\";
next-server $IP;
}" > /etc/dhcp/dhcpd.conf
systemctl restart dhcpd
systemctl enable dhcpd
if [ -z "`firewall-cmd --list-port|grep '67/udp'`" ]
then
firewall-cmd --add-port=67/udp
firewall-cmd --add-port=67/udp --permanent
fi
#dhcp配置完成
#xinetd
yum -y -q install tftp-server xinetd
sed -i '13 s#/var/lib##g' /etc/xinetd.d/tftp
sed -i '14 s/yes/no/g' /etc/xinetd.d/tftp
if [ -z "ls /|grep 'tftpboot'" ]
then
mkdir /tftpboot
else
rm -rf /tftpboot
mkdir /tftpboot
fi
systemctl restart xinetd
systemctl enable xinetd
firewall-cmd --add-port=69/udp
firewall-cmd --add-port=69/udp --permanent
#xinetd配置完成
#httpd
yum -y -q install httpd syslinux
mkdir -p /var/www/html/iso
mount /dev/cdrom /var/www/html/iso
if [ -z "cat /etc/fstab|grep '/dev/sr0 /var/www/html/iso iso9660'" ]
then
echo "/dev/sr0 /var/www/html/iso iso9660 defaults 0 0" >> /etc/fstab
fi
cp /var/www/html/iso/isolinux/vmlinuz /tftpboot
cp /var/www/html/iso/isolinux/initrd.img /tftpboot
mkdir /tftpboot/pxelinux.cfg
cp /var/www/html/iso/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
cp /usr/share/syslinux/pxelinux.0 /tftpboot
sed -i '1 s/vesamenu.c32/ks/g' /tftpboot/pxelinux.cfg/default
sed -i 's/^(menu end)$//g' /tftpboot/pxelinux.cfg/default
echo "label ks
menu label ^Install CentOS 7
kernel vmlinuz
append initrd=initrd.img method=http://$IP/iso ks=http://$IP/ks.cfg devfs=nomount
menu end" >> /tftpboot/pxelinux.cfg/default
cp /root/anaconda-ks.cfg /var/www/html/ks.cfg
sed -i 's/^(cdrom)$/^(install)$/g' /var/www/html/ks.cfg
sed -i 9a"url --url=\"http://$IP/mnt/iso\"" /var/www/html/ks.cfg
chmod a+r /var/www/html/ks.cfg
systemctl restart httpd
systemctl enable httpd
firewall-cmd --add-port=80/tcp
firewall-cmd --add-port=80/tcp --permanent