SHELL configuration script installed unattended batch of PXE

PXE installed unattended batch script

Preparation 2 LAN:

The first NIC to use NET, installation services for
the second network card to provide services 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

Guess you like

Origin blog.51cto.com/14469918/2441174