網絡裝機pxe服務器的配置過程


網絡裝機pxe服務器的配置過程

背景:

  針對於Linux運維工作中遇到的需要大批量安裝Linux系統的情況,通過網絡裝機的方式實現無人值守安裝Linux操作系統,現需要配置一台pxe服務器用於pxe批量安裝Linux操作系統,本次以Centos7為例。只要將這台配置好了的服務器合同其他需要安裝Linux系統的客戶機連接在同一個局域網中,就可以通過網絡來進行Linux系統的安裝。這台服務器需要提供DHCP服務和tfpt服務以及http服務,DHCP服務主要是為了給客戶機提供IP地址,而tftp服務主要是為了提供安裝系統所需要的引導文件,而HTTP服務則是提供安裝系統的軟件包。缺一不可。

一、准備條件

1.1、關閉防火牆和selinux。

  關閉防火牆命令:

1 [root@localhost ~]# systemctl stop firewalld.service 
2 [root@localhost ~]# systemctl disable firewalld.service 
3 Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
4 Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
5 [root@localhost ~]# 

 

  關閉selinux命令:將/etc/selinux/config中的SELINUX的值修改為“disabled”。重啟生效。重啟命令:reboot

  驗證selinux是否關閉,命令:getenforce

1 [root@localhost ~]# 
2 [root@localhost ~]# getenforce
3 Disabled
4 [root@localhost ~]# 

1.2、掛載Centos7的光盤鏡像

  實驗是在虛擬機上做的。掛載前需要將虛擬機的光驅和實際的Centos7的光盤鏡像連接起來,這里不做介紹。

  掛載Centos7光盤鏡像

  掛載命令:

 

1 [root@localhost /]# mkdir /var/www/html/Centos7
2 [root@localhost /]# ls /var/www/html/
3 Centos7
4 [root@localhost /]# mount /dev/sr0 /var/www/html/Centos7/
5 mount: /dev/sr0 is write-protected, mounting read-only

 

1.3、安裝DHCP、tftp、http服務

命令:

1 [root@localhost yum.repos.d]# yum -y install dhcp
2 [root@localhost yum.repos.d]# yum -y install httpd
3 [root@localhost yum.repos.d]# yum -y install xinetd
4 [root@localhost yum.repos.d]# yum -y install tftp-server
5 [root@localhost yum.repos.d]# 

查看是否安裝http、tftp、dhcp等服務。

二、修改配置文件

2.1、修改dhcp服務的配置文件/etc/dhcp/dhcpd.conf

導入dhcp模板文件的配置內容。

修改配置文件。

2.2、修改tftp服務的配置文件/etc/xinetd/tftp,啟用tftp功能。默認tftp是關閉的。

 

三、http搭建yum源

  用於提供軟件包的訪問地址。

啟用http服務。配置http服務開機啟動。

 命令:

1 [root@localhost etc]# systemctl restart httpd
2 [root@localhost etc]# systemctl enable httpd
3 Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
4 [root@localhost etc]# 

創建yum客戶端位置文件。在/etc/yum.repos.d/下創建yck.repo文件,這個文件的名字隨便取,但是需要以.repo結尾。

檢查yum是否配置成功。

四、提取光盤鏡像中的引導文件和其他系統必須的文件

將光盤鏡像中的initrd.img、splash.png、vesamenu.c32、vmlinuz拷貝到tftp服務默認的共享目錄/var/lib/tftpboot/中。

命令:

1 [root@localhost yum.repos.d]# cp -a /var/www/html/Centos7/isolinux/initrd.img /var/www/html/Centos7/isolinux/vmlinuz /var/lib/tftpboot/
2 [root@localhost yum.repos.d]# cp -a /var/www/html/Centos7/isolinux/splash.png /var/www/html/Centos7/isolinux/vesamenu.c32 /var/lib/tftpboot/
3 [root@localhost yum.repos.d]# 

在/var/lib/tftpboot/創建目錄pxelinux.cfg,並把光盤鏡像中的isolinux.cfg拷貝到pxelinux.cfg目錄下並命名為default。

命令:

1 [root@localhost yum.repos.d]# mkdir /var/lib/tftpboot/pxelinux.cfg
2 [root@localhost yum.repos.d]# cp -a /var/www/html/Centos7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
3 [root@localhost yum.repos.d]# ls /var/lib/tftpboot/pxelinux.cfg/
4 default
5 [root@localhost yum.repos.d]# 

獲取pxelinux.0文件,pxelinux.0是由syslinux包提供的,所以要先安裝syslinux。然后再找pxelinux.0文件。

1 [root@localhost yum.repos.d]# yum -y install syslinux
2 [root@localhost yum.repos.d]# find / -name "pxelinux.0"
3 /usr/share/syslinux/pxelinux.0
4 [root@localhost yum.repos.d]# 

把pxelinux.0文件拷貝到/var/lib/tftpboot/下。

修改/var/lib/tftpboot/pxelinux.cfg/default文件。

修改內容。

 

六、生成自動應答文件ks.cfg.並將應答文件放在/var/www/html/下。

安裝system-config-kickstart軟件包。通過命令system-config-kickstart開始配置自動應答文件,這個過程是全圖形操作。

命令:

1 system-config-kickstart

 

 

 

 

 如果軟件包選擇項看不到任何軟件包。

也可自定義腳本如下,根據自己的想法去寫腳本。

將ks.cfg文件放在/var/www/html/下。

七、啟動tftp服務、dhcp服務。確認dhcp、tftp、http服務是否正在運行。

八、新創建一個虛擬機,將新的虛擬機網卡設置為橋接模式,復制主機的網絡狀態。開機從網卡啟動,開始裝機。

 新建虛擬機就不多介紹了。內存設為2G。太小可能導致系統安裝失敗。

新的虛擬機開機按F12.從網卡啟動。

按回車鍵后,開始安裝。

開始加載文件了,之后的暗賬過程都是無人值守的。

系統安裝完成。





 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

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



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