PXE高效批量网络装机

目录

PXE概述

1.PXE(Preboot eXcution Environment)

2.PXE批量部署的优点

 3.搭建PXE网络体系的前提条件

(1)客户端:

(2)服务端:

4.搭建 PXE 远程安装服务器

(1)安装并启用 TFTP 服务

(2)修改TFTP服务的配置文件

(3)安装并启用 DHCP 服务

(4)修改DHCP服务的配置文件

(5)安装FTP服务,准备CentOS 7 安装源

(6)准备 PXE 引导程序 和 准备 Linux 内核、初始化镜像文件

(7)配置启动菜单文件

(8)验证 PXE 网络安装

5.搭建PXE安装服务器完全自动安装

(1)安装system-config-kickstart 工具

(2)配置kickstart选项

(3)配置 ks.cfg 文件

(4)再次修改 defaults 文件配置,让ks.cfg文件配置生效

(5)新建虚拟机进行测试

总结

PXE概述

1.PXE(Preboot eXcution Environment)

PXE(预启动执行环境,在操作系统之前运行)是由Intel公司开发的网络引导技术,工作在Client/Server模式,允许客户机通过网络从远程服务器下载引导镜像,并加载安装文件或者整个操作系统。

2.PXE批量部署的优点

规模化:同时装配多台服务器

自动化 :安装系统、配置各种服务

远程实现:不需要光盘、U盘等安装介质

 3.搭建PXE网络体系的前提条件

(1)客户端:

【1】客户机的网卡要支持PXE协议(集成BOOTROM芯片)

【2】主板支持网络引导;一般大多数服务器主机都支持,只需在BIOS设置中允许从 Network 或

LAN 启动即可。

(2)服务端:

【1】网络中有一台 DHCP 服务器以便为客户机自动分配地址、指定引导文件位置。

【2】服务器要通过 TFTP服务(简单文件传输协议)来提供系统内核和引导镜像文件的下载。

4.搭建 PXE 远程安装服务器

(1)安装并启用 TFTP 服务

[root@localhost yum.repos.d]# yum install -y xinetd tftp-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 tftp-server.x86_64.0.5.2-22.el7 将被 安装
---> 软件包 xinetd.x86_64.2.2.3.15-14.el7 将被 安装
--> 解决依赖关系完成
.............................中间省略................................................
  正在安装    : 2:xinetd-2.3.15-14.el7.x86_64                                              1/2 
  正在安装    : tftp-server-5.2-22.el7.x86_64                                              2/2 
  验证中      : tftp-server-5.2-22.el7.x86_64                                              1/2 
  验证中      : 2:xinetd-2.3.15-14.el7.x86_64                                              2/2 

已安装:
  tftp-server.x86_64 0:5.2-22.el7                 xinetd.x86_64 2:2.3.15-14.el7                

完毕!

(2)修改TFTP服务的配置文件

[root@localhost ~]# cd /etc/xinetd.d/
[root@localhost xinetd.d]# ls
chargen-dgram   daytime-dgram   discard-dgram   echo-dgram   tcpmux-server  time-dgram
chargen-stream  daytime-stream  discard-stream  echo-stream  tftp           time-stream
[root@localhost xinetd.d]# vim 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        #TFTP默认使用UDP协议
        wait                    = no           #no表示客户机可以多台一起连接,                                       
        user                    = root         #yes表示客户机只能一台一台连接
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot   #指定TFTP根目录(引导文件的存储路径)
        disable                 = no                     #no表示开启TFTP服务
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

保存退出之后设置服务开机自启即可

[root@localhost xinetd.d]# systemctl enable --now xinetd
[root@localhost xinetd.d]# systemctl enable --now tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.

(3)安装并启用 DHCP 服务

[root@localhost xinetd.d]# yum install -y dhcp
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 dhcp.x86_64.12.4.2.5-83.el7.centos.1 将被 安装
  > 解决依赖关系完成
.............................中间省略.....................................
  正在安装    : 12:dhcp-4.2.5-83.el7.centos.1.x86_64                                       1/1 
  验证中      : 12:dhcp-4.2.5-83.el7.centos.1.x86_64                                       1/1 

已安装:
  dhcp.x86_64 12:4.2.5-83.el7.centos.1                                                         

完毕!

复制官方模板去指定目录

[root@localhost xinetd.d]# cd /usr/share/doc/dhcp-4.2.5/
[root@localhost dhcp-4.2.5]# ls
dhcpd6.conf.example  dhcpd.conf.example  ldap

[root@localhost dhcp-4.2.5]# \cp -f dhcpd.conf.example /etc/dhcp/dhcpd.conf 
[root@localhost dhcp-4.2.5]# cd /etc/dhcp/
[root@localhost dhcp]# ls
dhclient.d  dhclient-exit-hooks.d  dhcpd6.conf  dhcpd.conf  scripts

(4)修改DHCP服务的配置文件

[root@localhost dhcp]# vim dhcpd.conf 
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
#option domain-name "example.org";                             打上注释#
#option domain-name-servers ns1.example.org, ns2.example.org;  打上注释#

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
ddns-update-style none;          #取消注释#禁用DNS动态更新

next-server 192.168.10.10;       #指定 TFTP 服务器的地址
filename "pxelinux.0";           #指定要下载的 PXE 引导程序的文件

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

subnet 10.152.187.0 netmask 255.255.255.0 {
}

# This is a very basic subnet declaration.

subnet 192.168.10.0 netmask 255.255.255.0 {    #声明要分配的网段地址
  range 192.168.10.100 192.168.10.200;         #设置地址池
  option routers 192.168.10.10;         #默认网关地址指向TFTP服务器的IP地址
}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

subnet 10.254.239.32 netmask 255.255.255.224 {
  range dynamic-bootp 10.254.239.40 10.254.239.60;
  option broadcast-address 10.254.239.31;
  option routers rtr-239-32-1.example.org;
"dhcpd.conf" 107L, 3278C 已写入 

保存退出之后设置服务开机自启即可

[root@localhost dhcp]# systemctl enable --now dhcpd

(5)准备 PXE 引导程序 和 准备 Linux 内核、初始化镜像文件

[root@localhost ~]#yum install -y syslinux
[root@localhost ~]# cd /usr/share/selinux/
[root@localhost selinux]# ls
packages  targeted
[root@localhost selinux]# cd ..
[root@localhost share]# cd /usr/share/syslinux/
#PXE引导程序由软件包 syslinux 提供

[root@localhost syslinux]# ls

   pxelinux.0 
内容省略,只留下需要的内容

[root@localhost syslinux]# cp pxelinux.0 /var/lib/tftpboot/
#复制 PXE引导程序 到TFTP根目录下

[root@localhost syslinux]# ls /var/lib/tftpboot/
pxelinux.0
[root@localhost syslinux]# cd /mnt/
[root@localhost mnt]# ls
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@localhost mnt]# cd images/
[root@localhost images]# ls
efiboot.img  pxeboot  TRANS.TBL
[root@localhost images]# cd pxeboot/
[root@localhost pxeboot]# ls
initrd.img  TRANS.TBL  vmlinuz

[root@localhost pxeboot]# cp vmlinuz initrd.img /var/lib/tftpboot/
#复制 Linux系统的内核文件 和 初始化镜像文件(linux引导加载模块)到TFTP根目录下

[root@localhost pxeboot]# ls /var/lib/tftpboot/
initrd.img  pxelinux.0  vmlinuz

 (6)安装FTP服务,准备CentOS 7 安装源

[root@localhost dhcp]# yum install -y vsftpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 vsftpd.x86_64.0.3.0.2-29.el7_9 将被 安装
--> 解决依赖关系完成

依赖关系解决
..................................中间省略..................................
  正在安装    : vsftpd-3.0.2-29.el7_9.x86_64                                               1/1 
  验证中      : vsftpd-3.0.2-29.el7_9.x86_64                                               1/1 

已安装:
  vsftpd.x86_64 0:3.0.2-29.el7_9                                                               

完毕!
[root@localhost dhcp]# systemctl enable --now vsftpd
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@localhost dhcp]# cd /var/ftp/
[root@localhost ftp]# mkdir centos7
[root@localhost ftp]# ls /mnt/
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL
[root@localhost ftp]# mount /dev/sr0 /var/ftp/centos7/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ftp]# cd /var/ftp/centos7/
[root@localhost centos7]# ls
CentOS_BuildTag  EULA  images    LiveOS    repodata              RPM-GPG-KEY-CentOS-Testing-7
EFI              GPL   isolinux  Packages  RPM-GPG-KEY-CentOS-7  TRANS.TBL

(7)配置启动菜单文件

[root@localhost centos7]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  vmlinuz
[root@localhost tftpboot]# mkdir pxelinux.cfg
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  pxelinux.cfg  vmlinuz
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# touch default
[root@localhost pxelinux.cfg]# ls
default
[root@localhost pxelinux.cfg]# vim default

default auto           #指定默认入口名称
prompt 1               #设置是否等待用户选择,“1”表示等待用户控制

label auto         #图形安装(默认)引导入口,label 用来定义启动项
kernel vmlinuz     #kernel 和 append用来定义引导参数
append initrd=initrd.img method=ftp://192.168.10.10/centos7

label text                 #文本安装引导入口
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.10.10/centos7

label rescue              #救援模式引导入口
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.10.10/centos7

(8)验证 PXE 网络安装

首先启动 tftp-server  xinetd  dhcpd  vsftpd 四个服务,然后使用 VMware创建的虚拟机进行测试,

虚拟机内存至少需要 2GB,否则在启动安装时可能会报错。

由于没有加载光盘,会自动采用网络引导启动

开启虚拟机,在提示字符串“boot:”后直接按Enter键(或执行“auto”命令),将会自动通过网络下载安装文件,并进入默认的图形安装入口;

完成这些配置之后,点击开始安装即可

5.搭建PXE安装服务器完全自动安装

(1)安装system-config-kickstart 工具

[root@localhost ~]# yum install -y system-config-kickstart

之后有两种方法可以进入kickstart 工具界面

【1】图形化界面操作

【2】命令操作

作用:可以自动完成安装界面选项的选择

(2)配置kickstart选项

 

验证配置暂时可以忽略

显示配置默认即可

软件包选择在centos7,无法正常选择,需要重新设置

(3)配置 ks.cfg 文件

在root界面下进行查看,出现 ks.cfg 文件

[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  ks.cfg  
公共  模板  视频  图片  文档  下载  音乐  桌面

          #其中 anaconda-ks.cfg 是系统的应答文件

[root@localhost ~]# vim ks.cfg     #查看文件内容

获取软件包配置需要到系统的应答文件中复制一些配置到 ks.cfg  文件中。(下面为配置信息)

系统应答文件中的相关配置

%packages                             @起点位置标识
@^gnome-desktop-environment
@base
@core
@desktop-debugging
@development
@dial-up
@directory-client
@fonts
@gnome-desktop
@guest-agents                        中间为自动化装载需要的软件包配置
@guest-desktop-agents
@input-methods
@internet-browser
@java-platform
@multimedia
@network-file-system-client
@networkmanager-submodules
@print-client
@x11
chrony
kexec-tools

%end                                 #终点位置标识

将这些配置复制到 ks.cfg 文件末尾位置后,保存退出即可

拓展:最小安装就是在上面的配置文件删掉中间,加入一个@^minimal 即可

%packages   
@^minimal        #最小安装配置
%end   

将保存修改后的ks.cfg  文件移动到ftp中

[root@localhost ~]# cp ks.cfg /var/ftp/
[root@localhost ~]# cd /var/ftp/
[root@localhost ftp]# ls
centos7  ks.cfg  pub 

(4)再次修改 defaults 文件配置,让ks.cfg文件配置生效

[root@localhost ftp]# cd /var/lib/tftpboot/
[root@localhost tftpboot]# ls
initrd.img  pxelinux.0  pxelinux.cfg  vmlinuz
[root@localhost tftpboot]# cd pxelinux.cfg/
[root@localhost pxelinux.cfg]# ls
default
[root@localhost pxelinux.cfg]# vim default
default auto
prompt 0                #将1改成 0 可以不用再按Enter或写入auto

label auto
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.10.10/centos7 ks=ftp://192.168.10.10/ks.cfg
                                #每行增加ks=ftp://192.168.10.10/ks.cfg配置
label text
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.10.10/centos7 ks=ftp://192.168.10.10/ks.cfg

label rescue
kernel vmlinuz
append initrd=initrd.img method=ftp://192.168.10.10/centos7 ks=ftp://192.168.10.10/ks.cfg

(5)新建虚拟机进行测试

无需任何操作,自动安装和选择配置

 之后等待安装完成后,进入到虚拟机查看配置

    #在新建的虚拟机中查看,在kickstart配置界面写入的命令
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
local.repo  repo.bak
[root@localhost yum.repos.d]# cat local.repo 
[local]
name=local
baseurl=ftp://192.168.80.30/centos7
enabled=1
gpgcheck=0
[root@localhost yum.repos.d]

总结

PXE  批量网络远程安装系统

1.安装 tftp-server  xinetd  dhcp  vsftpd  syslinux 软件包

tftp-server  xinetd  用于传输系统内核和系统初始化镜像文件 vmlinuz  initrd.img
dhcp     用于自动分配地址、指定PXE引导文件位置  next-server    filename
vsftpd   用于提供系统软件包安装源
syslinux 用于提供PXE引导程序文件 pxelinux.0

2.复制 vmlinuz  initrd.img  pxelinux.0 到  /var/lib/tftpboot/ 目录

3.在 /var/lib/tftpboot/ 目录里准备 PXE 启动菜单配置文件  pxelinux.cfg/default

4.修改服务配置文件,启动 tftp-server  xinetd  dhcpd  vsftpd 服务

5.安装 system-config-kickstart ,准备 kickstart 自动应答文件,修改 PXE 启动菜单配置文件,实现 Kickstart 无人值守安装

6.客户机要求至少内存2G,并设置成网络引导开机

<think>好的,我现在需要回答用户关于在Linux环境下通过PXE实现高效批量网络安装操作系统并自动挂载存储的问题。首先,我需要回忆PXE的基本原理和相关组件,确保自己理解正确。 根据用户提供的引用,PXE服务器需要集成DHCP、TFTP、HTTP/FTP等服务。用户提到自动挂载存储,这可能涉及到Kickstart配置中的存储设置或者安装后的自动挂载脚本。我需要检查引用中提到的内容,比如引用[4]提到ks.cfg应答文件可以自动安装系统,无需干预,这可能与存储配置有关。 接下来,我应该分步骤说明如何搭建PXE服务器,配置必要的服务,然后结合Kickstart实现自动化安装。同时,要确保在Kickstart配置文件中添加存储挂载的指令,比如分区和挂载点。此外,可能需要在安装后脚本中设置自动挂载,比如修改/etc/fstab。 需要注意用户要求自动挂载存储,这可能包括本地磁盘分区或网络存储(如NFS、iSCSI)。在Kickstart配置中,需要明确分区方案,并在%post部分添加挂载命令或配置fstab。引用[5]中复制内核文件到TFTP根目录的步骤也需要提及,确保PXE引导文件正确部署。 最后,生成相关问题时要围绕PXE配置、Kickstart优化、存储挂载方法等方面,帮助用户进一步了解相关主题。</think>### 如何通过Linux PXE实现高效批量网络安装并自动挂载存储? #### 一、PXE批量网络安装核心步骤 1. **搭建PXE服务器环境** - **安装必要服务**:需部署DHCP、TFTP、HTTP/FTP服务,其中DHCP用于分配IP并引导客户端获取启动文件,TFTP提供引导程序(如`pxelinux.0`)和内核文件,HTTP/FTP存储操作系统镜像[^2][^3]。 - **配置DHCP**:在`/etc/dhcp/dhcpd.conf`中添加以下配置: ```plaintext subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.100 192.168.1.200; option routers 192.168.1.1; filename "pxelinux.0"; # 引导文件路径 next-server 192.168.1.10; # TFTP服务器IP } ``` - **部署TFTP服务**:将引导文件(如`pxelinux.0`、`vmlinuz`内核和`initrd.img`初始RAM磁盘)复制到`/var/lib/tftpboot/`目录[^5]。 2. **配置Kickstart无人值守安装** - **生成`ks.cfg`文件**:使用`system-config-kickstart`工具或手动编写应答文件,定义分区、软件包、用户设置等。示例片段: ```plaintext # 分区与存储配置(自动挂载) clearpart --all --initlabel part / --fstype="xfs" --size=20480 part /data --fstype="xfs" --size=10240 # 自定义挂载点 ``` - **关联Kickstart与PXE**:在`/var/lib/tftpboot/pxelinux.cfg/default`菜单中追加: ```plaintext label auto kernel vmlinuz append initrd=initrd.img ks=http://192.168.1.10/ks.cfg ``` 3. **实现存储自动挂载** - **在Kickstart中定义分区**:通过`part`指令划分存储设备并指定挂载点(如上述示例)。 - **配置`/etc/fstab`(可选)**:在`%post`脚本中添加命令,实现开机自动挂载网络存储(如NFS): ```bash echo "192.168.1.20:/nfs_share /mnt/nfs nfs defaults 0 0" >> /etc/fstab ``` #### 二、验证与部署 1. **启动PXE客户端**:目标设备设置为PXE启动后,会自动获取IP并加载安装菜单。 2. **观察自动化流程**:系统将按`ks.cfg`完成安装,存储分区和挂载点会自动生效[^4]。 --- ###
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值