實驗環境:
系統:centos7.5 本機IP:192.168.10.141/24
Kickstart可以實作批量安裝、部署系統環境快、可實作無人值守安裝。
實作原理:配置批量的安裝的伺服器,在伺服器端建立網絡鏡像、搭建DHCP服務、HTTP服務。當同子網内的裸機開機時選擇網絡安裝,網卡開始向伺服器擷取IP,IP擷取到之後通過TFTP服務擷取到啟動檔案。然後利用http通路伺服器端的HTTP服務,擷取到網頁下的鏡像開始安裝。
PXE(Preboot Execution Environment)可實作網卡在開機時作為啟動項啟動,進而接收網絡相關參數及啟動引導檔案。
一、配置防火牆和selinux
首先把selinux和防火牆關閉
關閉防火牆:
# systemctl stop firewalld
# systemctl disable firewalld
永久關閉selinux:
# vim /etc/sysconfig/selinux
SELINUX=disabled
關閉啟動的selinux:
# setenforce 0
[[email protected] ~]# getenforce
Permissive
二、安裝服務
安裝所需要的服務
#yum install tftp-server dhcp httpd xinetd syslinux –y
配置dhcp
cat >>/etc/dhcp/dhcpd.conf<<EOF
ddns-update-style interim;
subnet 192.168.10.0 netmask 255.255.255.0 {
option domain-name-servers 223.5.5.5;
option domain-name "internal.example.org";
range 192.168.10.100 192.168.10.110;
option subnet-mask 255.255.255.0;
option routers 192.168.10.141;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.10.141;
filename "/pxelinux.0";
}
EOF
# systemctl start dhcpd //開啟服務
# systemctl enable dhcpd //開機自啟
開啟TFTP
# vim /etc/xinetd.d/tftp
把disable設定為no 開啟TFTP:

# systemctl start xinetd //啟動服務
# systemctl enable xinetd //開機啟動
開啟http服務并挂載鏡像
# systemctl start httpd
# systemctl enable httpd
将裝有centos7.5系統的CD光牒鏡像/dev/cdrom挂載到http服務的根目錄
# mkdir /var/www/html/os/ //建立挂載目錄
# mount /dev/cdrom /var/www/html/os/ //挂載系統鏡像
通路http://ip位址/os/ 出現鏡像檔案内容
從鏡像中找到相關的配置檔案
# cp /var/www/html/os/images/pxeboot/vmlinuz /var/lib/tftpboot/
# cp /var/www/html/os/images/pxeboot/initrd.img /var/lib/tftpboot/
# mkdir -p /var/lib/tftpboot/pxelinux.cfg
# cp /var/www/html/os/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
修改pxe連接配接安裝配置
# vim /var/lib/tftpboot/pxelinux.cfg/default
default linux //修改
append initrd=initrd.img ks=http://192.168.10.141/ks.cfg ksdevice=ens33 ip=dhcp
# chmod -R 644 /var/lib/tftpboot/pxelinux.cfg/default //設定檔案檔案權限
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ //拷貝引導檔案到tftp服務根目錄下
三、配置kickstart自動安裝檔案
# yum -y install system-config-kickstart //安裝kickstart
# system-config-kickstart //啟動kickstart配置界面
基本配置
安裝方法
安裝引導
分區設定
設定啟動分區
設定交換分區
設定根分區
網絡設定
密碼驗證
防火牆設定
圖形環境設定
後續安裝設定,後續寫入配置檔案
儲存配置檔案ks.cfg
ks.cfg檔案内容:
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$Lb09cUNd$8tOblm49AMbnMkTbsan7C0
# Use network installation
url --url="http://192.168.10.141/os"
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Africa/Abidjan --isUtc
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot --fstype="ext4" --size=1024
part swap --fstype="swap" --size=2048
part / --fstype="ext4" --grow --size=1
#後續添加的内容
###要安裝的包
%packages
#選擇最小化安裝
@^minimal
#安裝核心元件
@core
###根據需要安裝
net-tools
ntp
ntpdate
vim-enhanced
wget
%end
###以%end結尾
四、自動化安裝
注意:客戶機記憶體要2GB以上否則會報錯
設定啟動順序(磁盤無法檢測到引導檔案就會網絡啟動)
全部自動化安裝