【網絡安裝】1. 簡單網絡引導安裝 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM