1. PXE服務(wù)搭建
- pxe服務(wù)器
- 硬件基本信息
- CPU大于4核
- 內(nèi)存大于4G
- 硬盤大于50G
- 系統(tǒng)基本信息
- 系統(tǒng)版本:centos7.4
- selinux:關(guān)閉
- Firewalld:關(guān)閉
- yum源:阿里云的yum源
- 硬件基本信息
- client服務(wù)器
- 硬件基本信息
- CPU大于4核
- 內(nèi)存大于4G
- 硬盤大于50G
- 支持網(wǎng)絡(luò)啟動(dòng)
- 硬件基本信息
1.1. 搭建dhcp服務(wù)
- 基本配置:
- DHCP服務(wù)器地址:192.168.17.128/24
- 服務(wù)器裝機(jī)網(wǎng)段:192.168.17.0/24 網(wǎng)關(guān): 192.168.17.254
- 交換機(jī)裝機(jī)網(wǎng)段:192.168.100.0/24 網(wǎng)關(guān): 192.168.100.254
- 服務(wù)器帶外管理網(wǎng)段:192.168.255.0/24 網(wǎng)關(guān): 192.168.255.254
- 默認(rèn)filename:gpxelinux.0(獲取方式)
- 默認(rèn)next-server:192.168.17.128/24
- 其它不太重要的配置(可選擇性關(guān)注):
- DNS服務(wù)器地址:192.168.17.2
- NTP服務(wù)器地址:ntp.aliyun.com
- domain-search:test.com
1.1.1. 安裝dhcp服務(wù)
[root@pxe01 ~]# yum install dhcp
文件路徑:/etc/dhcp/dhcpd.conf
include "/etc/dhcp/ipxe.conf";
include "/etc/dhcp/ipmi_host";
# 用來(lái)設(shè)置DHCP服務(wù)器與DNS服務(wù)器的動(dòng)態(tài)信息更新模式:
# interim為DNS互動(dòng)更新模式
# ad-hoc為特>殊DNS更新模式
# none為不支持動(dòng)態(tài)更新模式
ddns-update-style none;
# 現(xiàn)在這個(gè)選項(xiàng)是可以忽略的李破,因?yàn)?DDNS 在前面已在配置文件中已經(jīng)被禁用阿浓。
# 但是當(dāng) DDNS 運(yùn)行時(shí)房午,這個(gè)選項(xiàng)會(huì)忽略主機(jī)更新其 DNS 主機(jī)名的請(qǐng)求。
ignore client-updates;
# 是否動(dòng)態(tài)分配IP給未知的使用者
allow unknown-clients;
# 當(dāng)dhcp服務(wù)器準(zhǔn)備動(dòng)態(tài)分配ip地址給一個(gè)客戶端時(shí)竞膳,它先發(fā)送一個(gè)icmp echo 請(qǐng)求 (ping)給這個(gè)要分配的地址,然后等1秒鐘诫硕,
# 如果沒(méi)有icmp echo信息返回坦辟,它就分配這個(gè)地址。
# 如果有返回信息章办,就把這個(gè)地址放棄锉走,服務(wù)器不會(huì)給客戶端回應(yīng)。
# 這個(gè)ping檢查導(dǎo)致在回應(yīng)dhcpdiscover信息時(shí)默認(rèn)有1秒鐘的延遲纲菌,這對(duì)某些客戶端可能是問(wèn)題挠日。
# 可以在這里配置是否檢查。如果這個(gè)值設(shè)置為false翰舌,就不進(jìn)行ping檢查嚣潜。
ping-check true;
# 因?yàn)閜ing-check 設(shè)置為true,ping-timeout允許配置dhcp服務(wù)器應(yīng)該等多長(zhǎng)時(shí)間椅贱。如果沒(méi)有設(shè)置值懂算,默認(rèn)是1秒只冻。
ping-timeout 1;
#客戶端是否通過(guò)ICMP發(fā)現(xiàn)網(wǎng)絡(luò)掩碼,路由
option perform-mask-discovery true;
option router-discovery true;
# 設(shè)置服務(wù)器時(shí)間(與格林威治時(shí)間相差8個(gè)小時(shí),计技,臺(tái)灣本地時(shí)間(local time)會(huì)比GMT時(shí)間快8小時(shí)(GMT + 8))
option time-offset 28800;
option ntp-servers ntp.aliyun.com;
option domain-search "test.com";
option domain-name-servers 192.168.17.2;
# 安裝系統(tǒng)的PXE環(huán)境下的IP網(wǎng)段
group host_pool {
allow bootp;
allow booting;
default-lease-time 1800;
max-lease-time 2400;
next-server 192.168.17.128;
filename "gpxelinux.0";
if exists user-class and option user-class = "iPXE" {
filename "http://192.168.17.128/pxe_boot/boot.ipxe";
}
else if option client-arch != 00:00 {
filename "ipxe.efi";
}
else {
filename "gpxelinux.0";
}
subnet 192.168.17.0 netmask 255.255.255.0 {option routers 192.168.17.254; range 192.168.17.100 192.168.17.200;}
}
# 帶外IP的分配喜德,一般用于mac綁定,這里只寫網(wǎng)段
group ipmi_pool {
default-lease-time 3600;
max-lease-time 7200;
subnet 192.168.255.0 netmask 255.255.255.0 { option routers 192.168.255.254; }
}
# 交換機(jī)的pxe引導(dǎo)配置
group sw_pool {
allow bootp;
allow booting;
default-lease-time 1800;
max-lease-time 3600;
if substring (option host-name, 0, 6) = "Ruijie" {
option tftp-server-name "192.168.17.128";
option bootfile-name "ruijie.py";
}
else if substring (option vendor-class-identifier, 0, 6) = "HUAWEI" {
option tftp-server-name "192.168.17.128";
option bootfile-name "huawei.py";
}
else if substring (option vendor-class-identifier, 0, 3) = "H3C" {
option tftp-server-name "192.168.17.128";
option bootfile-name "h3c.py";
}
subnet 192.168.100.0 netmask 255.255.255.0 { option routers 192.168.100.254 ; range 192.168.100.100 192.168.100.200;}
}
文件路徑:/etc/dhcp/ipxe.conf
option space ipxe;
option ipxe-encap-opts code 175 = encapsulate ipxe;
option ipxe.priority code 1 = signed integer 8;
option ipxe.keep-san code 8 = unsigned integer 8;
option ipxe.skip-san-boot code 9 = unsigned integer 8;
option ipxe.syslogs code 85 = string;
option ipxe.cert code 91 = string;
option ipxe.privkey code 92 = string;
option ipxe.crosscert code 93 = string;
option ipxe.no-pxedhcp code 176 = unsigned integer 8;
option ipxe.bus-id code 177 = string;
option ipxe.san-filename code 188 = string;
option ipxe.bios-drive code 189 = unsigned integer 8;
option ipxe.username code 190 = string;
option ipxe.password code 191 = string;
option ipxe.reverse-username code 192 = string;
option ipxe.reverse-password code 193 = string;
option ipxe.version code 235 = string;
option iscsi-initiator-iqn code 203 = string;
# Feature indicators
option ipxe.pxeext code 16 = unsigned integer 8;
option ipxe.iscsi code 17 = unsigned integer 8;
option ipxe.aoe code 18 = unsigned integer 8;
option ipxe.http code 19 = unsigned integer 8;
option ipxe.https code 20 = unsigned integer 8;
option ipxe.tftp code 21 = unsigned integer 8;
option ipxe.ftp code 22 = unsigned integer 8;
option ipxe.dns code 23 = unsigned integer 8;
option ipxe.bzimage code 24 = unsigned integer 8;
option ipxe.multiboot code 25 = unsigned integer 8;
option ipxe.slam code 26 = unsigned integer 8;
option ipxe.srp code 27 = unsigned integer 8;
option ipxe.nbi code 32 = unsigned integer 8;
option ipxe.pxe code 33 = unsigned integer 8;
option ipxe.elf code 34 = unsigned integer 8;
option ipxe.comboot code 35 = unsigned integer 8;
option ipxe.efi code 36 = unsigned integer 8;
option ipxe.fcoe code 37 = unsigned integer 8;
option ipxe.vlan code 38 = unsigned integer 8;
option ipxe.menu code 39 = unsigned integer 8;
option ipxe.sdi code 40 = unsigned integer 8;
option ipxe.nfs code 41 = unsigned integer 8;
option client-arch code 93 = unsigned integer 16;
文件路徑:/etc/dhcp/ipmi_host
host BMC_XXXXX { hardware ethernet 00:00:00:00:27:85; fixed-address 192.168.255.11 ;}
host BMC_XXXX1 { hardware ethernet 00:00:00:00:EF:05; fixed-address 192.168.255.12 ;}
1.1.2. 設(shè)置開(kāi)機(jī)自啟
[root@pxe01 ~]# systemctl start dhcpd
[root@pxe01 ~]# systemctl enable dhcpd
1.2. 搭建tftp-server服務(wù)
1.2.1. 安裝tftp-server
[root@pxe01 ~]# yum install tftp tftp-server xinetd
文件路徑:/etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
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
}
1.2.2. 啟動(dòng)tftp服務(wù)
[root@pxe01 ~]# systemctl start xinetd
[root@pxe01 ~]# systemctl enable xinetd
1.2.3. 測(cè)試tftp是否正常
[root@pxe01 ~]# netstat -tuanpl |grep 69
udp 0 0 0.0.0.0:69 0.0.0.0:* 1423/xinetd
[root@pxe01 ~]# echo "test tftp-server" >/var/lib/tftpboot/test.txt
[root@pxe01 ~]# ls
anaconda-ks.cfg
[root@pxe01 ~]# tftp 192.168.17.128
tftp> get test.txt
tftp> quit
[root@pxe01 ~]# ls
anaconda-ks.cfg test.txt
[root@pxe01 ~]# cat test.txt
test tftp-server
1.3. 配置裝機(jī)菜單界面
這里我們使用centos6的裝機(jī)界面為模板垮媒,原因是看著舒服舍悯。
1.3.1. <span id="get_gpxelinux">獲取gpxelinux.0</span>
安裝syslinux,即可獲取gpxelinux.0
[root@pxe01 ~]# yum install syslinux
[root@pxe01 ~]# cp /usr/share/syslinux/gpxelinux.0 /var/lib/tftpboot/
1.3.2. 添加其它啟動(dòng)文件
[root@pxe01 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@pxe01 ~]# wget -O /var/lib/tftpboot/pxelinux.cfg/default https://mirrors.aliyun.com/centos/6/os/x86_64/isolinux/isolinux.cfg
[root@pxe01 ~]# wget -O /var/lib/tftpboot/splash.jpg https://mirrors.aliyun.com/centos/6/os/x86_64/isolinux/splash.jpg
[root@pxe01 ~]# cp /usr/share/syslinux/vesamenu.c32 /var/lib/tftpboot/
[root@pxe01 ~]# ls /var/lib/tftpboot/
gpxelinux.0 pxelinux.cfg splash.jpg test.txt vesamenu.c32
1.3.3. 配置default文件
文件路徑:/var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
#prompt 1
timeout 600
#display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 8.X!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
label local
menu label Boot from local drive
localboot 0xffff
label linux
menu label CentOS 8.X
menu default
kernel http://192.168.17.128/centos8-pxe/vmlinuz
append initrd=http://192.168.17.128/centos8-pxe/initrd.img net.ifnames=0 biosdevname=0 rd.driver.pre=mlx5_core,i40e,ixgbe ksdevice=bootif inst.gpt
ipappend 2
1.3.3. 啟動(dòng)驗(yàn)證
系統(tǒng)安裝選擇界面
1.4. 安裝源配置
1.4.1. 安裝httpd服務(wù)
[root@pxe01 ~]# yum install httpd
[root@pxe01 ~]# vim /etc/httpd/conf.d/welcome.conf
<LocationMatch "^/+$">
Options +Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
[root@pxe01 ~]# vim /etc/httpd/conf.d/autoindex.conf
IndexOptions FancyIndexing HTMLTable VersionSort NameWidth=*
[root@pxe01 ~]# systemctl enable httpd.service
[root@pxe01 ~]# systemctl restart httpd.service
1.4.2. PXE環(huán)境設(shè)置
1.4.2.1. 掛載CentOS8.1的ISO鏡像
[root@pxe01 ~]# mkdir -p /var/www/html/iso/centos8u1
[root@pxe01 ~]# vim /etc/fstab
/dev/cdrom /var/www/html/iso/centos8u1/ iso9660 defaults,loop 0 0
[root@pxe01 ~]# mount -a
[root@pxe01 ~]# ls /var/www/html/iso/centos8u1/
AppStream BaseOS EFI images isolinux media.repo TRANS.TBL
1.4.2.2. 配置PXE環(huán)境
[root@pxe01 ~]# mkdir -p /var/www/html/centos8-pxe/{ks,scripts}
[root@pxe01 ~]# cp /var/www/html/iso/centos8u1/isolinux/{initrd.img,vmlinuz} /var/www/html/centos8-pxe/
[root@pxe01 ~]# ls /var/www/html/centos8-pxe/
initrd.img ks scripts vmlinuz
http服務(wù)啟動(dòng)正常
因?yàn)檫@次是手動(dòng)安裝睡雇,需要加入?yún)?shù)inst.stage2=http://192.168.17.128/iso/centos8u1
萌衬。
[root@pxe01 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
label linux
menu label CentOS 8.X
menu default
kernel http://192.168.17.128/centos8-pxe/vmlinuz
append initrd=http://192.168.17.128/centos8-pxe/initrd.img net.ifnames=0 biosdevname=0 rd.driver.pre=mlx5_core,i40e,ixgbe ksdevice=bootif inst.gpt inst.stage2=http://192.168.17.128/iso/centos8u1
ipappend 2
1.4.3. 裝機(jī)測(cè)試
裝機(jī)界面
1.4.4. 加載過(guò)程
根據(jù)httpd服務(wù)的訪問(wèn)日志,可以知道pxe啟動(dòng)的過(guò)程
[root@pxe01 ~]# tail /var/log/httpd/access_log
192.168.17.101 - - [02/May/2020:00:32:20 +0800] "GET /centos8-pxe/vmlinuz HTTP/1.0" 200 8106744 "-" "gPXE/1.0.0"
192.168.17.101 - - [02/May/2020:00:32:20 +0800] "GET /centos8-pxe/initrd.img HTTP/1.0" 200 62113500 "-" "gPXE/1.0.0"
192.168.17.129 - - [02/May/2020:00:32:36 +0800] "GET /iso/centos8u1/.treeinfo HTTP/1.1" 200 1520 "-" "curl/7.61.1"
192.168.17.129 - - [02/May/2020:00:32:36 +0800] "GET /iso/centos8u1/images/install.img HTTP/1.1" 200 533405696 "-" "curl/7.61.1"
192.168.17.129 - - [02/May/2020:00:32:44 +0800] "GET /iso/centos8u1/images/updates.img HTTP/1.1" 404 230 "-" "curl/7.61.1"
192.168.17.129 - - [02/May/2020:00:32:44 +0800] "GET /iso/centos8u1/images/product.img HTTP/1.1" 404 230 "-" "curl/7.61.1"
1.5. 解決的問(wèn)題
- 安裝centos8系統(tǒng)需要的安裝源問(wèn)題
也就是不需要刻錄過(guò)個(gè)光盤了