kickstart+pxe实现自动批量安装rhel7操作系统

什么是kickstart

Kickstart是红帽企业Linux和其他基于RPM的Linux发行版中用于自动化安装的工具。通过记录人工干预填写的各种参数并生成ks.cfg文件,Kickstart能够在无需人工干预的情况下自动完成操作系统的安装。这一特性使其在需要批量部署系统时显得尤为高效。

pxe简介

PXE(预启动执行环境)是一种网络引导技术,允许计算机在没有本地存储设备的情况下通过网络启动操作系统。PXE的全称是Preboot Execute Environment,由Intel提出,旨在通过网络引导系统。它广泛应用于需要大规模部署操作系统的场景,例如企业或学校的计算机实验室、数据中心等。通过PXE技术,可以大大简化安装过程,提高配置效率和一致性。同时,它在无盘工作站、系统恢复和虚拟化环境等方面也有广泛应用。

pxe工作流程

1、PXE客户端启动:当计算机启动时,如果BIOS或UEFI设置为网络启动,则内置的PXE客户端会向网络发送DHCP请求,寻找DHCP服务器。

2、DHCP服务器响应:DHCP服务器响应该请求,为客户端分配IP地址,并提供TFTP服务器的位置以及引导文件名。

3、下载引导文件:PXE客户端通过TFTP协议从指定的TFTP服务器下载引导文件,通常是pxelinux.0。这个文件是小型的PXE引导程序,用于进一步加载操作系统内核和初始化文件系统。

4、执行引导文件:客户端执行下载的引导文件,该文件继续引导过程,通常包括下载更多必要的文件如内核和根文件系统。

5、启动操作系统:最后,客户端加载内核和初始化文件系统,并最终启动操作系统。

配置步骤

实验环境

1、rhel7主机

2、开启主机图形化界面

3、配置网络可用

4、配置系统软件仓库

5、关闭VMware DHCP功能

1、kickstart自动安装脚本制作

创建软链接

ln -s /rhel7/ /var/www/html/

测试浏览器能否访问172.25.254.100/rhel7

安装图形化生成kickstart自动安装脚本的工具

yum install system-config-kickstart -y

启动图形制作工具

system-config-kickstart

基本配置

安装方法

引导安装程序选项

分区信息

网络配置

防火墙配置

显示配置

安装后脚本

点击文件保存,选择.cfg文件的保存位置

编辑ks.cfg文件

[root@localhost ~]#vim ks.cfg

[root@localhost ~]# cat ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$wKNajUe6$0tKWZP4dZm6y6bZqpQHt1.
# System language
lang zh_CN
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Use network installation
url --url="http://172.25.254.100/rhel7"
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="xfs" --size=1024
part swap --fstype="swap" --size=512
part / --fstype="xfs" --grow  --size=1

%packages
@base
httpd
%end

%post
mkdir -p /rhel7

echo mount /dev/vdrom /rhel7 >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
cat > /etc/yum.repos.d/rhel7.repo << EOF
[rhel7]
name=rhel7
baseurl=file:///rhel7/
gpgcheck=0
EOF

yum install gcc -y
%end

将ks.cfg文件复制到/var/www/html/目录下

[root@localhost ~]#cp /root/ks.cfg /var/www/html/

2、搭建DHCP服务并测试kickstart脚本

安装dhcp服务为其他服务器提供分配IP的功能

[root@localhost ~]#yum install dhcp -y

[root@localhost ~]# rpm -qc dhcp
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

生成配置文件

[root@localhost ~]# \cp -f /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf

编辑dhcp配置文件并启动dhcp服务

[root@localhost ~]# vim /etc/dhcp/dhcpd.conf 
[root@localhost ~]# cat /etc/dhcp/dhcpd.conf 
# dhcpd.conf
# Sample configuration file for ISC dhcpd

# option definitions common to all supported networks...
option domain-name "du.org";
option domain-name-servers 114.14.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 172.25.254.0 netmask 255.255.255.0 {
  range 172.25.254.30 172.25.254.40;
  option routers 172.25.254.2;

}

[root@localhost ~]# systemctl enable --now dhcpd

新建一台虚拟机进行测试

3、搭建pxe网络安装环境实现服务器自动部署

安装syslinux

[root@localhost ~]# yum search pxelinux
[root@localhost ~]# yum install syslinux.x86_64 -y

安装tftp,共享pxelinux.0数据文件的网络服务

[root@localhost ~]# yum search tftp
[root@localhost ~]# yum install tftp-server.x86_64 -y

[root@localhost ~]# rpm -ql tftp-server 
/etc/xinetd.d/tftp
/usr/lib/systemd/system/tftp.service
/usr/lib/systemd/system/tftp.socket
/usr/sbin/in.tftpd
/usr/share/doc/tftp-server-5.2
/usr/share/doc/tftp-server-5.2/CHANGES
/usr/share/doc/tftp-server-5.2/README
/usr/share/doc/tftp-server-5.2/README.security
/usr/share/man/man8/in.tftpd.8.gz
/usr/share/man/man8/tftpd.8.gz
/var/lib/tftpboot

启动tftp服务

systemctl enable --now tftp

复制相关文件到/var/lib/tftpboot/目录下

[root@localhost ~]# cp /rhel7/isolinux/* /var/lib/tftpboot/
[root@localhost ~]# cp /usr/share/syslinux/pxe
pxechain.com  pxelinux.0    
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
[root@localhost ~]# cd /var/lib/tftpboot/

创建/var/lib/tftpboot/pxelinux.cfg目录,并将isolinux文件复制到default文件中

[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# cp isolinux.cfg pxelinux.cfg/default

编辑dhcp配置文件并重启DHCP服务

[root@localhost tftpboot]# vim /etc/dhcp/dhcpd.conf 
[root@localhost tftpboot]# cat /etc/dhcp/dhcpd.conf

......
subnet 172.25.254.0 netmask 255.255.255.0 {
  range 172.25.254.30 172.25.254.40;
  option routers 172.25.254.2;
  next-server 172.25.254.100;
  filename "pxelinux.0"
}

[root@localhost tftpboot]# systemctl enable --now dhcpd

编辑 default文件

[root@localhost tftpboot]# vim /var/lib/tftpboot/pxelinux.cfg/default 

[root@localhost tftpboot]# cat /var/lib/tftpboot/pxelinux.cfg/default 

......

label linux
  menu label ^Install Red Hat Enterprise Linux 7.9
  menu default
  kernel vmlinuz
  append initrd=initrd.img repo=http://172.25.254.100/rhel7 ks=http://172.25.254.100/ks.cfg quiet
......

新建一台虚拟机进行测试

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值