14.解放双手之无人职守安装脚本kickstart

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

#在企业中安装多台操作系统时面临的问题
当安装Linux操作系统时,安装过程需要回答很多设定问题,要手动选择,否则无法安装
当只安装1台Linux系统,手动选择设定工作量比较轻松
当安装多台Linux,这些设定需要重复多次,这些工作量就非常繁重了
那么我们如何解决批量安装?
用文件来记录所有安装过程中问题的答案,并让所有需要安装的主机自动读取
#kickstart作用#
以上解决方案中记录系统安装过程中所有问题答案的文件叫kickstart脚本

二.实验环境

1.主机名称 :westos
2.ip :172.25.254.19
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               #安装httpd
systemctl enable --now httpd       #开启httpd
systemctl disable --now firewalld  #关闭防火墙
setenforce 0    #selinux调整为警告模式
mkdir /var/www/html/ks             #创建文件夹
cp /root/anaconda-ks.cfg /var/www/html/ks/  #复制
cd /var/www/html/ks/
mv anaconda-ks.cfg  westos.cfg    #修改文件名称
chmod 644 westos.cfg              #给予权限读写

在这里插入图片描述在这里插入图片描述在这里插入图片描述
测试资源共享:在浏览器firefox中
http://172.25.254.19/ks/westos
在这里插入图片描述2.共享资源的意义
在安装操作系统时,每个被安装的操作系统都要有安装资源
如果使用镜像安装,每个安装的系统都需要加载一个镜像
这样会浪费存储,通过网络来共享镜像中的资源,让安装系统的主机能通过
网络访问被共享的资源这样就可以解决多台主机需要多个镜像安装的问题
#用模板自作kickstart#在已经装好的rhel8中,/root/anaconda-ks.cfg 就是安装当前系统时回答的所有问题的答案
生成的kickstart,此文件为kickstart模板
cp /root/anaconda-ks.cfg /var/www/html/ks/westos.cfg
vim /var/www/html/ks/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.SIxQ4rAWK19QBUvXP1et1us191K5w6GlIZvyEMaKx1FBK6EFTiwHC0X5DiktBfJzRsCy
 --iscrypted --gecos="westos"
 # Disk partitioning information
 part / --fstype="xfs" --grow --size=1   ##让/分区使用全部空闲磁盘空间
 part /boot --fstype="xfs" --size=200    ##/boot分区大小为512M
 part swap --fstype="swap" --size=500    ##swap分区大小为4096M
 reboot
 %packages
 @base       ##安装软件组base
 httpd       ##安装单个软件httpd
 %end

 #%pre       #系统安装前自动执行的脚本
 #%end

 %post       #系统安装后自动执行的脚本,配置网卡 
 cat >> /etc/yum.repos.d/westos.repo <<EOF
 [AppStream]
 name=AppStream
 baseurl=http://172.25.254.20/westos_8/AppStream
 gpgcheck=0
 [BaseOS]
 name=BaseOS
 baseurl=http://172.25.254.20/westos_8/BaseOS
 gpgcheck=0
 EOF
 %end
保存退出

四、搭建dhcpd服务器

让被安装的主机可以获得ip来访问网络资源及kickstart文件
http://172.25.254.19/ks/westos

测试

全自动化安装linux系统
配置脚本文件 自动安装系统
cd /mnt
vim westos_vm.sh
#配置westos_vm.sh

cat westos_vm.sh
#!/bin/bash
qemu-img create -f qcow2 /var/lib/libvirt/images/$1.qcow2 10G -o lazy_refcounts=off
virt-install \
  --name $1 \
  --memory 2048 \
  --vcpus 1 \
  --disk /var/lib/libvirt/images/$1.qcow2,bus=virtio \
  --network bridge=br0,model=virtio \
  --location http://172.25.254.250/rhel8.2 \
  --extra-args "ks=http://172.25.254.19/ks/westos.cfg" \
  --os-variant rhel8.2
保存

配置系统安装加载过程中,系统安装配置自动选择文件
cd /var/www/html/ks
vim westos.cfg #配置安装过程中所有问题答案的文件叫kickstart脚本

#version=RHEL8
#ignoredisk --only-use=sda
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Reboot after installation
reboot
# Use graphical install
graphical
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8 --addsupport=zh_CN.UTF-8

# Network information
network  --bootproto=dhcp --onboot=on --ipv6=auto --no-activate
repo --name="AppStream" --baseurl=http://172.25.254.250/rhel8.2/AppStream
# Use network installation
url --url="http://172.25.254.250/rhel8.2"
# Root password
rootpw --iscrypted $6$cN4q3KwUvzIYh2d/$YtF2ZGyA6tDn/Kt3J0sL60GiurtNOjyOuDfZMubDGRmYdivW1c8fxbTLn3MXyZmGK1z.ZfqBZZVYcTx7UjmB7.
# X Window System configuration information
#xconfig  --startxonboot
firstboot --disable
# System services
#services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai
# Disk partitioning information
part swap --fstype="swap" --size=4096
part /boot --fstype="xfs" --size=512
part / --fstype="xfs" --grow  --size=1

%post --nochroot
touch /mnt/westosfile{1..5}
%end

%packages
@base

%end

安装kickstar
在这里插入图片描述
配置 /var/www/html/ks/westos.cfg
在这里插入图片描述

kickstart  /var/www/html/ks/westos.cfg     #检测westos.cfg有无语法问题

配置/mnt/westos_vm.sh 脚本文件
在这里插入图片描述退出保存
配置完成
运行

sh westos_vm.sh 虚拟机名称

在这里插入图片描述
完成自动化安装
查看效果
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值