PXE 网络安装 CentOS 7,BIOS(Legacy) 和 UEFI 启动都支持_pxe服务器 uefi+bios-程序员宅基地

技术标签: linux  服务器  centos7  centos  

CentOS 7 配置 PXE+Kickstart 实现网络安装(无人值守)

网络安装至少需要两个系统:

  • 服务器 - 运行 DHCP服务器、TFTP 服务器从服务器提供引导文件,同时 HTTP、FTP 或者 NFS 服务器托管安装映射。
  • 客户端 - 要安装系统的机器。安装开始时,客户端会查询 DHCP 服务器,从 TFTP 服务器中获取引导文件,并从 HTTP、FTP 或者 NFS 服务器下载安装映象。

配置网络引导

网络引导配置步骤在不同的系统中有所不同,具体看要安装 Linux 的系统是使用 BIOS 还是UEFI

配置防火墙

# 关闭并禁用防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

# 在防火墙中允许某服务的连接(本次不使用此方式)
[root@localhost ~]# firewall-cmd --add-service=tftp

配置SELinux

# 查看SELinux状态
[root@localhost ~]# getenforce
Enforcing
# 设置SELinux为permissive模式,1 是Enfocing模式
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
# 彻底禁用SELinux
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

配置Yum仓库

使用ISO镜像搭建本地仓库,提升安装软件包的速度。

# ISO文件挂载
[root@localhost ~]# mount -o loop,ro -t iso9660 CentOS-7-x86_64-DVD-1810.iso /media
# cdrom光盘挂载(根据自己的情况二选一)
[root@localhost ~]# mount /dev/cdrom /media
# 备份原有文件
[root@localhost ~]# cp -r /etc/yum.repos.d /etc/yum.repos.d_bak
[root@localhost ~]# rm -f /etc/yum.repos.d/*
# yum配置文件
[root@localhost ~]# cat /etc/yum.repos.d/local.repo
[development]
name=local
baseurl=file:///media/
gpgcheck=0
[root@localhost ~]# yum makecache

安装配置HTTP服务

[root@localhost ~]# yum install -y httpd
# 启动HTTP服务
[root@localhost ~]# systemctl start httpd
# 设置开机启动
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

# 系统通过网络安装时需要指定安装源,这里使用HTTP服务提供安装源,也可以通过FTP服务提供
# 将ISO文件挂载后复制到/var/www/html目录即可
[root@localhost ~]# mount -o loop,ro -t iso9660 CentOS-7-x86_64-DVD-1810.iso /media
# cdrom光盘挂载(根据自己的情况二选一)
[root@localhost ~]# mount /dev/cdrom /media
[root@localhost ~]# cp -r /media /var/www/html/centos7.6

安装配置TFTP服务

[root@localhost ~]# yum install -y tftp-server
# 在 /etc/xinet.d/tftp 配置文件中,将 disabled 参数从 yes 改为 no
[root@localhost ~]# vim /etc/xinetd.d/tftp
[root@localhost ~]# cat /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
}
# 启动服务
[root@localhost ~]# systemctl start tftp
[root@localhost ~]# systemctl enable tftp
Created symlink from /etc/systemd/system/sockets.target.wants/tftp.socket to /usr/lib/systemd/system/tftp.socket.
[root@localhost ~]# systemctl status tftp

安装配置DHCP服务

[root@localhost ~]# yum install -y dhcp

# subnet字段为局部设置,优先级高于全局。option在全局和局部都可设置
[root@localhost ~]# cat /etc/dhcp/dhcpd.conf
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
option space pxelinux;
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;

subnet 192.168.22.0 netmask 255.255.255.0 {
    
  option routers 192.168.22.2;              # 网关
  range 192.168.22.190 192.168.22.199;      # 可分配的起始IP~结束IP

  class "pxeclients" {
    
      match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
      next-server 192.168.22.132;    # 提供引导文件的服务器IP地址,即tftp服务器地址

      if option architecture-type = 00:07 {
    
        filename "uefi/shim.efi";         # 采用shim打包的EFI引导映象
      } else {
    
        filename "pxelinux/pxelinux.0";   # SYSLINUX打包的BIOS引导映像
      }
  }
}

# 启动服务并设置开机自启
[root@localhost ~]# systemctl start dhcpd.service
[root@localhost ~]# systemctl enable dhcpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
[root@localhost ~]# systemctl status dhcpd.service

为使用BIOS(Legacy)的机器配置

  • 需要软件包 SYSLINUX 中的 pxelinux.0 文件

    [root@localhost ~]# cp /media/Packages/syslinux-4.05-15.el7.x86_64.rpm ./
    # 提取软件包
    [root@localhost ~]# rpm2cpio syslinux-4.05-15.el7.x86_64.rpm | cpio -dimv
    [root@localhost ~]# ls -lrt usr/share/syslinux/pxelinux.0
    -rw-r--r--. 1 root root 26759 10月 31 2018 usr/share/syslinux/pxelinux.0
    
  • tftpboot 中创建 pxelinux 目录,并将 pxelinux.0 复制到该目录中

    [root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux
    [root@localhost ~]# cp usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/pxelinux
    
  • pxelinux/ 目录中创建目录 pxelinux.cfg,添加名为 default 的配置文件

    [root@localhost ~]# mkdir /var/lib/tftpboot/pxelinux/pxelinux.cfg
    # 可根据/media/isolinux/isolinux.cfg修改
    ## 设置背景图片,如 menu background splash.png,要将splash.png文件放在pxelinux目录下
    ## 设置菜单风格,如 default vesamenu.c32,要将vesamenu.c32文件放在pxelinux目录下
    ## 这里直接指定从哪个label启动,省去了进入菜单的时间
    [root@localhost ~]# vim /var/lib/tftpboot/pxelinux/pxelinux.cfg/default
    default linux
    prompt 1
    timeout 600
    
    label linux
      menu label ^Install system
      kernel vmlinuz
      append initrd=initrd.img ip=dhcp inst.repo=http://192.168.22.132/centos7.6 inst.ks=http://192.168.22.132/ks.cfg
    
  • 将引导映像复制到 pxelinux/ 目录下

    [root@localhost ~]# cp /media/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/pxelinux/
    [root@localhost ~]# tree /var/lib/tftpboot/pxelinux/
    /var/lib/tftpboot/pxelinux/
    ├── initrd.img
    ├── pxelinux.0
    ├── pxelinux.cfg
    │   └── default
    └── vmlinuz
    
  • 重新载入已运行服务 tftpxinetddhcp

    [root@localhost ~]# systemctl daemon-reload
    [root@localhost ~]# systemctl restart tftp httpd dhcpd
    # 将用到的服务设置为开机自启(已设置过请忽略)
    [root@localhost ~]# systemctl enable tftp httpd dhcpd
    

为使用UEFI的机器配置

  • 需要软件包 shim 中的 shim.efi 文件,和软件包 grub2-efigrubx64.efi 文件

    [root@localhost ~]# cp /media/Packages/shim-x64-15-1.el7.centos.x86_64.rpm ./
    [root@localhost ~]# cp /media/Packages/grub2-efi-x64-2.02-0.76.el7.centos.x86_64.rpm ./
    # 提取软件包
    [root@localhost ~]# rpm2cpio shim-x64-15-1.el7.centos.x86_64.rpm | cpio -dimv
    [root@localhost ~]# rpm2cpio grub2-efi-x64-2.02-0.76.el7.centos.x86_64.rpm | cpio -dimv
    [root@localhost ~]# ls -l boot/efi/EFI/centos/shim.efi
    -rwx------. 1 root root 1205224 11月 10 2018 boot/efi/EFI/centos/shim.efi
    [root@localhost ~]# ls -l boot/efi/EFI/centos/grubx64.efi
    -rwx------. 1 root root 1090976 11月  9 2018 boot/efi/EFI/centos/grubx64.efi
    
  • tftpboot/ 目录中创建 uefi/ 目录,并将 EFI 引导映像复制到该目录下

    [root@localhost ~]# mkdir /var/lib/tftpboot/uefi
    [root@localhost ~]# cp boot/efi/EFI/centos/shim.efi /var/lib/tftpboot/uefi/
    [root@localhost ~]# cp boot/efi/EFI/centos/grubx64.efi /var/lib/tftpboot/uefi/
    [root@localhost ~]# chmod 644 /var/lib/tftpboot/uefi/shim.efi
    [root@localhost ~]# chmod 644 /var/lib/tftpboot/uefi/grubx64.efi
    
  • uefi/ 目录中添加名为 grub.cfg 的配置文件

    # 可根据/media/EFI/BOOT/grub.cfg修改
    [root@localhost ~]# vim /var/lib/tftpboot/uefi/grub.cfg
    set timeout=10
      menuentry 'RHEL 7' {
          
      linuxefi uefi/vmlinuz ip=dhcp inst.repo=http://192.168.22.132/centos7.6 inst.ks=http://192.168.22.132/ks_uefi.cfg
      initrdefi uefi/initrd.img
    }
    
  • pxeboot 引导映像复制到 uefi/ 目录下

    [root@localhost ~]# cp /media/images/pxeboot/{vmlinuz,initrd.img}  /var/lib/tftpboot/uefi/
    [root@localhost ~]# tree /var/lib/tftpboot/uefi/
    /var/lib/tftpboot/uefi/
    ├── grub.cfg
    ├── grubx64.efi
    ├── initrd.img
    ├── shim.efi
    └── vmlinuz
    
  • 重新载入已运行服务 tftpxinetddhcp

    [root@localhost ~]# systemctl daemon-reload
    [root@localhost ~]# systemctl restart tftp httpd dhcpd
    # 将用到的服务设置为开机自启(已设置过请忽略)
    [root@localhost ~]# systemctl enable tftp httpd dhcpd
    

创建Kickstart应答文件

# 操作系统安装后,root家目录下有应答文件anaconda-ks.cfg,可根据要安装的机器情况修改该文件
[root@localhost ~]# cp anaconda-ks.cfg /var/www/html/ks.cfg
[root@localhost ~]# chmod +r /var/www/html/ks.cfg
[root@localhost ~]# ls -l /var/www/html/
total 4
-rw-r--r--. 1 root root 1618 Aug 11 11:23 ks.cfg
drwxr-xr-x. 8 root root  254 Aug 11 10:49 media

# 验证 Kickstart 文件,pykickstart 软件包提供的 ksvalidator 命令
[root@localhost ~]# yum install pykickstart
[root@localhost ~]# ksvalidator ks.cfg

也可以在线编辑,如果有红帽客户门户网站帐户,则可以使用 https://access.redhat.com/labs/kickstartconfig/ 中的 Kickstart Configuration Tool 完成基本配置,并下载得到的 Kickstart 文件。

使用 ksverdiff 命令显示两本版本间 Kickstart 语法的不同。

# -f 指定要比较的第一个发行本,-t 指定要比较的最后一个发行本。
[root@localhost ~]# ksverdiff -f RHEL6 -t RHEL7

使用system-config-kickstart生成应答文件

system-config-kickstart是一款图形化工具,需要桌面环境或X11服务

# 安装system-config-kickstart
[root@localhost ~]# yum install -y system-config-kickstart
# 启动system-config-kickstart
[root@localhost ~]# system-config-kickstart
安装X11
# 服务端安装X11服务,需要重新登录自动生成.Xauthority文件
[root@localhost ~]# yum install -y xorg-x11-xauth
# 中文字体(可选)
[root@localhost ~]# yum install -y google-noto-sans-fonts wqy-unibit-fonts wqy-zenhei-fonts
安装图形界面(不建议)
[root@localhost ~]# yum groups list
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Installed Groups:
   Legacy UNIX Compatibility
   System Administration Tools
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Scientific Support
   Security Tools
   Smart Card Support
   System Management
Done

[root@localhost ~]# yum groupinstall -y "Server with GUI"
[root@localhost ~]# cat /etc/inittab
# 查看默认运行级别
[root@localhost ~]# systemctl get-default
# 设置图形化为默认
[root@localhost ~]# systemctl set-default graphical.target
# startx命令切换到图形界面

问题

  • 软件包选择时,出现“由于下载软件包失败, 软件包选择被禁止”错误

    修改Yum配置文件 local.repo,自定义标识源改为 [development]

  • 安装时出现 “no space left on device” 错误

    PXE装机内存最少要2G

参考

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Future_promise/article/details/108287038

智能推荐

AVFrame&AVPacket_天天av-程序员宅基地

文章浏览阅读1.5w次。AVFrame:( This structure describes decoded (raw) audio or video data. AVFrame must be allocated using av_frame_alloc(). Note that this only allocates the AVFrame itself, the buffers for the data mus_天天av

Java经典例题07:用100元人民币兑换10元、5元、1元的纸币_编程把100元换成1元5元10元-程序员宅基地

文章浏览阅读3.5k次,点赞2次,收藏12次。解题思路分析:1.100元兑换10元纸币,可以兑换10张,但每种纸币都要有,所以最多只能兑换9张,最少兑换1张。则初始值为1;循环条件小于10或者小于等于9。2.100元兑换5元纸币,可以兑换20,但每种纸币都要有,所以最多只能兑换19张,最少兑换1张。初始值为1;循环条件小于20或者小于等于19。3.100元兑换1元纸币,可以兑换100张,但每种纸币都要有,所以最多只能兑换99张,最少兑换1张。则初始值为1;循环条件小于100或者小于等于99。_编程把100元换成1元5元10元

猜三次年龄_找人猜三次年龄-程序员宅基地

文章浏览阅读450次。1、允许用户最多尝试三次2、每尝试三次后,如果还没猜对,就问用户是否继续玩,如果回答Y,y,就继续猜三次,以此往复,如果回答N,n,就直接退出times=0count=3while times<=3:age=int(input(‘请输入年龄:’))if age == 18:print(‘猜对了’)breakelif age > 18:print(‘猜大了’)else:print(‘猜小了’)times+=1if times3:choose = input(‘继续猜Y_找人猜三次年龄

SDOI2017 Round2 详细题解-程序员宅基地

文章浏览阅读152次。这套题实在是太神仙了。。做了我好久。。。好多题都是去搜题解才会的 TAT。剩的那道题先咕着,如果省选没有退役就来填吧。「SDOI2017」龙与地下城题意丢 \(Y\) 次骰子,骰子有 \(X\) 面,每一面的概率均等,取值为 \([0, X)\) ,问最后取值在 \([a, b]\) 之间的概率。一个浮点数,绝对误差不超过 \(0.013579\) 为正确。数据范围每组数据有 \...

嵌入式数据库-Sqlite3-程序员宅基地

文章浏览阅读1.1k次,点赞36次,收藏25次。阅读引言: 本文将会从环境sqlite3的安装、数据库的基础知识、sqlite3命令、以及sqlite的sql语句最后还有一个完整的代码实例, 相信仔细学习完这篇内容之后大家一定能有所收获。

C++ Builder编写WinForm从Web服务器下载文件-程序员宅基地

文章浏览阅读51次。UnicodeString templateSavePath = ChangeFileExt(ExtractFilePath(Application->ExeName),"tmp.doc");IdAntiFreeze1->OnlyWhenIdle = false;//设置使程序有反应.TMemoryStream *templateStream ;templateStre..._c++webserver下载文件

随便推点

JAVA小项目潜艇大战_java潜艇大战-程序员宅基地

文章浏览阅读8.3k次,点赞10次,收藏41次。一、第一天1、创建战舰、侦察潜艇、鱼雷潜艇、水雷潜艇、水雷、深水炸弹类完整代码:package day01;//战舰public class Battleship { int width; int height; int x; int y; int speed; int life; void move(){ System.out.println("战舰移动"); }}package day01;//侦察潜艇_java潜艇大战

02表单校验的基本步骤-程序员宅基地

文章浏览阅读940次。表单校验的基本步骤_表单校验

libOpenBlas.dll缺失依赖解决办法-程序员宅基地

文章浏览阅读4.5k次。libOpenBlas.dll缺失依赖解决办法 intellij idea 1.dll文件缺失依赖,报错:“找不到指定模块”2.下载depends查看dll缺失文件3.下载缺失依赖libopenblas.dll出错起因由于java web项目需要调用openBlas库来进行运算,就下载了预编译的libopenblas文件进行调用,首先遇到路径出错问题、之后又是dll文件缺失依赖问题,以下是解决..._libopenblas.dll

Swoole 实践篇之结合 WebSocket 实现心跳检测机制-程序员宅基地

文章浏览阅读251次,点赞3次,收藏10次。这里实现的心跳检测机制是一个基础版的,心跳包的主要作用是用于检测用户端是否存活,有助于我们及时判断用户端是否存在断线的问题。在我之前开发过的项目中,有一个基于物联网在线直播抓娃娃的项目,其中就有需要实时监控设备在线状态的需求,该需求就是使用心跳包来实现的。实际上心跳检测技术,应用更广泛的是实时通信、或设备管理的场景偏多。

Maven dependency scope_maven dependent scope-程序员宅基地

文章浏览阅读714次。Dependency scope is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks.There are 6 scopes available:compileThis is the default scop_maven dependent scope

TCP头部结构信息_tcp头部包含哪些信息-程序员宅基地

文章浏览阅读3.6k次。TCP 头部结构信息_tcp头部包含哪些信息