这篇文章主要是技术实现,如果操作环境与本文一致,可直接复制,粘贴使用,已经批量部署1万台+服务器。步骤原理会在后面的文章中进行剖析,如果根据本文部署出现问题,可以在评论区交流。
实验环境:
[root@node1 ~]# cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)
# kickstart服务器:192.168.75.121
1. 部署dhcp:
在121服务器部署dhcp服务,为客户端分配IP。如果是虚拟机,可关闭虚拟机的dhcp服务。
yum install dhcp -y
cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cat > /etc/dhcp/dhcpd.conf <<EOF
option domain-name-servers 114.114.114.114;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.75.0 netmask 255.255.255.0 {
range 192.168.75.100 192.168.75.200;
option routers 192.168.75.2;
next-server 192.168.75.121;
filename "pxelinux.0";
}
EOF
# 启动dhcp服务:
systemctl start dhcpd && systemctl enable dhcpd
2. 挂载本地镜像:
yum install httpd -y
systemctl start httpd && systemctl enable httpd
mkdir -p /var/www/html/centos
mount /dev/cdrom /var/www/html/centos
# 设置永久挂载:
cat >> /etc/fstab <<EOF
/dev/cdrom /var/www/html/centos iso9660 defaults 0 0
EOF
3. 部署tftp:
yum install tftp-server xinetd -y
sed -i '/disable/s/yes/no/' /etc/xinetd.d/tftp
systemctl start xinetd && systemctl enable xinetd
yum -y install syslinux -y
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /var/www/html/centos/isolinux/{vesamenu.c32,splash.png,vmlinuz,initrd.img} /var/lib/tftpboot/
mkdir -p /var/lib/tftpboot/pxelinux.cfg
# cp /var/www/html/centos/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
cat > /var/lib/tftpboot/pxelinux.cfg/default <<EOF
default vesamenu.c32
timeout 600
menu background splash.png
menu title CentOS 7 Kickstart Install
label linux
menu label ^Install CentOS 7
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.75.121/ks.cfg
EOF
5. 部署应答文件:
cat >> /etc/yum.repos.d/local.repo <<EOF
[development]
name= centos 7 local repo
baseurl=http://192.168.75.121/centos
gpgcheck=0
EOF
yum install system-config-kickstart -y
echo '
install
keyboard 'us'
rootpw --iscrypted $1$Iky8z/yl$gjlD.1n7Y2ITlKG2ldEMK1
lang en_US
auth --useshadow --passalgo=sha512
text
firstboot --disable
selinux --disabled
firewall --disabled
reboot
timezone Asia/Shanghai
url --url="http://192.168.75.121/centos"
bootloader --location=mbr
zerombr
clearpart --all --initlabel
part /boot --fstype="xfs" --size=300
part swap --fstype="swap" --size=512
part / --fstype="xfs" --grow --size=1
%post --interpreter=/bin/bash
useradd lutixia
echo "123" | passwd --stdin lutixia
%end
%packages
@base
@debugging
@performance
-abrt-console-notification
-bash-completion
-bpftool
-bridge-utils
-bzip2
-chrony
-cryptsetup
-dmraid
-dosfstools
-ethtool
-fprintd-pam
-gnupg2
-hunspell
-hunspell-en
-kmod-kvdo
-kpatch
-ledmon
-libaio
-libstoragemgmt
-lvm2
-man-pages
-man-pages-overrides
-mdadm
-mlocate
-mtr
-nano
-ntpdate
-pinfo
-plymouth
-pm-utils
-rdate
-rfkill
-rng-tools
-rsync
-scl-utils
-setuptool
-smartmontools
-sos
-sssd-client
-tcpdump
-tcsh
-teamd
-time
-unzip
-usbutils
-vdo
-vim-enhanced
-virt-what
-wget
-which
-words
-xfsdump
-xz
-yum-langpacks
-yum-utils
-zip
%end
' > /var/www/html/ks.cfg
6. 准备一台客户机(物理机或者虚拟机):
如果是虚拟机可以去掉cd,usb,打印机等设备,内存设置2G以上,直接启动即可实现自动部署。
获取文章更新,以及常用软件,可以关注公众号: 笨办法学linux
网友评论