PXE(Pre-boot Execution Environment
,预启动执行环境),通过网络接口启动计算机,不依赖本地存储设备(如硬盘)或本地已安装的操作系统。
PXE 与 kickstart 安装系统,实际上 COBBLER 程序就是 PXE 的一种封装。
- 由 INTEL 和 Systemsoft 公司于1999年9月20日公布
- C/S 的工作模式
- PXE客户端会调用网际协议(IP)、用户数据报协议(UDP)、动态主机设定协议(DHCP)、小型文件传输协议(TFTP)等网络协议
实验环境
属性 | 值 |
---|---|
操作系统 | CentOS Linux release 7.5.1804 (Core) |
网卡地址 | 192.168.100.1/24 |
光盘镜像 | CentOS-7-x86_64-DVD-1804.iso |
原理图
部署服务
部署 DHCP 服务
安装 DHCP
# yum install dhcp -y
配置 DHCP
# vim /etc/dhcp/dhcpd.conf
修改以下字段
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.100.0 netmask 255.255.255.0 {
option routers 192.168.100.2;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.100.2;
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 192.168.100.60 192.168.100.100;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.100.10;
filename "pxelinux.0";
}
参数解析
参数 | 解析 |
---|---|
option routers | 网关 |
option subnet-mask | 子网掩码 |
option domain-name-servers | DNS 服务器 |
range dynamic-bootp | 将要部署的区段 |
启动 DHCP
# systemctl start dhcpd
# systemctl enable dhcpd
部署 TFTP 服务
安装 TFTP
yum install -y tftp-server tftp syslinux-tftpboot
配置 TFTP
# cp /var/ftp/pub/images/pxeboot/initrd.img /var/lib/tftpboot/
# cp /var/ftp/pub/images/pxeboot/vmlinuz /var/lib/tftpboot/
# mkdir /var/lib/tftpboot/pxelinux.cfg
写入配置文件
# vim /var/lib/tftpboot/pxelinux.cfg/default
default linux
prompt 1
timeout 60
display boot.msg
label linux
kernel vmlinuz
append initrd=initrd.img text ks=ftp://192.168.100.10/ks.cfg
部署 XINETD 服务
安装 XINETD
yum install -y xinetd
配置 XINETD
# vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
小贴士:disable 参数默认是 yes 的,改为 no 即可。
启动 XINETD
# systemctl start xinetd
# systemctl enable xinetd
配置 kickstart
以当前系统安装文件 anaconda-ks.cfg
为模板
# cp ~/anaconda-ks.cfg /var/ftp/ks.cfg
修改配置模板
# vim /var/ftp/ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use network installation
url --url=ftp://192.168.100.147/pub
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
# 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=eno16777736 --onboot=yes --ipv6=auto
network --hostname=localhost.localdomain
# Root password
# root password rootroot
rootpw --iscrypted $6$7gdZF8XhDef10LyT$2uRiP4qFYaBBTgpggKU/BXKgMDJLWN/BriXXgBwyzkjaz9G9YP/xD08I1OJfgBcPMoURsE5inVIoX.J6aERmR0
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@^minimal
@core
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
配置文件授权
# chmod +r /var/ftp/ks.cfg
测试服务
以虚拟机为例,创建新机器进行自动化安装测试。
部署服务
部署 DHCP 服务
安装 DHCP
# yum install dhcp -y
配置 DHCP
# vim /etc/dhcp/dhcpd.conf
修改以下字段
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.100.0 netmask 255.255.255.0 {
option routers 192.168.100.2;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.100.2;
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 192.168.100.60 192.168.100.100;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.100.10;
filename "pxelinux.0";
}
参数解析
参数 | 解析 |
---|---|
option routers | 网关 |
option subnet-mask | 子网掩码 |
option domain-name-servers | DNS 服务器 |
range dynamic-bootp | 将要部署的区段 |
启动 DHCP
# systemctl start dhcpd
# systemctl enable dhcpd
部署 TFTP 服务
安装 TFTP
yum install -y tftp-server tftp syslinux-tftpboot
配置 TFTP
# cp /var/ftp/pub/images/pxeboot/initrd.img /var/lib/tftpboot/
# cp /var/ftp/pub/images/pxeboot/vmlinuz /var/lib/tftpboot/
# mkdir /var/lib/tftpboot/pxelinux.cfg
写入配置文件
# vim /var/lib/tftpboot/pxelinux.cfg/default
default linux
prompt 1
timeout 60
display boot.msg
label linux
kernel vmlinuz
append initrd=initrd.img text ks=ftp://192.168.100.10/ks.cfg
部署 XINETD 服务
安装 XINETD
yum install -y xinetd
配置 XINETD
# vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
小贴士:disable 参数默认是 yes 的,改为 no 即可。
启动 XINETD
# systemctl start xinetd
# systemctl enable xinetd
配置 kickstart
以当前系统安装文件 anaconda-ks.cfg
为模板
# cp ~/anaconda-ks.cfg /var/ftp/ks.cfg
修改配置模板
# vim /var/ftp/ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use network installation
url --url=ftp://192.168.100.147/pub
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
# 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=eno16777736 --onboot=yes --ipv6=auto
network --hostname=localhost.localdomain
# Root password
# root password rootroot
rootpw --iscrypted $6$7gdZF8XhDef10LyT$2uRiP4qFYaBBTgpggKU/BXKgMDJLWN/BriXXgBwyzkjaz9G9YP/xD08I1OJfgBcPMoURsE5inVIoX.J6aERmR0
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@^minimal
@core
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
配置文件授权
# chmod +r /var/ftp/ks.cfg
测试服务
以虚拟机为例,创建新机器进行自动化安装测试。
部署服务
部署 DHCP 服务
安装 DHCP
# yum install dhcp -y
配置 DHCP
# vim /etc/dhcp/dhcpd.conf
修改以下字段
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 192.168.100.0 netmask 255.255.255.0 {
option routers 192.168.100.2;
option subnet-mask 255.255.255.0;
option domain-name-servers 192.168.100.2;
option time-offset -18000; # Eastern Standard Time
range dynamic-bootp 192.168.100.60 192.168.100.100;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.100.10;
filename "pxelinux.0";
}
参数解析
参数 | 解析 |
---|---|
option routers | 网关 |
option subnet-mask | 子网掩码 |
option domain-name-servers | DNS 服务器 |
range dynamic-bootp | 将要部署的区段 |
启动 DHCP
# systemctl start dhcpd
# systemctl enable dhcpd
部署 TFTP 服务
安装 TFTP
yum install -y tftp-server tftp syslinux-tftpboot
配置 TFTP
# cp /var/ftp/pub/images/pxeboot/initrd.img /var/lib/tftpboot/
# cp /var/ftp/pub/images/pxeboot/vmlinuz /var/lib/tftpboot/
# mkdir /var/lib/tftpboot/pxelinux.cfg
写入配置文件
# vim /var/lib/tftpboot/pxelinux.cfg/default
default linux
prompt 1
timeout 60
display boot.msg
label linux
kernel vmlinuz
append initrd=initrd.img text ks=ftp://192.168.100.10/ks.cfg
部署 XINETD 服务
安装 XINETD
yum install -y xinetd
配置 XINETD
# vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
小贴士:disable 参数默认是 yes 的,改为 no 即可。
启动 XINETD
# systemctl start xinetd
# systemctl enable xinetd
配置 kickstart
以当前系统安装文件 anaconda-ks.cfg
为模板
# cp ~/anaconda-ks.cfg /var/ftp/ks.cfg
修改配置模板
# vim /var/ftp/ks.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Install OS instead of upgrade
install
# Use network installation
url --url=ftp://192.168.100.147/pub
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot --enable
# 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=eno16777736 --onboot=yes --ipv6=auto
network --hostname=localhost.localdomain
# Root password
# root password rootroot
rootpw --iscrypted $6$7gdZF8XhDef10LyT$2uRiP4qFYaBBTgpggKU/BXKgMDJLWN/BriXXgBwyzkjaz9G9YP/xD08I1OJfgBcPMoURsE5inVIoX.J6aERmR0
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# System bootloader configuration
bootloader --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel
%packages
@^minimal
@core
%end
%addon com_redhat_kdump --disable --reserve-mb='auto'
%end
配置文件授权
# chmod +r /var/ftp/ks.cfg
测试服务
以虚拟机为例,创建新机器进行自动化安装测试。
附录
参考链接
本文由 柒 创作,采用 知识共享署名4.0
国际许可协议进行许可。
转载本站文章前请注明出处,文章作者保留所有权限。
最后编辑时间: 2018-08-17 11:56 AM