PXE 說明
PXE(Preboot eXecution Environment) 支持客戶端通過網路從服務器端下載系統鏡像,并進行安裝,在安裝程序中,可以通過 Kickstart 組態檔實作無人值守安裝,并定制作業系統,
PXE 服務器組件:
DHCP : 負責分配網路 IP 地址,并通過 DHCP 包來指定系統啟動檔案的,
syslinux: 預啟動程式
TFTP: PXE 客戶端通過 TFTP 獲取啟動檔案,
FTP: PXE 客戶端通過 FTP 下載系統鏡像內容,
初始化服務器
為 PXE Server 配置固定 IP 地址;
[it@pxesvr ~]$ sudo vim /etc/sysconfig/network-scripts/ifcfg-ens192
[sudo] password for it:
[it@pxesvr ~]$ cat /etc/sysconfig/network-scripts/ifcfg-ens192
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens192
UUID=6346f97a-42c5-4fff-ad62-93bdfd90f417
DEVICE=ens192
ONBOOT=yes
IPADDR=10.10.10.53
PREFIX=24
GATEWAY=10.10.10.1
DNS1=10.10.10.1
IPV6_PRIVACY=no
關閉防火墻;
[it@pxesvr ~]$ sudo systemctl stop firewalld.service
[it@pxesvr ~]$ sudo systemctl disable firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
DHCP
安裝 DHCP 服務器角色;
[it@pxesvr ~]$ sudo yum install dhcp-server -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:12:17 ago on Sat 10 Oct 2020 04:06:12 PM CST.
Dependencies resolved.
================================================================================================================
Package Arch Version Repository Size
================================================================================================================
Installing:
dhcp-server x86_64 12:4.3.6-30.el8 localREPO 529 k
Transaction Summary
================================================================================================================
Install 1 Package
... ... ... ...
... ... ... ...
... ... ... ...
配置 DHCP;
[it@pxesvr ~]$ sudo vim /etc/dhcp/dhcpd.conf
[it@pxesvr ~]$ sudo cat /etc/dhcp/dhcpd.conf | grep -v ^#
allow bootp;
allow booting;
default-lease-time 600;
max-lease-time 7200;
option space pxelinux;
option pxelinux.magic code 208 = string;
option pxelinux.configfile code 209 = text;
option pxelinux.pathprefix code 210 = text;
option pxelinux.reboottime code 211 = unsigned integer 32;
option architecture-type code 93 = unsigned integer 16;
subnet 10.10.10.0 netmask 255.255.255.0 {
option routers 10.10.10.1;
range 10.10.10.100 10.10.10.199;
class "pxeclients" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
next-server 10.10.10.53; #pxe server IP
if option architecture-type = 00:07 {
filename "uefi/BOOTX64.EFI"; # UEFI boot
} else {
filename "pxelinux.0"; # BIOS boot
}
}
}
啟動 DHCP 服務,并配置開機啟動;
[it@pxesvr ~]$ sudo systemctl enable --now dhcpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/dhcpd.service → /usr/lib/systemd/system/dhcpd.service.
syslinux
安裝 syslinux-tftpboot;
[it@pxesvr ~]$ sudo yum install syslinux-tftpboot -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:46:30 ago on Mon 12 Oct 2020 11:18:21 AM CST.
Dependencies resolved.
================================================================================================================
Package Arch Version Repository Size
================================================================================================================
Installing:
syslinux-tftpboot noarch 6.04-1.el8 localREPO 462 k
Installing dependencies:
syslinux x86_64 6.04-1.el8 localREPO 576 k
syslinux-nonlinux noarch 6.04-1.el8 localREPO 554 k
Transaction Summary
================================================================================================================
Install 3 Packages
... ... ... ...
... ... ... ...
... ... ... ...
配置啟動選單(只有兩個選單,一個 Install Red Hat Enterprise Linux 8.0,一個是 Boot from local drive(默認選擇)),并在第一個選單配置啟動系統鏡像所需的檔案,以及下載系統鏡像的目錄;
[it@pxesvr ~]$ sudo mkdir /tftpboot/pxelinux.cfg
[it@pxesvr ~]$ sudo cp /os/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
[it@pxesvr ~]$ sudo vim /tftpboot/pxelinux.cfg/default
[it@pxesvr ~]$ sudo cat /tftpboot/pxelinux.cfg/default
default vesamenu.c32
timeout 600
display boot.msg
menu title Red Hat Enterprise Linux 8.0
# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
menu tabmsg Press Tab for full configuration options on menu items.
menu separator # insert an empty line
menu separator # insert an empty line
label linux
menu label ^Install Red Hat Enterprise Linux 8.0
kernel vmlinuz
append initrd=initrd.img inst.stage2=ftp://10.10.10.53/rhel8.2 repo=ftp://10.10.10.53/rhel8.2 ip=dhcp quiet
label local
menu label ^Boot from local drive
menu default
localboot 0xffff
啟動選單檔案 default 你可以通過示例檔案修改獲得,也可以自己新建獲得,
復制系統鏡像啟動檔案到對應的位置
[it@pxesvr ~]$ sudo cp /os/isolinux/{boot.msg,vesamenu.c32} /tftpboot/
[it@pxesvr ~]$ sudo cp /os/images/pxeboot/{vmlinuz,initrd.img} /tftpboot/
TFTP
安裝 TFTP 服務器角色(pxe 客戶端通過 TFTP 獲取啟動檔案);
[it@pxesvr ~]$ sudo yum install tftp-server -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:45:23 ago on Mon 12 Oct 2020 08:05:39 AM CST.
Dependencies resolved.
================================================================================================================
Package Arch Version Repository Size
================================================================================================================
Installing:
tftp-server x86_64 5.2-24.el8 localREPO_APP 50 k
Transaction Summary
================================================================================================================
Install 1 Package
... ... ... ...
... ... ... ...
... ... ... ...
配置 TFTP 服務器(修改 TFTP 的路徑為 /tftpboot);
[it@pxesvr ~]$ sudo vim /usr/lib/systemd/system/tftp.service
[it@pxesvr ~]$ sudo cat /usr/lib/systemd/system/tftp.service
[Unit]
Description=Tftp Server
Requires=tftp.socket
Documentation=man:in.tftpd
[Service]
ExecStart=/usr/sbin/in.tftpd -s /tftpboot
StandardInput=socket
[Install]
Also=tftp.socket
啟動 TFTP 服務,并配置開機啟動;
[it@pxesvr ~]$ sudo systemctl enable --now tftp
Created symlink /etc/systemd/system/sockets.target.wants/tftp.socket → /usr/lib/systemd/system/tftp.socket.
FTP
安裝 FTP 服務器(用于 pxe client 下載系統鏡像檔案);
[it@pxesvr ~]$ sudo yum install vsftpd -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:01:41 ago on Sat 10 Oct 2020 04:06:12 PM CST.
Dependencies resolved.
================================================================================================================
Package Arch Version Repository Size
================================================================================================================
Installing:
vsftpd x86_64 3.0.3-28.el8 localREPO_APP 180 k
Transaction Summary
================================================================================================================
Install 1 Package
... ... ... ...
... ... ... ...
配置 ftp 服務器,開啟匿名訪問,指定匿名訪問的目錄;
[it@pxesvr ~]$ sudo vim /etc/vsftpd/vsftpd.conf
[sudo] password for it:
[it@pxesvr ~]$ sudo grep -e anonymous -e anon_root /etc/vsftpd/vsftpd.conf | grep -v ^#
anonymous_enable=YES
anon_root=/home/ISO/
啟動 ftp 服務,并配置開機啟動;
[it@pxesvr ~]$ sudo systemctl enable --now vsftpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/vsftpd.service → /usr/lib/systemd/system/vsftpd.service.
創建 ftp 匿名訪問的目錄目錄,然后復制系統鏡像內容到該目錄;
[it@pxesvr ~]$ sudo mkdir /home/ISO/rhel8.2
mount RHEL-8-0-0-BaseOS-x86_64.iso /mnt/rhel8.2
[it@pxesvr ~]$ sudo cp -r /mnt/rhel8.2/* /home/ISO/rhel8.2
**note:**如果復制的安裝源有問題,你可以嘗試通過手動復制和粘貼,
測驗啟動
通過 BIOS(Legacy ) 的方式啟動客戶端主機進行測驗

配置支持 UEFI 啟動
配置 UEFI 啟動選單
[it@pxesvr ~]$ sudo mkdir /tftpboot/uefi
[sudo] password for it:
[it@pxesvr ~]$ sudo cp -r /os/EFI/BOOT/* /tftpboot/uefi/
[it@pxesvr ~]$ vim /tftpboot/uefi/grub.cfg
[it@pxesvr ~]$ sudo vim /tftpboot/uefi/grub.cfg
[it@pxesvr ~]$ sudo cat /tftpboot/uefi/grub.cfg
[sudo] password for it:
set default="1"
function load_video {
insmod efi_gop
insmod efi_uga
insmod video_bochs
insmod video_cirrus
insmod all_video
}
load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2
set timeout=60
### END /etc/grub.d/00_header ###
search --no-floppy --set=root -l 'RHEL-8-0-0-BaseOS-x86_64'
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install Red Hat Enterprise Linux 8.0' --class fedora --class gnu-linux --class gnu --class os {
linuxefi vmlinuz inst.stage2=ftp://10.10.10.53/rhel8.2 repo=ftp://10.10.10.53/rhel8.2 ip=dhcp quiet
initrdefi initrd.img
}
menuentry 'Test this media & install Red Hat Enterprise Linux 8.0' --class fedora --class gnu-linux --class gnu --class os {
linuxefi vmlinuz inst.stage2=ftp://10.10.10.53/dvd quiet
initrdefi initrd.img
}
設定引導檔案權限
設定路徑/var/lib/tftpboot/uefi 中的5個檔案權限為777
cd /tftpboot/uefi
chmod 777 *
重啟服務
[it@pxesvr ~]$ sudo systemctl restart dhcpd.service
[it@pxesvr ~]$ sudo systemctl restart tftp.socket
測驗啟動
通過 UEFI 的方式啟動客戶端主機進行測驗,

通過 PXE 自動安裝作業系統(2):kickstart 應答檔案
Kickstart 檔案是實作系統自動安裝的應答檔案,
示例檔案
#version=RHEL8
ignoredisk --only-use=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=sda
# Use graphical install
graphical
# Reboot after installation
reboot
repo --name="AppStream" --baseurl=ftp://10.10.10.53/rhel8.2/AppStream
# Use network installation
url --url="ftp://10.10.10.53/rhel8.2"
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# Run the Setup Agent on first boot
firstboot --disable
# System language
lang en_US.UTF-8
# Network information
network --bootproto=dhcp --device=ens192 --ipv6=auto --activate
network --hostname=localhost.localdomain
# Root password
rootpw --iscrypted $6$VrOUsKRz8dywq5D5$1SbE62Vu/YPtzqd.4Y0U/M6fqILDluHAPFU5Kt9GkAS8eZVC7.yA/aBCzkWbNx0MJicFBR2MmipOItFBdqW6X.
# X Window System configuration information
xconfig --startxonboot
# System services
services --enabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc
user --groups=wheel --name=it --password=$6$fI8GAHa5Q6JG1BB3$6/Dv5ndCa4KMIkVFBkmVzvnV.SvwSO5.h0ppaaI75f53G9dH4.l6yUR.IUYGTKX/ctKwyzliKJQtOpV7TAZqI. --iscrypted --gecos="it"
%packages
@^graphical-server-environment
kexec-tools
%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
Kickstart檔案說明
ignoredisk: 在安裝程序中控制對磁盤的連接,如果你使用的是自動磁區,那么在安裝程序中可以通過 ignoredisk --driver=sdc 指定自動磁區忽略的磁盤,如果你有多個磁盤,并且只想使用其中一個進行自動磁區,并安裝作業系統,你可以使用 ignoredisk --only-use=sda 指定只使用 sda 這一個磁盤,
autopart: 自動創建根磁區( / ),交換磁區(swap)和適當的啟動磁區(/boot),在足夠大的驅動器上,還會創建 /home 磁區,通過 --type= 指定磁區型別,如示例中使用的 lvm,你還可以通過 --fstype= 指定系統檔案型別,如 xfs,ext4 等等,默認是 xfs,你還可以通過 --encrypted 選項,對所有磁區進行加密,
clearpart: 在磁區前,洗掉現有磁區,可以通過 --drives= 指定要洗掉磁區的磁盤,也可以通過 --all 清除所有設備的磁區,
graphical: 安裝程序以圖形化的方式進行,就和手動安裝一樣,也可以使用 text 命令,以文本的方式顯示安裝程序,
reboot: 安裝完成后重啟,
repo: 指定額外的軟體包安裝源,
url: 通過網路安裝時,安裝檔案的位置,
keyboard: 指定鍵盤布局,通過 --vckeymap= 指定應使用哪個 VConsole 鍵盤模式,通過 --xlayouts= 指定鍵盤的布局,
firstboot: 第一次啟動系統時,是否顯示 Initial Setup,如果啟用,則必須安裝 initial-setup 軟體包,如果未指定,則默認禁用這個選項,–enable 表示啟動 Initial Setup,–disable 表示禁用 Initial Setup,如果你使用 --enable ,你還可以使用 --reconfig 選項在引導系統時啟動重配置(reconfiguration)模式,在這個模式下,你可以從新配置系統語言,鍵盤滑鼠,root 密碼,系統安全級別,時區以及一些網路配置,
lang: 配置系統語言,
network: 網路配置,使用 --bootproto= 指定計算機獲取 IP 的方式,是 dchp 還是 static,使用 --device= 指定要配置的設備名稱,使用 --activate 激活該設備,如果你的 --bootproto= 使用的是 static,那么你可以使用 ip= 指定 IP 地址,–netmask= 指定子網掩碼,–gateway= 指定網關,–nameserver= 指定 DNS,使用 ipv6= 指定 IPv6 配置,使用 auto 表示自動配置,使用 --hostname 配置主機名,
rootpw: 指定 root 用戶的密碼,–iscrypted 表示密碼以密文的方式顯示,–plaintext 表示以明文的方式顯示密碼,你還可以使用 --lock 鎖定 root 用戶,
當你使用 –iscrypted 時,可以在一臺已經安裝好系統的機器上,通過 python 生成密碼的密文(如果是 Python 3,則對應的命令應該是 python3.),
$ python -c 'import crypt; print(crypt.crypt("My Password"))'
1
xconfig: 配置 X Windows 系統,–startxonboot 表示在安裝的系統中使用圖形界面登錄,
services: 配置服務的默認狀態,–disabled= 指定默認禁用的服務,使用 --enabled= 指定默認啟用的服務,
timezone: 指定時區,
user: 添加額外的用戶,通過 --name= 指定用戶名,通過 --groups= 指定用戶要添加的組(除默認組),通過 --password= 指定該用戶的密碼,–iscrypted 表示以密文的方式,通過–gecos= 定義用戶的 GECOS資訊,如,用戶的全名等等,
%packages 表示要安裝的軟體包,
通過 @ 指定軟體包組,如:
%packages
@core
@X Window System
@Desktop
%end
通過 @^ 指定環境組,如:
%packages
@^graphical-server-environment
%end
直接輸入軟體包名,指定獨立的軟體包,如:
%packages
@core
@desktop
sqlite
curl
%end
通過 - 號排錯軟體包組中的某個軟體包
%packages
@Development Tools
-pkgconf
-pkgconf-m4
-pkgconf-pkg-config
-redhat-rpm-config
%end
%package 要以 %end 結尾
%addon 配置 kdump,–enable 表示開啟,并通過 --reserve-mb= 指定為 kdump 預留的記憶體大小,auto 表示自動,要以 %end結束,
%anaconda 部分指定了 password 策略,同樣以 %end 結束,
你還可以通過 %pre 指定在磁盤磁區前要執行的腳本,通過 %post 指定系統安裝完成后要執行的腳本,這些模塊都需要 %end 結束,
更多關于 kickstart 應答檔案的語法可以參考官方網站的系統安裝指南,到目前為止,紅帽官網還沒有關于 RHEL 8 的安裝指南,你可以參考 RHEL 7 的安裝指南進行撰寫,
在啟動選單檔案中添加 kickstart 應答路徑
編輯好 kickstart 應答檔案后,將其保存成 ks.cfg (檔案名可以自定義),上傳到 ftp 根目錄中(路徑也是自定義的),如該示例的檔案路徑是:ftp://10.10.10.53/ks.cfg
BISO(Legacy)方式啟動:
[it@pxesvr ~]$ sudo vim /tftpboot/pxelinux.cfg/default
[it@pxesvr ~]$ sudo cat /tftpboot/pxelinux.cfg/default
... ... ... ...
... ... ... ...
label linux
menu label ^Install Red Hat Enterprise Linux 8.0
kernel vmlinuz
append initrd=initrd.img inst.stage2=ftp://10.10.10.53/rhel8.2 inst.ks=ftp://10.10.10.53/ks.cfg quiet
... ... ... ...
... ... ... ...
UEFI 方式啟動:
[it@pxesvr ~]$ sudo vim /tftpboot/uefi/grub.cfg
[it@pxesvr ~]$ sudo cat /tftpboot/uefi/grub.cfg
[sudo] password for it:
... ... ... ...
... ... ... ...
### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install Red Hat Enterprise Linux 8.0' --class fedora --class gnu-linux --class gnu --class os {
linuxefi vmlinuz inst.stage2=ftp://10.10.10.53/rhel8.2 inst.ks=ftp://10.10.10.53/ks.cfg quiet
initrdefi initrd.img
}
... ... ... ...
... ... ... ...
至此,你就可以通過 PXE Server 進行自動安裝 RHEL 8 作業系統了,
參考鏈接 :
通過 PXE 自動安裝作業系統(1):部署 PXE Server :
https://mp.weixin.qq.com/s/E90teVh2XIf3c244m5b3Qg
通過 PXE 自動安裝作業系統(2):部署 PXE Server :
https://mp.weixin.qq.com/s/PgVHBIqoRG9q57RlNrFpAw
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/245914.html
標籤:Linux
上一篇:每次打開Excel就自動打開VBA小視窗,顯示型別不匹配,請問該怎么辦呀~救救孩子
下一篇:Linux常用命令--開機與用戶
