SHELL脚本之配置PXE批量无人值守装机
admin
2023-03-30 18:41:27
0

PXE批量无人值守装机脚本

准备2个网卡:

第一个网卡使用NET,用来安装服务
第2个网卡用来提供dhcp服务

#!/bin/bash
#部署pxe批量装机服务

#配置双网卡
#定义网卡配置文件位置
k=/etc/sysconfig/network-scripts

#复制网卡配置文件模板
cd /etc/sysconfig/network-scripts
cp -p ifcfg-ens33 ifcfg-ens36

#修改第2块网卡配置文件
sed -i 's/dhcp/static/' $k/ifcfg-ens36
sed -i 's/ens33/ens36/' $k/ifcfg-ens36
sed -i '/UUID/d' $k/ifcfg-ens36
cat >>$k/ifcfg-ens36 <<-EOF
IPADDR=192.168.100.100
NETMASK=255.255.255.0
GATEWAY=192.168.100.1
EOF

#重启网络服务
systemctl restart network

#防止yum安装进程休眠
rm -rf /var/run/yum.pid

#安装必要服务
yum install dhcp syslinux tftp-server vsftpd -y

#修改DHCP服务配置文件
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cat >>/etc/dhcp/dhcpd.conf <<-EOF
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.10 192.168.100.20;
option routers 192.168.100.100;
next-server 192.168.100.100;
filename "pxelinux.0";
}
EOF

#定义要经常用的tftp站点
tftp=/var/lib/tftpboot

#复制引导程序到tftp站点
cp /usr/share/syslinux/pxelinux.0 $tftp/

#修改tftp配置文件
sed -i '/disable/s/yes/no/g' /etc/xinetd.d/tftp

#创建镜像文件挂载点
cd /var/ftp
mkdir centos7

#挂载镜像文件
mount /dev/sr0 /var/ftp/centos7

#复制压缩内核和系统初始化文件到tftp站点
cd centos7/images/pxeboot
cp initrd.img vmlinuz $tftp

#在tftp站点中创建启动菜单存放位置
cd $tftp
mkdir pxelinux.cfg
cd pxelinux.cfg

#创建启动菜单文件
cat >default <<-EOF
default auto
prompt 1

label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg

label linux text
kernel vmlinuz
append text initrd=initrd.img method=ftp://192.168.100.100/centos7

label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7
EOF

#安装系统工具
yum install system-config-kickstart -y

#创建系统安装过程文件
cat >/var/ftp/ks.cfg <<-EOF
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
#Install OS instead of upgrade
install
#Keyboard layouts
keyboard 'us'
#Root password
rootpw --plaintext 123
#Use network installation
url --url="ftp://192.168.100.100/centos7/"
#System language
lang zh_CN
#System authorization information
auth  --useshadow  --passalgo=sha512
#Use graphical install
graphical
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
#System bootloader configuration
bootloader --location=mbr
#Partition clearing information
clearpart --all
#Disk partitioning information
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=4096
part /home --fstype="xfs" --size=4096
part / --fstype="xfs" --grow --size=1

%packages
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
kexec-tools

%end
EOF

#关闭防火墙
systemctl stop firewalld.service
setenforce 0

#启动所有服务
systemctl start dhcpd
systemctl start tftp
systemctl start vsftpd

相关内容

热门资讯

河南760亿省级财政资金定存招... 【大河财立方消息】5月11日消息,河南省财政厅公布2026年度第1期河南省省级财政专户资金定期存款代...
无忧传媒宣布与“孕妇泰国坠崖案... 据北京商报消息,5月11日,记者从无忧传媒方面获悉,目前公司与签约达人王暖暖经友好协商已确定解约。5...
米哈游:编造“皮套论”谣言构成... 【大河财立方消息】 5月11日,据米哈游法务部,近日米哈游诉网络博主许某鹏(网名“自由人米八”)、罗...
外交部介绍特朗普访华具体安排和... 5月11日,外交部发言人郭嘉昆主持例行记者会。总台央视记者提问:中方已经发布美国总统特朗普来华进行国...
61家!郑州市科技类校外培训机... 根据《河南省科技类校外培训机构设置标准和管理指南(试行)》有关规定,为落实“双减”政策要求,经科技类...
夫妻酒后各自驾车,路上相撞,双... 5月10日晚,四川夹江县公安局发布消息,该局交通管理大队于近日处理一起追尾事故时,查获一对夫妻双双酒...
顾客称用餐时石锅上爬满虫,餐厅... 近日,有网友反映,在福建省晋江市池店镇的“钱头大自然餐厅”用餐时,顾客吃到一半竟发现石锅外壁上爬满了...
公职人员纠集他人私闯民宅殴打重... 5月10日,中共安康高新区空港新城委员会发布情况说明,内容如下:5月10日,网络出现反映“安康高新区...
中美联合侦破跨国走私贩毒案,抓... 4月初,中国公安部禁毒局和美国司法部缉毒署成功联合侦破郭某等人走私贩毒案,同步在中国辽宁、广东,美国...
多名网友收到广东地震局短信,官... 5月11日上午,多名广东网友发帖称,自己收到了广东地震局的短信,短信内容如下:【广东省地震局】温馨提...