2020年10月8日 星期四

CentOS8建置PXE server(網路開機安裝)

   因為公司主管需要我研究這個東西所以就寫了一份很詳細的教學文件,但我是覺得,如果非必要用實機的話還是用虛擬機去做大量部署會來的好,虛擬機做一台10秒,實機裝一台30分鐘,光這樣比就不用比了,不過是拿來測試倒是也可以用用看。


  

  • 安裝套件dnsmasqCentOS8預設已有安裝

    yum install dnsmasq

  • 備 份原dnsmasq設定檔,建立新的設定檔

    mv -v /etc/dnsmasq.conf /etc/dnsmasq.conf.bak

    v i /etc/dnsmasq.cof

  • 輸入以下設定

    interface=ens192 #PXE server網卡代號

    bind-interfaces

    domain=linuxhint.local #主機名

    dhcp-range=ens192,192.168.199.100,192.168.199.240,255.255.255.0,8h #DHCP ip範圍

    dhcp-option=option:router,192.168.199.254 #gateway ip

    dhcp-option=option:dns-server,168.95.1.1 #dns server

    dhcp-option=option:dns-server,8.8.8.8 #dns server

    enable-tftp #啟用tftp server

    tftp-root=/netboot/tftp #指定tftp路徑

    dhcp-boot=pxelinux.0,192.168.199.26 #指定client端要連的PXE server

    pxe-prompt="Press F8 for PXE Network boot.",5

    pxe-service=x86PC,"Install OS via PXE",pxelinux



  • 建立PXE server必要目錄

    mkdir -pv netboottftp/pxelinux.cfg



  • 啟動dnsmasq服務

    service dnsmasq start



  • 確 認服務狀態

    service dnsmasq status



  • 安裝PXE相關套件

    yum install syslinux





  • 複製pxe開機必要檔案到tftp路徑資料夾

    cp -v /usr/share/syslinux/{pxelinux.0,menu.c32,ldlinux.c32,libutil.c32} /netboot/tftp/



  • 安裝Apache server

    yum install httpd



  • 建立apache目錄捷徑到/netboot資料夾

    ln -s /var/www/html /netboot/www



  • 啟動Apache服務

    service httpd start



  • 掛載欲安裝的iso檔,掛載為Centos8.2;利用firezilla上傳Centos8.2 ISO檔,上傳後掛載

    mount -o loop CentOS8.2.2004-x86_64-dvd1.iso /mnt





  • 建立存放Centos的安裝檔目錄

    mkdir -v /netboot/{tftp,www}/centos8



  • 複製掛載的安裝檔到剛建立的資料夾

    rsync -avz /mnt/ /netboot/www/centos8



  • 複製initrd.imgvmlinuz2個檔案到/netboot/tftp/centos8資料夾

    cp -v /netboot/www/centos8/images/pxeboot/{initrd.img,vmlinuz}

    /netboot/tftp/centos8/



  • 可以把之前掛載的資料夾卸載及刪除檔案

  • 建立pxe server設定檔

    vi /netboot/tftp/pxelinux.cfg/default

    輸入以下內容

default menu.c32

label install_centos8

menu label ^Install CentOS 8

menu default

kernel centos8/vmlinuz

append initrd=centos8/initrd.img ip=dhcp inst.repo=http://192.168.15.1/centos8/


  • 關閉防火牆

    service firewalld stop


  • 驗證pxe server








參考網址:https://linuxhint.com/pxe_network_boot_centos8/



by Johnny