pxe + kickstart 系统自动化部署
关键组件如下:
- PXE 服务器: 传统服务器操作系统都支持, 我这块用的Rocky Linux 9
- 客户机: 目标安装的(需要支持 PXE 启动)
- DHCP 服务器(可以使用 dnsmasq 提供 DHCP 和 TFTP 服务)
- HTTP 服务器(用于存放 Kickstart 配置文件和安装介质)
1. 安装软件
dnf install -y dhcp-server tftp-server syslinux httpd tftp tftp-server
2. 配置DHCP服务器
编辑配置文件 /etc/dhcp/dhcpd.conf
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.170 192.168.1.179;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8;
default-lease-time 600;
max-lease-time 7200;
next-server 192.168.1.3; # TFTP 服务器地址
filename "pxelinux.0"; # PXE 引导文件
}
启动服务器
systemctl enable --now dhcpd
systemctl status dhcpd
查看ip分配情况
[root@localhost ~]# cat /var/lib/dhcpd/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.4.2b1
# authoring-byte-order entry is generated, DO NOT DELETE
authoring-byte-order little-endian;
server-duid "\000\001\000\001/W\335!\000\014)1U<";
lease 192.168.1.170 {
starts 1 2025/03/03 06:37:17;
ends 1 2025/03/03 06:47:17;
cltt 1 2025/03/03 06:37:17;
binding state active;
next binding state free;
rewind binding state free;
hardware ethernet 00:0c:29:6a:55:ec;
uid "\000VM\034!>7h\256Azl\342\026jU\354";
set vendor-class-identifier = "PXEClient:Arch:00000:UNDI:002001";
}
lease 192.168.1.170 {
starts 1 2025/03/03 06:37:17;
ends 1 2025/03/03 06:47:17;
tstp 1 2025/03/03 06:47:17;
cltt 1 2025/03/03 06:37:17;
binding state free;
hardware ethernet 00:0c:29:6a:55:ec;
uid "\000VM\034!>7h\256Azl\342\026jU\354";
set vendor-class-identifier = "PXEClient:Arch:00000:UNDI:002001";
}
3. 配置tftp工作目录
# 确保 /var/lib/tftpboot 存在
sudo mkdir -p /var/lib/tftpboot
sudo chmod -R 777 /var/lib/tftpboot
sudo cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
sudo cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/
sudo cp /usr/share/syslinux/memdisk /var/lib/tftpboot/
4. 配置HTTP服务
这个就是镜像地址 http://192.168.1.3/centos/
sudo mkdir -p /var/www/html/centos
cd /var/www/html/centos
sudo mount -o loop CentOS镜像文件.iso /mnt
sudo cp -r /mnt/* /var/www/html/centos/
5. 配置KickStart文件
/var/www/html/ks.cfg 这个文件放在http工作目录下, 需要访问http地址时可以访问到, 例如 http://192.168.1.3/ks.cfg
install
url --url=http://192.168.1.3/centos/
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang zh_CN.UTF-8
# Network information
network --bootproto=dhcp --device=ens192 --onboot=on
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$cad7VYFPmMX5A/jh$1cP7mqOQY1qW2npFViqa.FJ1mkWLN8i9KbrDzB50Vi6D6dnljlfWkhcNCv/DAKXbHmDb4hyyZIH15AlPaXcoT.
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype=ext4 --asprimary --size=1024
part / --fstype=ext4 --asprimary --size=1 --grow
firewall --disabled
selinux --disabled
%packages
@^minimal
@core
chrony
net-tools
lrzsz
kexec-tools
unzip
sysstat
wget
net-tools
screen
lsof
tcpdump
nc
mtr
openssl-devel
vim
bash-completion
nmap
telnet
tree
ntpdate
gcc
patch
libffi-devel
python-devel
zlib-devel
bzip2-devel
ncurses-devel
sqlite-devel
readline-devel
tk-devel
gdbm-devel
xz-devel
openssl
bitmap-fonts-cjk
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
reboot
5. 配置PXE引导菜单
/var/lib/tftpboot/pxelinux.cfg/default APPEND里面分别指明了系统文件位置, 和kickstart引导文件位置
default menu.c32
prompt 5
timeout 30
MENU TITLE Centos 7.6 PXE Menu
LABEL linux
MENU LABEL Install Centos 7.6
KERNEL vmlinuz
APPEND initrd=initrd.img inst.repo=http://192.168.1.3/centos/ ks=http://192.168.1.3/ks.cfg quiet net.ifnames=0 biosdevname=0
6. 启动服务
sudo systemctl enable --now httpd
sudo systemctl enable --now tftp
7. 开启客户机服务器验证
初学linux,每学到一点东西就写一点,如有不对的地方,恳请包涵!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能
2022-03-03 9.coredns组件详解
2022-03-03 8.kube-proxy组件详解