1. PXE服务搭建
- pxe服务器
- 硬件基本信息
- CPU大于4核
- 内存大于4G
- 硬盘大于50G
- 系统基本信息
- 系统版本:centos7.4
- selinux:关闭
- Firewalld:关闭
- yum源:阿里云的yum源
- 硬件基本信息
- client服务器
- 硬件基本信息
- CPU大于4核
- 内存大于4G
- 硬盘大于50G
- 支持网络启动
- 硬件基本信息
1.1. 搭建dhcp服务
- 基本配置:
- DHCP服务器地址:192.168.17.128/24
- 服务器装机网段:192.168.17.0/24 网关: 192.168.17.254
- 交换机装机网段:192.168.100.0/24 网关: 192.168.100.254
- 服务器带外管理网段:192.168.255.0/24 网关: 192.168.255.254
- 默认filename:gpxelinux.0(获取方式)
- 默认next-server:192.168.17.128/24
- 其它不太重要的配置(可选择性关注):
- DNS服务器地址:192.168.17.2
- NTP服务器地址:ntp.aliyun.com
- domain-search:test.com
1.1.1. 安装dhcp服务
[root@pxe01 ~]# yum install dhcp
文件路径:/etc/dhcp/dhcpd.conf
include "/etc/dhcp/ipxe.conf";
include "/etc/dhcp/ipmi_host";
# 用来设置DHCP服务器与DNS服务器的动态信息更新模式:
# interim为DNS互动更新模式
# ad-hoc为特>殊DNS更新模式
# none为不支持动态更新模式
ddns-update-style none;
# 现在这个选项是可以忽略的,因为 DDNS 在前面已在配置文件中已经被禁用。
# 但是当 DDNS 运行时,这个选项会忽略主机更新其 DNS 主机名的请求。
ignore client-updates;
# 是否动态分配IP给未知的使用者
allow unknown-clients;
# 当dhcp服务器准备动态分配ip地址给一个客户端时,它先发送一个icmp echo 请求 (ping)给这个要分配的地址,然后等1秒钟,
# 如果没有icmp echo信息返回,它就分配这个地址。
# 如果有返回信息,就把这个地址放弃,服务器不会给客户端回应。
# 这个ping检查导致在回应dhcpdiscover信息时默认有1秒钟的延迟,这对某些客户端可能是问题。
# 可以在这里配置是否检查。如果这个值设置为false,就不进行ping检查。
ping-check true;
# 因为ping-check 设置为true,ping-timeout允许配置dhcp服务器应该等多长时间。如果没有设置值,默认是1秒。
ping-timeout 1;
#客户端是否通过ICMP发现网络掩码,路由
option perform-mask-discovery true;
option router-discovery true;
# 设置服务器时间(与格林威治时间相差8个小时,,台湾本地时间(local time)会比GMT时间快8小时(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;
# 安装系统的PXE环境下的IP网段
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绑定,这里只写网段
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; }
}
# 交换机的pxe引导配置
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. 设置开机自启
[root@pxe01 ~]# systemctl start dhcpd
[root@pxe01 ~]# systemctl enable dhcpd
1.2. 搭建tftp-server服务
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. 启动tftp服务
[root@pxe01 ~]# systemctl start xinetd
[root@pxe01 ~]# systemctl enable xinetd
1.2.3. 测试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. 配置装机菜单界面
这里我们使用centos6的装机界面为模板,原因是看着舒服。
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. 添加其它启动文件
[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. 启动验证
1.4. 安装源配置
1.4.1. 安装httpd服务
[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环境设置
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环境
[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
因为这次是手动安装,需要加入参数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. 装机测试
1.4.4. 加载过程
根据httpd服务的访问日志,可以知道pxe启动的过程
[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. 解决的问题
- 安装centos8系统需要的安装源问题
也就是不需要刻录过个光盘了