shell脚本一键桌面化装机(pxe配合kickstart无人值守)

文章目录

  • pxe配合kickstart无人值守批量装机
  • 一、shell脚本一键桌面化装机

pxe配合kickstart无人值守批量装机

图文详解部分请看PXE配合Kickstart无人值守——批量装机简单如喝水(详细)

一、shell脚本一键桌面化装机

#!/bin/bash
#检测是否挂载
df | grep "sr0" &> /dev/null
if [ $? -eq 0 ];then
echo "磁盘已挂载"
else
mount /dev/sr0 /mnt &> /dev/null
fi

#安装并启动TFTP:tftp-server xinetd 
yum -y install tftp-server xinetd &> /dev/null

#修改tftp服务的配置文件:/etc/xinetd.d/tftp
sed -i 's/yes/no/g' /etc/xinetd.d/tftp
systemctl start tftp
systemctl enable tftp
systemctl start xinetd
systemctl enable xinetd

#安装dhcp
yum -y install dhcp &> /dev/null

#修改dhcp配置文件
cat /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example > /etc/dhcp/dhcpd.conf
echo 'ddns-update-style none;
next-server 192.168.184.30;
filename "pxelinux.0";' >> /etc/dhcp/dhcpd.conf

echo   'subnet 192.168.184.0 netmask 255.255.255.0 {
range 192.168.184.100 192.168.184.200;
option routers 192.168.184.30;
}' >> /etc/dhcp/dhcpd.conf
systemctl restart dhcpd
systemctl enable dhcpd

#准备linux内核、初始化镜文件
cp /mnt/images/pxeboot/initrd.img /var/lib/tftpboot
cp /mnt/images/pxeboot/vmlinuz /var/lib/tftpboot


#准备pxe引导程序
yum -y install syslinux &> /dev/null
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

#安装ftp服务,准备centos7安装源
yum -y install vsftpd &> /dev/null  #安装vsftpd服务

mkdir /var/ftp/centos7              #在ftp根目录下创建目录centos7
cp -rf /mnt/* /var/ftp/centos7/     #将镜像文件强制复制到centos7目录中,可加&让它自己后台运行
systemctl start vsftpd              #开启vsftpd服务
systemctl enable vsftpd             #开启vsftpd服务开机自启

mkdir /var/lib/tftpboot/pxelinux.cfg
touch /var/lib/tftpboot/pxelinux.cfg/default

echo 'default auto                              
prompt 1                                

label auto                      
kernel vmlinuz          
append initrd=initrd.img method=ftp://192.168.184.30/centos7

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

label linux rescue                              
kernel vmlinuz
append rescue initrd=initrd.img method=ftp://192.168.184.30/centos7' > /var/lib/tftpboot/pxelinux.cfg/default

systemctl stop firewalld.service
setenforce 0
echo "pxe配置完成"

echo "即将配置kickstart"
#安装system-config-kickstart 工具
yum install -y system-config-kickstart

cp /root/ks.cfg /var/ftp/ks.cfg

sed -i '6d' /var/lib/tftpboot/pxelinux.cfg/default

i=(append initrd=initrd.img method=ftp://192.168.184.30/centos7 ks=ftp://192.168.184.30/ks.cfg)

sed -i "5a `echo ${i[*]}`" /var/lib/tftpboot/pxelinux.cfg/default

sed -i 's/prompt 1/prompt 0/' /var/lib/tftpboot/pxelinux.cfg/default

shell脚本一键桌面化装机(pxe配合kickstart无人值守)_第1张图片
shell脚本一键桌面化装机(pxe配合kickstart无人值守)_第2张图片
shell脚本一键桌面化装机(pxe配合kickstart无人值守)_第3张图片
/root/ks.cfg的内容

#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$nqSbw4W/$IrR8rQYA5xOhLzPrybobg1
# Use network installation
url --url="ftp://192.168.184.30/centos7"
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled

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

%post --interpreter=/bin/bash
rm -rf /etc/yum.repos.d/*
echo '[local]
name=local
baseurl=ftp://192.168.184.30/centos7
enabled=1
gpgcheck=0' > /etc/yum.repos.d/local.repo
%end


%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

你可能感兴趣的:(Linux-CentOS7,linux,centos,shell,运维,服务器)