一、kickstart自动安装脚本的作用
1.在企业中安装多台操作系统时面临的问题
- 当安装Linux操作系统时,安装过程会需要回答很多关于设定的问题
- 这些问题必须手动选择,否则无法进行安装
- 当只安装1台Linux系统,手动选择设定工作量比较轻松
- 当安装多台Linux,这些设定需要重复多次,这些重复动作是效率底下的操作
2.如何解决以上问题?
用文件来记录所有安装过程中问题的答案,并让所有需要安装的主机自动读取
3.kickstart作用
以上解决方案中记录系统安装过程中所有问题答案的文件叫kickstart脚本
二、实验环境
- 主机名称 :carry
- ip :172.25.254.20
- 火墙,selinux关闭
- httpd服务开启
- 配置软件仓库能正常工作
三、kickstart自动安装脚本的制作
- 在rhel7系统中提供图形的kickstart制作方式
- 在rhel8中已经把图形的工具取消,并添加到rhn网络中
- 在rhel8中如果无法通过rhn网络制作kickstart,可以使用模板生成
- #通过模板生成kickstart文件#
- 在已经装好的rhel8中,/root/anaconda-ks.cfg 就是安装当前系统时回答的所有问题的答案
- 生成的kickstart,此文件为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
测试资源共享:
firefox http://172.25.254.20/westos_8
![](https://img-blog.csdnimg.cn/20200802115305887.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NzcyNzM4Mw==,size_16,color_FFFFFF,t_70)
- 共享资源的意义
- 在安装操作系统时,每个被安装的操作系统都要有安装资源
- 如果使用镜像安装,每个安装的系统都需要加载一个镜像
- 这样会浪费存储,通过网络来共享镜像中的资源,
- 让安装系统的主机能通过,网络访问被共享的资源
- 这样就可以解决多台主机需要多个镜像安装的问题
2.用模板自作kickstart
- 在已经装好的rhel8中,
- /root/anaconda-ks.cfg 就是安装当前系统时回答的所有问题的答案
- 生成的kickstart,此文件为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 --drives=sda ##把sda硬盘的所有内容删掉
-
# Use graphical install
-
#graphical ##安装过程开启图形
-
text ##安装过程不开图形
-
repo --name="AppStream" --baseurl=http://172.25.254.20/westos_8/AppStream
-
##软件安装资源
-
# Use netsource installation media
-
url --url="http://172.25.254.20/westos_8" ##系统安装资源
-
# 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=ens160 --onboot=on --ipv6=auto --noactivate
-
##网卡设定
-
network --hostname=localhost.localdomain ##主机名设定
-
# Root password
-
rootpw --plaintext westos
-
authselect --enableshadow --passalgo=sha512 ##系统默认开启的 加密认证方式
-
# X Window System configuration information
-
#xconfig --startxonboot ##安装完成后开机启动图形
-
skipx ##安装完成后开机不启动图形
-
# Run the Setup Agent on first boot
-
firstboot --disable ##首次启动初始化禁止
-
# System services
-
services --disabled="chronyd,firewalld" --enabled="sshd" ##在开机时开启或关闭的服务
-
# System timezone
-
timezone Asia/Shanghai --isUtc --nontp ##系统时区,启用utc计时方式,不其同ntp时间同步
-
#user --name=westos -password=$6$W8HmY8FoDLmjcv65$Xo.SIx
-
Q4rAWK19QBUvXP1et1us191K5w6GlIZvyEMaKx1FBK6EFTiwHC0X5DiktBfJzRsC
-
--iscrypted --gecos="westos"
-
# Disk partitioning information
-
part / --fstype="xfs" --ondisk=sda --grow --size=1 ##让/分区使用全部空闲磁盘空间
-
part /boot --fstype="xfs" --ondisk=sda --size=200 ##/boot 分区大小为200M
-
part swap --fstype="swap" --ondisk=sda --size=500 ##swap 分区大小为500M
-
-
%packages
-
@base ##安装软件组base
-
httpd ##安装单个软件httpd
-
%end
-
ksvalidator /var/www/html/westos.cfg ##检测westos.cfg语法
-
chmod 644 /var/www/html/westos.cfg
3.搭建dhcpd服务器
让被安装的主机可以获得ip来访问网络资源及kickstart文件
搭建方式 :之前在网络管理单元中的方式在此使用即可
vim /etc/dhcp/dhcpd.conf
4.测试
在系统安装基面选择
- Install Red Hat Enterprise Linux 8.0.0 <---- <TAB>键
- ks=http://172.25.254.20/westos.cfg <----<ENTER>键