当前位置:网站首页>Shell脚本完成pxe装机配置
Shell脚本完成pxe装机配置
2022-08-02 13:58:00 【正大光明瑞士卷】
目录
一、进入脚本界面
脚本界面代码:
#!/bin/bash
echo "-----------------------------------------------"
echo -e "欢迎使用pxe网络装机基础搭建脚本!\n作者:吕佳朋\n1.关闭防火墙,创建网卡ens36\n2.下载必要软件包并挂载系统光盘\n3.配置dhcp、tftp\n4.将装机必要文件移动到/var/lib/tftpboot\n5.exit"
echo "-----------------------------------------------"
read -p "please enter your choice:" i
二、必要手动设置
为虚拟机pxe服务端增加网卡设备,设置自定义仅主机模式(VMnet1)
这张网卡是作为dhcp服务器和ftp服务器为装机来分配ip并安装系统相关文件的,所有不需要设置网关地址和DNS,具体配置见下文。
三、设置网卡,关闭防火墙
firewalldset(){
read -p "请输入你的ens33网卡ip:" net1
read -p "请输入你作为dhcp服务端的网卡ip:" net
echo "=================================关闭系统防护=================================="
systemctl stop firewalld
setecforce 0
systemctl status firewalld
echo `#grep SELINNUX=disabled /etc/sysconfig/selinux`
grep SELINUX=disabled /etc/sysconfig/selinux
echo `#getenforce`
echo "==============================================================================="
echo "防火墙以及防护已关闭!"
echo "==============================================================================="
cp -p /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens36
sed -i '/UUID/d' /etc/sysconfig/network-scripts/ifcfg-ens36
#删除ens33网卡的UUID,否则会报错
sed -i 's/ens33/ens36/' /etc/sysconfig/network-scripts/ifcfg-ens36
#将ens33替换成ens36
sed -i s/$net1/$net/ /etc/sysconfig/network-scripts/ifcfg-ens36
#将ens33网卡地址进行替换
sed -i '/DNS/d' /etc/sysconfig/network-scripts/ifcfg-ens36
#将DNS行删除
sed -i '/GATEWAY/d' /etc/sysconfig/network-scripts/ifcfg-ens36
#将网关行删除
sed -i 's/dhcp\|none/static/' /etc/sysconfig/network-scripts/ifcfg-ens36
#将含有“dhcp”或“none”替换成static
ifdown ens36 && ifup ens36
ping -c 1 baidu.com > /dev/null
if [ $? -eq 0 ];then
echo "网络连接正常,设置完成!"
elif [ $? -ne 0 ];then
echo "网络设置出现错误,请检查"
fi
}
please enter your choice:1
请输入你的ens33网卡地址:192.168.116.22
请输入你作为dhcp服务端的网卡ip:192.168.100.100
检验:
四、下载相关服务并挂载系统光盘
yum下dhcp、tftp-server、syslinux、xinetd、system-config-kickstart、vsftpd
挂载系统光盘到/mnt下
install(){
echo "================================开始软件包安装================================"
yum install -y dhcp
yum install -y tftp-server
yum install -y syslinux
yum install -y xinetd
yum install -y system-config-kickstart
yum install -y vsftpd
echo "===============================开始系统光盘挂载==============================="
mount /dev/sr0 /mnt
echo "=============================================================================="
echo "必要软件包安装成功,系统光盘已挂载"
mount | grep /dev/sr0
echo "=============================================================================="
}
五、进行服务配置
复制一份dhcp.conf.example到/etc/dhcp/dhcpd.conf,并写入:
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.40 192.168.100.50;
option routers 192.168.100.100;
option domain-name-servers 114.114.114.114;
next-server 192.168.100.100;
filename \"pexlinux.0\";
其他的具体配置可以看之前的配置pxe装机的博客 :https://blog.csdn.net/m0_71518373/article/details/125923938?spm=1001.2014.3001.5502
serviceset(){
cp -p /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
echo "ddns-update-style none;
subnet 192.168.100.0 netmask 255.255.255.0 {
range 192.168.100.40 192.168.100.50;
option routers 192.168.100.100;
option domain-name-servers 114.114.114.114;
next-server 192.168.100.100;
filename \"pexlinux.0\";
}">> /etc/dhcp/dhcpd.conf
systemctl enable dhcpd
systemctl start dhcpd
sed -i '/wait/s/yes/no/' /etc/xinetd.d/tftp
sed -i '/disable/s/yes/no/' /etc/xinetd.d/tftp
systemctl enable tftp
systemctl start tftp
mkdir /var/ftp/centos7
cp -rf /mnt/* /var/ftp/centos7
systemctl enable vsftpd
systemctl start vsftpd
mkdir /var/lib/tftpboot/pxelinux.cfg
echo "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 ks=ftp://192.168.100.100/ks.cfg
label linux rescue
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.100.100/centos7 ks=ftp://192.168.100.100/ks.cfg">> /var/lib/tftpboot/pxelinux.cfg/default
echo "---------------------------------------------------------------------------"
echo "The main services are ready!"
echo "dhcpd:"
systemctl status dhcpd | grep -i active
echo "tftp:"
systemctl status tftp | grep -i active
echo "vsftpd:"
systemctl status vsftpd | grep -i active
echo "----------------------------------------------------------------------------"
}
六、将装机文件移动到tftp文件夹
简单的cp命令
filemv(){
cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot/
cp /mnt/images/pxeboot/vmlunz /var/lib/tftpboot/
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
echo "---------------------------------------------"
echo "The main pxe-files are already in position!"
echo "请进入桌面点击kickstart进行配置!"
echo "感谢使用,熊猫烧香"
echo "---------------------------------------------"
exit
}
kickstart这里还是需要在桌面环境中操作,并将保存的配置文件存放在 var/ftp/下
七、使用case让用户选择使用函数方法
main()
{
case $i in
1)
firewalldset
;;
2)
install
;;
3)
serviceset
;;
4)
filemv
;;
5)
echo "感谢使用,熊猫烧香"
exit
;;
*)
echo "错误的输入,请重新选择"
;;
esac
}
main $*
边栏推荐
- Flashback Technology of Oracle Database
- Mysql index details (with pictures and texts)
- 【Tensorflow】AttributeError: module ‘keras.backend‘ has no attribute ‘tf‘
- 目标检测场景SSD-Mobilenetv1-FPN
- 标量替换、栈上分配、同步消除
- 线程安全问题及关键字synchronized,volatile
- idea社区版下载安装教程_安装天然气管道的流程
- 微信小程序-最近动态滚动实现
- ORACLE expdp/impdp详解
- 关于C#使用DateTime数据的细节
猜你喜欢
史上最全!47个“数字化转型”常见术语合集,看完秒懂~
tinymce-plugins
"Second Uncle" is popular, do you know the basic elements of "exploding" short videos from the media?
如何解决mysql服务无法启动1069
科研试剂DSPE-PEG-VIP,二硬脂酰基磷脂酰乙醇胺-聚乙二醇-血管活性肠肽VIP
【Tensorflow】AttributeError: '_TfDeviceCaptureOp' object has no attribute '_set_device_from_string'
MySQL - ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
【C语言】手撕循环结构 —— for语句
C language improvement (3)
Enterprise Network Planning Based on Huawei eNSP
随机推荐
【C语言】夏日一题 —— 如何判断素数?
SQL函数 UPPER
网络安全第五次作业
“多源异构”和“异构同源”定义区分详解「建议收藏」
文件加密软件有哪些?保障你的文件安全
科研试剂DSPE-PEG-VIP,二硬脂酰基磷脂酰乙醇胺-聚乙二醇-血管活性肠肽VIP
数据机构---第六章图---图的遍历---选择题
微信小程序-最近动态滚动实现
[C language] Analysis of function recursion (1)
乐心湖‘s Blog——MySQL入门到精通 —— 囊括 MySQL 入门 以及 SQL 语句优化 —— 索引原理 —— 性能分析 —— 存储引擎特点以及选择 —— 面试题
Configure zabbix auto-discovery and auto-registration.
监管再次重拳出击,后市如何?2021-05-22
Reading IDEO, Design Changes Everything
OpenMMLab简介
多个驻外使领馆发提醒 事关赴华出行、人身财产安全
RKMPP库快速上手--(一)RKMPP功能及使用详解
网络安全第六次作业
如何解决1045无法登录mysql服务器
RowBounds[通俗易懂]
[typescript] Use the RangePicker component in antd to implement time limit the previous year (365 days) of the current time