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

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

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

如何解决以上问题?

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

kickstart作用

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

二.实验环境

1.主机名称 :westos_node1

2.ip :192.168.2.100

3.关闭火墙

4.httpd服务开启

5.配置软件仓库能正常工作

三.kickstart自动安装脚本的制作

在已经装好的node1中,/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/rhel8.2

mount /dev/cdrom /var/www/html/rhel8.2

测试资源共享:

firefox http://192.168.2.200/rhel8.2

共享资源的意义

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

用模板自作kickstart

在已经装好的node1中,/root/anaconda-ks.cfg 就是安装当前系统时回答的所有问题的答案 生成的kickstart,此文件为kickstart模板,然后修改其内容: 

cp /root/anaconda-ks.cfg /var/www/html/westos.ks  ##将文件复制到可以资源共享的目录            

vim /var/www/html/westos.ks   ##修改文件内容

#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 installationmedia

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

修改后的文件内容:

[root@westos_student50 Desktop]# vim /var/www/html/westos.ks
[root@westos_student50 Desktop]# cat  /var/www/html/westos.ks
#version=RHEL8
clearpart --none --initlabel
# Use graphical install
text
repo --name="AppStream" --baseurl=file:///run/install/sources/mount-0000-cdrom/AppStream

%packages
@base
httpd

%end

# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8 --addsupport=zh_CN.UTF-8

# Network information
network  --bootproto=dhcp --noboot=off

# Use network installation
cdrom
firstboot --disable

reboot

clearpart -all --initlabel

# Disk partitioning information
part / --fstype="xfs" --size=1
part /boot --fstype="xfs" --size=500
part swap --fstype="swap" --size=500

timezone Asia/shanghai --isUtc --nontp

rootpw --iscrypted $6$RHXiUh2H26uvF3zj$7v6.PzTltBqwwrwpkiD64BYQi6ZmsWn6z3AzxCqf9j1G8XDmOy3wF89UeTTDpBZ9sYGDT9L/15uED9QnvF45q1  

%post

touch /mnt/file{1..5}

%end

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

3.搭建dhcpd服务器

让被安装的主机可以获得ip来访问网络资源及kickstart文件

搭建方式

vim /etc/dhcp/dhcp.conf     ##更改文件

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "westos.org";
option domain-name-servers 114.114.114.114;

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

subnet 192.168.2.0 netmask 255.255.255.0 {
  range 192.168.2.220 192.168.2.210;
}

4.测试

在系统安装机面选择

Install Red Hat Enterprise Linux 8.0.0      <=====<tab>键

ks=http://192.168.2.200/westos.kz         <=====<ENTER>键

查看效果

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

溪野~~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值