实验环境:
系统: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系统的光盘镜像/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以上否则会报错
设置启动顺序(磁盘无法检测到引导文件就会网络启动)
全部自动化安装