PXE自动安装CentOS配置脚本

#!/bin/bash

if [[ $# != 1 ]];then
        echo "input a kickstart file"
        exit 1
fi

#关闭防火墙
systemctl stop firewalld &> /dev/null
systemctl disable firewalld &> /dev/null
iptables -F

#关闭selinux
setenforce 0
sed -r -i 's@(^SELINUX=).*@\1disabled@' /etc/selinux/config

#安装包
yum clean all &> /dev/null
yum install -y httpd dhcp tftp-server syslinux net-tools &> /dev/null

#准备程序包下载源
mkdir -pv /var/www/html/centos/7 &> /dev/null
echo "/dev/sr0   /var/www/html/centos/7    iso9660    defaults    0 0" >> /etc/fstab
umount /dev/sr0
mount -a > /dev/null

#准备kickstart文件
mkdir -pv /var/www/html/ksdir/7 &> /dev/null
cp $1 /var/www/html/ksdir/7/

#配置dhcp
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
subnet=$(route -n | grep "eth0" | cut -d" " -f1)
netmask=$(route -n | grep "eth0" | awk '{print $3}')
iprange=$(route -n | grep "eth0" | cut -d" " -f1 | sed -r 's@(.*)[^.]+$@\1@')
IP=$(ip a | egrep "inet.*eth0" | awk -F/ '{print $1}' | awk '{print $2}')
cat > /etc/dhcp/dhcpd.conf < /dev/null                                   
systemctl enable dhcpd httpd tftp.socket &> /dev/null

#准备pxe相关文件                                                                       
mkdir -pv /var/lib/tftpboot/pxelinux.cfg &> /dev/null                                  
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot                                    
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot                                      
cp /var/www/html/centos/7/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot              
cat > /var/lib/tftpboot/pxelinux.cfg/default <

当网卡名是eth0时可直接使用,kickstart文件自备,可以用system-config-kickstart生成kickstart文件,属于system-config-kickstart
ksvalidator:kickstart文件语法检查工具,属于pykickstart包

你可能感兴趣的:(PXE自动安装CentOS配置脚本)