简单网络引导安装 CentOS7

时间:2021-08-24
本文章向大家介绍简单网络引导安装 CentOS7,主要包括简单网络引导安装 CentOS7使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

组件介绍

xinetd -- 对服务访问进行控制,这里主要是控制tftp
dhcp -- 动态分配IP
tftp-server -- 从服务器端下载pxelinux.0、default文件
syslinux -- 用于网络引导
httpd -- 在网络上提供安装源,也就是镜像文件中的内容

注:这里所有服务都运行在同一服务器中,IP地址为:192.168.22.10

安装配置组件

安装组件

# yum install xinetd dhcp tftp-server syslinux httpd

配置DHCP

# vim /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#
ddns-update-style none;
ignore client-updates;
default-lease-time 259200;
max-lease-time 518400;
option domain-name-servers 192.168.22.2;
subnet 192.168.22.0 netmask 255.255.255.0 {
       range 192.168.22.101 192.168.22.110;
       option routers 192.168.22.2; 
       option subnet-mask 255.255.255.0;
       # the configuration for tftp-server
       next-server 192.168.22.10;
       # the configuration file for pxe boot
       filename "pxelinux.0";  # 如果是UEFI模式,修改为“BOOTX64.EFI”
       #filename "BOOTX64.EFI";
}

# systemctl start dhcpd.service
# systemctl enable dhcpd.service

配置TFTP

# vim /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  # 将此值改为no,表明开启此服务
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}

# systemctl start xinetd.service
# systemctl start tftp.service
# ss -tunlp | grep xinetd
# ss -tunlp | grep tftp

配置HTTPD并准备安装文件

vmlinuz:可引导的、压缩的内核文件
initrd.img:包含一些模块和安装文件系统

# systemctl start httpd.service
# systemctl enable httpd.service

# mkdir /var/www/html/centos7
# mount /dev/sr0 /var/www/html/centos7

# mkdir /var/lib/tftpboot/centos7
# cp /var/www/html/centos7/images/pxeboot/initrd.img /var/lib/tftpboot/centos7/
# cp /var/www/html/centos7/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7/

设置syslinux加载器

/usr/share/syslinux/menu.c32  文本模式
/usr/share/syslinux/vesamenu.c32  图形模式
/usr/share/syslinux/pxelinux.0

vesamenu.c32 和 menu.c32 是syslinux所拥有众多模块中的两个,它们的功能是指定启动器使用什么模式的背景。这里选择menu.c32,即文本模式。

pxelinux.0文件对整个引导器的作用就如同内核对系统的作用一般,它可以解释default文件(配置引导菜单的文件)中的每个配置项,并根据配置项做出不同的反应。如等待的时间、启动器背景、启动菜单、内核引导等等。

# cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot

pxelinux.cfg目录:pxelinux被执行后,它会扫描该目录下是否存在指定的配置文件,如果存在,则引用被制定的配置文件。

default文件存放于pxelinux.cfg目录中,pxelinux程序最后扫描的配置文件名就是default。所以,我们经常把启动器配置项都写入该文件中。

所以我们就要建立pxelinux.cfg,并在此目录下建立default文件,编辑引导菜单。

# mkdir /var/lib/tftpboot/pxelinux.cfg
# vim /var/lib/tftpboot/pxelinux.cfg/default

default文件内容为:(BIOS引导模式)

default menu.c32
prompt 0
timeout 30

menu title ########## PXE Boot Menu ##########

label linux
  menu label ^Install CentOS 7
  kernel centos7/vmlinuz
  append initrd=centos7/initrd.img repo=http://192.168.22.10/centos7 quiet

检查文件以及服务

此时/var/lib/tftp文件夹的结构应该是这样的:

/var/lib/tftpboot/
├── centos7
│   ├── initrd.img
│   └── vmlinuz
├── menu.c32
├── pxelinux.0
└── pxelinux.cfg
    └── default

确保开启dhcpd、xinetd、tftp、http这些服务,在开启的时候没有发生错误,说明配置没问题。

验证httpd是否运行正常:http://192.168.22.10/centos7/

同时为了防止意外的发生我们需要关闭防火墙和selinux。

# systemctl stop firewalld.service
# systemctl enable firewalld.service
# setenforce 0
# vim /etc/selinux/config
...
SELINUX=permissive
...

测试

pxe服务器配置完成后,就可以在此子网中用网络引导安装了,此时和普通的安装系统差别不大,但是要选择从网络引导。

注意

如果服务器内存配置小于2GB,自动化安装会出现以下错误信息:

dracut-initqueue[629]: curl: (23) Failed writing body

相关Bug:

Bug 1595369 - rhel 7.5 installation fails with 1GB ram

https://bugzilla.redhat.com/show_bug.cgi?id=1595369
作者:Varden
本文内容如有雷同,请联系作者!
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/varden/p/15179036.html