Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

PXE + TFTP + DHCP 實現 Linux 網絡無人值守安裝全流程

編輯:Linux 教學

PXE(Preboot Execution Environment)讓客戶端通過網絡從服務器下載啟動映像並安裝作業系統。本文詳細記錄基於 CentOS 的 TFTP + DHCP 服務端配置、PXE 引導文件準備、啟動菜單定製及客戶端安裝全流程。

服務端環境準備

# 安裝核心服務
yum install tftp-server tftp dhcp
# 檢查安裝
rpm -qa tftp* dhcp*

TFTP 服務配置

編輯 /etc/xinetd.d/tftp:

service tftp
{
    socket_type = dgram
    protocol = udp
    wait = yes
    user = root
    server = /usr/sbin/in.tftpd
    server_args = -u nobody -s /tftpboot
    disable = no          # 關鍵:yes → no
    per_source = 11
    cps = 100 2
    flags = IPv4
}

啟動:service xinetd restart

DHCP 服務配置

  1. 複製模板:cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
  2. 核心配置段:
    subnet 192.168.12.0 netmask 255.255.255.0 {
        option routers 192.168.12.1;
        option subnet-mask 255.255.255.0;
        option domain-name-servers 192.168.12.1;
        range dynamic-bootp 192.168.12.128 192.168.12.254;
        default-lease-time 21600;
        max-lease-time 43200;
        # PXE 關鍵指令
        next-server 192.168.12.1;      # TFTP 服務器 IP
        filename "pxelinux.0";         # 引導文件名
    }
  3. 啟動:service dhcpd restart && chkconfig dhcpd on

PXE 引導文件準備

  1. 安裝 syslinux:yum install syslinux
  2. 複製引導文件:
    cp /usr/share/syslinux/pxelinux.0 /tftpboot/
    cp /usr/share/syslinux/menu.c32 /tftpboot/
    cp /usr/share/syslinux/memdisk /tftpboot/
    cp /usr/share/syslinux/mboot.c32 /tftpboot/
  3. 創建啟動菜單 /tftpboot/pxelinux.cfg/default:
    DEFAULT menu.c32
    PROMPT 0
    TIMEOUT 300
    MENU TITLE PXE Network Install
    
    LABEL centos7
        MENU LABEL ^1. Install CentOS 7 x64
        KERNEL images/centos7/vmlinuz
        APPEND initrd=images/centos7/initrd.img inst.repo=https://192.168.12.1/centos7 ks=https://192.168.12.1/ks.cfg
    
    LABEL local
        MENU LABEL ^2. Boot from local disk
        LOCALBOOT 0

安裝源與 Kickstart 配置

  • 掛載 ISO 並導出 HTTP:mount -o loop CentOS-7-x86_64-DVD.iso /mnt && ln -s /mnt /var/www/html/centos7
  • 編寫 ks.cfg 實現完全無人值守安裝(分區、軟件包、網絡、root 密碼等)

客戶端安裝驗證

  1. 客戶端 BIOS 設置網絡啟動優先
  2. 獲取 DHCP IP → 下載 pxelinux.0 → 顯示菜單 → 選擇安裝項 → 自動完成
Copyright © Windows教程網 All Rights Reserved