一、Kickstart自动脚本的作用
传统装机需要手动设置各种参数,按部就班的安装,若需要同时安装上百台机器,重复性工作太多,而且耗费人力和时间,kickstart则可以生成一个设置好各种参数的脚本ks.cfg文件,然后在装机是选择ks文件可自动按照ks文件中设定的参数安装系统
二、实验环境
主机名称:westos656
ip: 172.25.254.230
防火墙、selinux关闭
http服务开启
软件仓库正常使用
三、Kickstart自动脚本的制作
在已经安装了rhel8的主机上, /root/anaconda-ks.cfg 就是安装当前主机系统时回答所有问题的答案生成的Kickstart,此文件可当做模板。
操作步骤
1.资源共享
dnf install httpd -y
systemctl enable --now httpd
systemctl disable --now firewalld
setenforce 0 #selinux调为警告模式
mkdir /var/www/html/westos_8
mount /dev/cdrom /var/www/html/westos_8
2.资源共享测试
172.25.254.230/westos_8
3.使用模板制作Kickstart
cp /root/anaconda-ks.cfg /var/www/html/westos.cfg
vim /var/www/html/westos.cfg
#version=RHEL8
ignoredisk --only-use=sda #只是使用第一块硬盘
# Partition clearing information
clearpart --all --initlabel #清空选中硬盘的所有内容
# Use graphical install
#graphical #安装过程开启图形
text #安装过程不开图形
repo --name="AppStream" --baseurl=http://192.168.158.101/rhel/AppStream
#安装资源
# Use netsource installation media
url --url="http://192.168.158.101/rhel/" #系统安装资源
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us' #键盘布局
# System language
lang en_US.UTF-8 --addsupport=zh_CN.UTF-8 #语言支持
# Network information
network --bootproto=dhcp --device=ens16 --onboot=on --ipv6=auto --no-activate
#网卡设定
network --hostname=localhost.localdomain #主机名设定
# Root password
rootpw --plaintext YOUPASSWORD
authselect --enableshadow --passalgo=sha512 #默认开启的加密认证方式
# X Window System configuration information
#xconfig --startxonboot #安装完成后开机启动图形
skipx #安装完成后开机不启动图形
# Run the Setup Agent on first boot
firstboot --disabl #首次启动初始化禁止
# System services
services --disabled="chronyd,firewalld" --enabled="sshd"
#在开机时开启或关闭的服务
# System timezone
timezone Asia/Shanghai --isUtc --nontp
#系统时区,启用utc计时方式,不其同ntp时间同步
user --name=westos --
password=$6$W8HmY8FoDLmjcv65$Xo.SIxQ4rAWK19QBUvXP1et1us191K5w6GlIZvyEMaKx1FBK6EFTiwHC0X5DiktBfJzRsCyxDlmVemkSWfHlx1
--iscrypted --gecos="westos"
# Disk partitioning information
part / --fstype="xfs" --grow --size=1 # / 分区使用全部剩余磁盘空间
part /boot --fstype="xfs" --size=200 #/boot分区大小为200M
part swap --fstype="swap" --size=500 #swap分区大小为500M
reboot
%packages
@base #安装软件组base
httpd #安装单个软件httpd
%end
#%pre #系统安装前自动执行的脚本
#%end
%post #系统安装后自动执行的脚本
cat >> /etc/yum.repos.d/westos.repo <<EOF
[AppStream]
name=AppStream
baseurl=http://192.168.158.101/rhel/AppStream
gpgcheck=0
[BaseOS]
name=BaseOS
baseurl=http://192.168.158.101/rhel/BaseOS
gpgcheck=0
EOF
%end
ksvalidator ks.cfg #检查ks.cfg是否存在语法错误
四、实验
安装