pxe批量部署脚本

Posted twoo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pxe批量部署脚本相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#检查环境
setenforce 0
sed -i ‘s/=enforce/=disabled/g‘ /etc/selinux/config
systemctl restart firewalld
#配置yum源
cd /etc/yum.repos.d
mkdir bak
mv *.repo bak
mkdir /dvd
mount /dev/cdrom /dvd
cat > /etc/yum.repos.d/1.repo <<EOF
[dvd]
name=dvd
baseurl=file:///dvd
enabled=1
gpgcheck=0
EOF
yum clean all
yum makecache
#安装dhcp
yum -y install dhcp
cat > /etc/dhcp/dhcpd.conf <<EOF 
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.200.0 netmask 255.255.255.0 
range 192.168.200.100 192.168.200.200;
option routers 192.168.200.12;
filename \"pxelinux.0"\;
next-server 192.168.200.12; 
EOF 
systemctl restart dhcpd
#安装tftp
yum -y install tftp-server xinetd
vim /etc/xinetd.d/tftp
sed -i ‘13s/= -s /var/lib/tftpboot/= -s /tftpboot/g‘ /etc/xinetd.d/tftp
sed -i ‘14s/= yes/= no/g‘ /etc/xinetd.d/tftp
systemctl restart xinetd
#安装http
yum -y install httpd syslinux
rm -fr /etc/httpd/conf.d/welcome.conf
mkdir /var/www/html/iso
mount /dev/cdrom /var/www/html/iso/
cat >> /etc/fstab <<EOF
/dev/cdrom/ /var/www/htm/iso iso9660 defaults 0 0
EOF
#制作光盘系统
mkdir /tftpboot
cp /var/www/html/iso/isolinux/vmlinuz /tftpboot/
cp /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 ‘1s/vesamenu.c32/ks/g‘ /tftpboot/pxeinux.cfg/default
sed -i ‘60a label ks
menu label ^Install CentOS 7
kernel vmlinuz
append initrd=initrd.img append initrd=initrd.img method=http://192.168.200.12/iso 
ks=http://192.168.200.12/ks.cfg devfs=nomount‘
cp /root/anaconda-ks.cfg /var/www/html/ks.cfg
sed -i ‘5s/cdrom/install/g‘ /var/www/html/ks.cfg
sed -i ‘6a url --url=\"http://192.168.200.12/iso"\‘ /var/www/html/ks.cfg
chmod /var/www/html/ks.cfg
#添加防火墙
systemctl enable dhcpd xinetd httpd
systemctl restart dhcpd xinetd httpd
firewall-cmd --add-port=67/udp --permanent
firewall-cmd --add-port=69/udp --permanent
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

  

以上是关于pxe批量部署脚本的主要内容,如果未能解决你的问题,请参考以下文章

PXE批量部署

pxe批量部署

使用 PXE+Kickstart 实现无人值守批量部署系统

5.12PXE+Kickstart批量无人值守部署

PXE 无人值守批量部署 Centos 7

利用pxe dhcp tfcp http kickstart实现批量部署linux系统