pxe批量装机

简述

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 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值