Linux中的无人职守安装脚本kickstart

    Linux中的无人职守安装脚本kickstart

 

 一.kickstart自动安装脚本的作用      

 在企业中安装多台操作系统时面临的问题
当安装Linux操作系统时,安装过程会需要回答很多关于设定的问题
这些问题必须手动选择,否则无法进行安装
当只安装1台Linux系统,手动选择设定工作量比较轻松
当安装多台Linux,这些设定需要重复多次,这些重复动作是效率底下的操作

 如何解决以上问题?
用文件来记录所有安装过程中问题的答案,并让所有需要安装的主机自动读取


 kickstart作用
以上解决方案中记录系统安装过程中所有问题答案的文件叫kickstart脚本

     二.实验环境     
1.主机名称  :westos_node1
2.ip        :172.25.254.20
3.火墙,selinux关闭
4.httpd服务开启
5.配置软件仓库能正常工作



     三.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


 共享资源的意义
在安装操作系统时,每个被安装的操作系统都要有安装资源
如果使用镜像安装,每个安装的系统都需要加载一个镜像
这样会浪费存储,通过网络来共享镜像中的资源,让安装系统的主机能通过
网络访问被共享的资源这样就可以解决多台主机需要多个镜像安装的问题



 用模板自作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               把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 --no-activate    网卡设定
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.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         系统安装后自动执行的脚本
%end


ksvalidator   /var/www/html/westos.cfg       检测westos.cfg语法

chmod 644 /var/www/html/westos.cfg


  搭建dhcpd服务器 
让被安装的主机可以获得ip来访问网络资源及kickstart文件

 搭建方式
之前在网络管理单元中的方式在此使用即可



     测试      
在系统安装基面选择
Install Red Hat Enterprise Linux 8.0.0    <---- <TAB>键

ks=http://172.25.254.20/westos.cfg      <----<ENTER>键

查看效果

猜你喜欢

转载自blog.csdn.net/qq_47714288/article/details/109634890