CentOS8的PXE安装-1-PXE服务搭建

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
http服务启动正常

因为这次是手动安装,需要加入参数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. 解决的问题

  1. 安装centos8系统需要的安装源问题
    也就是不需要刻录过个光盘了
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269