简简单单写了一个部署PXE服务的脚本

[root@localhost ~]# bash PXE_centos7_6.sh

前提能连接外网,仓库没有问题

!/bin/bash

echo "-----------------PXE批量部署CentOS7.6脚本-------------------"
echo -e "开始部署。。。。。\n"

#下载安装部署PXE必要服务与文件

systemctl status expect dhcp vsftpd syslinux tftp-server xinetd &> /dev/null
if [ $? -eq 0 ];then
        echo -e "必要软件已经安装!!\n"
else
        yum -y install expect dhcp vsftpd syslinux tftp-server xinetd &> /dev/null &> /dev/null
        systemctl start vsftpd
        systemctl enable vsftpd &> /dev/null
        echo -e "软件已安装完毕\n"
fi
mkdir /var/ftp/centos7.6 &> /dev/null
if [ -e /var/ftp/centos7.6/repodata ];then
        echo "镜像内容在ftp服务器中已存在!!"
else
        echo -e "正在将镜像内容复制到ftp服务器中。。。\n"
        cp -a /mnt/* /var/ftp/centos7.6/
        echo -e "复制结束\n"
fi
systemctl start tftp
systemctl enable tftp &> /dev/null
systemctl start xinetd
systemctl enable xinetd &> /dev/null
if [ -e /var/lib/tftpboot/centos7.6 ]; then
        echo -e "centos7.6文件在tftp服务器中已存在\n"
else
        echo -e "正在将centos7.6引导文件复制到tftp服务器\n"
        cp -a /mnt/isolinux/* /var/lib/tftpboot/
        echo -e "复制完毕!\n"
fi

#开始部署PXE

echo -e "开始提取centos7.6共享内核与初始化镜像。。。。。。\n"
mkdir /var/lib/tftpboot/centos7.6 &> /dev/null
mv /var/lib/tftpboot/initrd.img /var/lib/tftpboot/centos7.6/ &> /dev/null
mv /var/lib/tftpboot/vmlinuz /var/lib/tftpboot/centos7.6/ &> /dev/null
mv /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default &> /dev/null
echo -e "提取完毕!!!\n"

cat > /var/lib/tftpboot/pxelinux.cfg/default << eof

# A scrollbar of some type? Not sure.
menu color scrollbar 0 #ffffffff #ff355594 none

# Timeout msg
menu color timeout 0 #ffffffff #00000000 none
menu color timeout_msg 0 #ffffffff #00000000 none

# Command prompt text
menu color cmdmark 0 #84b8ffff #00000000 none
menu color cmdline 0 #ffffffff #00000000 none

# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.

menu tabmsg Press Tab for full configuration options on menu items.

menu separator # insert an empty line
menu separator # insert an empty line

label linux
  menu label Install CentOS 7
eof
echo -e "pxe菜单文件编写完成!\n"
sed -i '/disable/c \        disable                 = no' /etc/xinetd.d/tftp
systemctl restart xinetd

cp -a /root/anaconda-ks.cfg /var/ftp/centos76_ks.cfg
chmod  644 /var/ftp/centos76_ks.cfg
echo ""

#下边是CenTos7.6的ks文件

cat > /var/ftp/centos76_ks.cfg << eof
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$pHhwGQlp$FnSejX6/.MBUrHVJlIUTb/
# System language
lang en_US
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled


# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=2048
part / --fstype="xfs" --grow --size=1

%packages
@core
vim-enhanced
net-tools
psmisc
lftp
wget
rsync
ntpdate
bash-completion
lvm2
%end


%post
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
%end
eof

#提供DHCP服务

cat > /etc/dhcp/dhcpd.conf << eof
subnet 192.168.152.0 netmask 255.255.255.0 {
  range 192.168.152.100 192.168.152.150;
  option routers 192.168.152.2;
  option domain-name-servers 114.114.114.114;
  next-server 192.168.152.15;
  filename "pxelinux.0";
}
eof

systemctl restart dhcpd
systemctl restart xinetd
systemctl restart dhcpd
systemctl restart tftp
systemctl restart vsftpd
echo "PXE部署成功"
                                        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值