Linux& Windows 系统部署环境搭建--PXE专题(一)

------网络启动环境配置


前言

       在数据中心服务器操作系统部署过程中,亲眼目睹操作系统工程师手持数十个光驱,在数据机房手忙脚乱的安装操作系统,于是在长假闲暇之余,将本人长期工作场景中的方法梳理归纳一下,在搭建VMware虚拟环境,对安装步骤和安装命令和脚本进行验证,确保能实现自动化部署操作系统,解决难题,与有识之士共同探讨与分享,抛砖引玉,目的是通过把简单工作专业化,降低现场实施的技术门槛实现专业化部署的目的。方便基础工程师能够专业、高效、优雅地完成操作系统部署。

       本文内容分有几专题,适合有一定Linux应用基础的行业人士,通过专题学习,能够独自完成CPU架构有x86、ARM、飞腾、海光、兆芯、龙芯等架构的系统。在同一服务器中配置相关参数,解决异构CPU的问题

PXE部署优点:1、快捷部署,采用PXE系统部署方式,可以实现多台客户端设备同时部署安装,

                         2、自动化,安装过程从开始引导后,少许甚至无需人工干预,自动安装

                         3、标准化,安装过程在选项选取全部采用应答文件,而非每次的人工点击选取,实现安装配置文件标准统一;

                         4、版本控制,所有安装系统的拷贝来源于同一安装源,易于进行版本控制。

一、基础环境说明

PXE服务端:  CPU架构是 x86_64

                        CentOS 8.5 64Bit  for x86_64   (选择“带GUI的服务器)

                        IP地址:192.168.150.100/24,GW 192.168.150.254

                        yum软件仓库已经正确配置,能够获取到软件包

                        配置都是在root用户下进行

PXE客户端:  CPU架构是 x86_64

                        待部署系统CentOS 7.9 (2009) x86_64

                        网卡支持PXE启动协议

二、安装文件准备

       安装的目标系统是CentOS 7.9 (2009) x86_64,安装文件有光盘介质或者ISO镜像文件的方式,选择任一方式都可以,需预先准备好安装光盘或ISO镜像。

1.光盘方式

#新建系统安装源目录
mkdir -p /opt/LinuxInstaller/CentOS7.9
chmod -Rf 755 /opt/LinuxInstaller/CentOS7.9
#采用系统光盘方式
OSdisk=$(ls /run/media/root/)
/bin/cp -rf "/run/media/root/$OSdisk/." /opt/LinuxInstaller/CentOS7.9

2.ISO镜像方式

代码如下(示例):

#新建系统安装源目录
mkdir -p /opt/LinuxInstaller/CentOS7.9
chmod -Rf 755 /opt/LinuxInstaller/CentOS7.9
#/opt                 #先将ISO镜像文件已经存放在/opt目录下 
mkdir -p /mnt/CentOS7.9 #新建ISO文件挂载目录
ISO=$(ls /opt/*.iso)
mount -t iso9660 -o loop,ro "$ISO" /mnt/CentOS7.9
/bin/cp -rf "/mnt/CentOS7.9/." /opt/LinuxInstaller/CentOS7.9

 三、tftp服务配置

yum -y install tftp-server  #安装tftp-server软件包
yum -y install syslinux     #安装syslinux软件包
mkdir -p /var/lib/tftpboot/Legacy/pxelinux.cfg
mkdir -p /var/lib/tftpboot/Legacy/CentOS7.9
mkdir -p /var/lib/tftpboot/EFI/CentOS7.9

/bin/cp -fr /usr/share/syslinux/. /var/lib/tftpboot/Legacy/
/bin/cp -fr /opt/LinuxInstaller/CentOS7.9/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/EFI/CentOS7.9
/bin/cp -fr /opt/LinuxInstaller/CentOS7.9/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/Legacy/CentOS7.9
/bin/cp -rf /opt/LinuxInstaller/CentOS7.9/isolinux/isolinux.cfg /var/lib/tftpboot/Legacy/pxelinux.cfg/default
/bin/cp -rf /opt/LinuxInstaller/CentOS7.9/EFI/BOOT/. /var/lib/tftpboot/EFI/

firewall-cmd --add-service=tftp --permanent
firewall-cmd --reload
systemctl enable tftp.socket    #在引导过程中启用tftp服务
systemctl start tftp.socket     #启动tftp服务
#systemctl status tftp.socket    ##查验tftp.socket服务状态

四、DHCP服务配置

yum -y install dhcp-server	#安装dhcp服务

#多网络端口指定dhcp服务端口
#echo "DHCPDARGS=ens160">> /etc/sysconfig/dhcpd

mv -f /etc/dhcp/dhcpd.conf{,.bak}	#重命名原配置文件
mv -f /etc/dhcp/dhcpd6.conf{,.bak}

#指定DHCP服务所使用的IP address 或网络接口需要在下面定义,作为参数引入
#例如: local_ip=192.168.150.100 或
#DHCP_iface=ens***	#
local_ip=192.168.150.100     #定义接口IP
echo $local_ip      #IP需根据实际情况修改
cat>/etc/dhcp/dhcpd.conf<<EOF
default-lease-time 300;    #默认租约时间 ,单位为秒
max-lease-time 7200;       #最大租约时间,单位为秒
##authoritative;
ddns-update-style none; 
option space pxelinux;
option pxelinux.mtftp-ip    code 1 = ip-address;
option pxelinux.mtftp-cport code 2 = unsigned integer 16;
option pxelinux.mtftp-sport code 3 = unsigned integer 16;
option pxelinux.mtftp-tmout code 4 = unsigned integer 8;
option pxelinux.mtftp-delay code 5 = unsigned integer 8;
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;
#定义 DHCP 服务器名
server-name "PXEserver";
#定义DNS 服务器
option domain-name "pxe.org";
option domain-name-servers 114.114.114.114;
subnet 192.168.150.0 netmask 255.255.255.0 {
allow booting;
allow bootp;
#网关
option routers 192.168.150.254;
#广播地址
#option boardcase-address 192.168.150.255;
option netbios-name-servers $local_ip;
# 定义分配的网段和掩码
range 192.168.150.51 192.168.150.100; #地址范围
# 定义分配的地址范围
next-server $local_ip;
}
class "pxeclients" { # 指定引导文件名称
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
     if option architecture-type = 00:00 { filename "Legacy/pxelinux.0"; }
#    if option architecture-type = 00:00 { filename "Legacy/lpxelinux.0"; }	#支持HTTP 协议
else if option architecture-type = 00:07 { filename "EFI/BOOTX64.EFI";}	#x64 uefi
else if option architecture-type = 00:09 { filename "EFI/BOOTX64.EFI";}	#x64 uefi
}
EOF
firewall-cmd --add-service=dhcp --permanent
firewall-cmd --reload

systemctl enable dhcpd	 #在引导过程中启用dhcp 服务
systemctl start dhcpd	   #启动dhcp服务
#systemctl status dhcpd	 #查验DHCP 服务状态

五、网络安装源配置

创建基于网络的安装源,采用HTTP、FTP或者NFS服务传送系统安装文件

1、HTTP 配置

yum -y install httpd
mkdir -p /var/www/html/CentOS7.9
/bin/cp -rf "/opt/LinuxInstaller/CentOS7.9/." /var/www/html/CentOS7.9
##ln -sf /opt/LinuxInstaller/CentOS7.9 /var/www/html/
#配置文件校验 apachectl configtest

semanage fcontext -a -t httpd_sys_content_t "/opt/LinuxInstaller(/.*)?"
restorecon -Rv /opt/LinuxInstaller/
echo "PXE 系统安装环境" > /var/www/html/index.html
firewall-cmd --add-service=http --permanent
firewall-cmd --reload
systemctl enable httpd
systemctl start  httpd
#systemctl status httpd

2、FTP 配置

yum -y install vsftpd
/bin/cp -rf /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
sed -i "s/anonymous_enable=NO/anonymous_enable=YES/g" '/etc/vsftpd/vsftpd.conf'
#sed -i "s/#anon_upload_enable=YES/anon_upload_enable=NO/g" '/etc/vsftpd/vsftpd.conf'  #允许上传配置
sed -i "s/write_enable=YES/write_enable=NO/g" '/etc/vsftpd/vsftpd.conf'
echo 'pasv_min_port=10021' >> /etc/vsftpd/vsftpd.conf
echo 'pasv_max_port=10031' >> /etc/vsftpd/vsftpd.conf

/bin/cp -rf "/opt/LinuxInstaller/CentOS7.9/." /var/ftp/CentOS7.9
## mount --bind /opt/LinuxInstaller/CentOS7.9 /var/ftp/CentOS7.9
semanage fcontext -a -t public_content_t "/var/ftp/CentOS7.9(/.*)?"
restorecon -rf /var/ftp/CentOS7.9
find /var/ftp/CentOS7.9 -type f -exec chmod 444 {} \;
find /var/ftp/CentOS7.9 -type d -exec chmod 755 {} \;

firewall-cmd --add-service ftp --permanent
firewall-cmd --add-port 10021-10031/tcp --permanent
firewall-cmd --reload
systemctl enable vsftpd
systemctl start vsftpd
#systemctl status vsftpd

3、NFS 配置

yum -y install nfs-utils

mkdir -p opt/LinuxInstaller/CentOS7.9
echo '/opt/LinuxInstaller/CentOS7.9 192.168.150.0/24(ro,root_squash,all_squash,async)' >>/etc/exports
exportfs -arv

firewall-cmd --add-service nfs --permanent
firewall-cmd --add-service rpc-bind --permanent
firewall-cmd --reload
systemctl enable nfs-server.service
systemctl start nfs-server.service
#systemctl status nfs-server.service

六、启动菜单适配

       启动引导有基于BIOS和基于UEFI两种启动方式,通常x86_64架构的设备支持基于BIOS和基于UEFI启动方式,ARM架构的设备只支持UEFI启动。为增强部署环境的适应性,建议BIOS和UEFI的启动菜单都进行配置。

1、修改配置详细说明

原配置修改后配置
BIOS系统配置文件:'/var/lib/tftpboot/Legacy/pxelinux.cfg/default'
kernel vmlinuzkernel CentOS7.9/vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64三选一
append initrd=CentOS7.9/initrd.img inst.repo=http://192.168.150.100/CentOS7.9
append initrd=CentOS7.9/initrd.img inst.repo=ftp://192.168.150.100/CentOS7.9
append initrd=CentOS7.9/initrd.img inst.repo=nfs:nfsvers=4:192.168.150.100:/opt/LinuxInstaller/CentOS7.9
UEFI系统配置文件:'/var/lib/tftpboot/EFI/grub.cfg'
linuxefi /images/pxeboot/vmlinuz inst.stage2=hd:LABEL=CentOS\x207\x20x86_64三选一
linuxefi /EFI/CentOS7.9/vmlinuz inst.repo=http://192.168.150.100/CentOS7.9
linuxefi /EFI/CentOS7.9/vmlinuz inst.repo=ftp://192.168.150.100/CentOS7.9
linuxefi /EFI/CentOS7.9/vmlinuz inst.repo=nfs:nfsvers=4:192.168.150.100:/opt/LinuxInstaller/CentOS7.9
initrdefi /images/pxeboot/initrd.imginitrdefi /EFI/CentOS7.9/initrd.img


2、基于BIOS的系统

修改 /var/lib/tftpboot/Legacy/pxelinux.cfg/default 配置文件,具体如下:

3、基于UEFI的系统

修改 '/var/lib/tftpboot/EFI/grub.cfg'配置文件,具体如下:

六、验证配置

systemctl status tftp.socket | grep 'Active: '
systemctl status dhcpd | grep "Active: "
systemctl status httpd | grep "Active: "
systemctl status vsftpd | grep "Active: "
systemctl status nfs-server.service | grep "Active: "

       检查服务安装的tftp、dhcp、http、ftp、nfs服务都是“active”状态,而不是“inactive"状态,说明服务已经启用。

总结

        到这里,简单的PXE网络启动部署环境就算搭建完成。解决了十个光驱安装系统的问题,但要实现无人值守安装,可以参看后续专题,Kickstart配置

  • 9
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值