文章目錄
- PXE實作無人值批量部署服務器
- 一、PXE概述
- 1.1 什么是PXE
- 1.2 什么是KickStart
- 1. 3 安裝的必要條件
- 二、PXE作業原理
- 2.1 作業原理
- 2.2 本次實驗環境
- 2.3 執行PXE+KiskStart安裝需要準備內容
- 三、安裝步驟
- 3.1 配置YUM源
- 3.2 關閉防火墻、selinux
- 3.3 安裝DHCP 、tftp(tftp-server、xinetd)
- 3.3.1 安裝dhcp、tftp-server、xinetd
- 3.3.2 配置DHCP服務
- 3.3.3 配置tftp服務
- 3.3.4 安裝syslinux,拷貝pxelinux.0檔案
- 3.4 撰寫kickstart.cfg組態檔
- 3.4.1安裝system-config-kickstart
- 3.4.2 system-config-kickstart 界面配置
- 3.5 配置 HTTP鏡像源
- 3.5.1 安裝http
- 3.5.2 將iso 鏡像檔案掛在設定開機自啟動
- 3.6 配置開機選單 default
- 3.6.1 將ks6.cfg移動到 /var/www/html/ks
- 3.6.2 配置開機選單
- 3.6.3 將客戶機 設定網路啟動(raid等),開機啟動即可
- 四、總結
PXE實作無人值批量部署服務器
一、PXE概述
1.1 什么是PXE
- PEX (Pre-Boot Execution E nvironment 預啟動執行環境),是一種引導方式,并不是一種安裝方式,
- 基于 Client/Server的作業模式
- PXE在網卡的ROM 中,當計算機引導時,BIOS把PXE Client調入記憶體執行,PXE Client 將放置在遠端的檔案通過網路下載到本地運行,
1.2 什么是KickStart
-
KickStart 是一種無人值守的安裝方式,KickStart 的作業原理是通過 記錄典型的安裝程序中記錄所需要填寫的各種引數(語言、時區、密碼、磁區、鍵盤等),并生成一個ks.cfg的檔案,(名字可以修改,默認ks.cfg)
-
在其后的安裝程序中,當出現要求填寫引數的情況時,安裝程式會首先去查找KickStart 生成的檔案,當找到合適的引數時,就采用找到的引數,當沒有找到合適的引數,就會卡著,需要人工干預,
-
如果KickStart 檔案涵蓋安裝程序中所有需要填寫的引數時,只需要告訴安裝程式從何處取得 ks.cfg檔案,安裝完畢后,安裝程式會根據ks.cfg中設定的重啟選項重啟系統,并結束安裝,
1. 3 安裝的必要條件
-
BIOS 支持PXE,需要在BIOS開啟
-
NIC 網卡支持
二、PXE作業原理
2.1 作業原理
-
拓撲圖
-

-
PXE作業原理
1.首先 PXE Client 向 DHCP 服務器發起請求分配IP(網卡需要向DHCP請求地址,獲取資訊) 2. DHCP 除了給你分配地址外,還會給你分配 boot-loader name(引導程式的名字) 以及Tftp 服務器IP地址 3.網卡使用Tftp 的客戶端,向tftp服務器發起請求,把引導程式(pxelinux.0)加載到記憶體中來 4.然后 BIOS會執行這個引導程式, 5.引導程式會 boot-loader會從tftp去查找它的組態檔(default) 6.根據組態檔來引導
2.2 本次實驗環境
-
實驗環境
主機名 網路模式 IP地址 Server 僅主機
vmware 需要關閉DHP10.0.0.100 Client 僅主機 DHCP分配
2.3 執行PXE+KiskStart安裝需要準備內容
-
DHCP 服務器 用來給客戶機分配IP
-
TFTP 服務器 用來存放PXE 的相關檔案:系統引導檔案
-
FTP|NFS|HTTP服務器 用來存放系統安裝檔案
-
KickStart所生成的ks.cfg組態檔
-
帶有一個 PXE支持網卡的 將安裝的 主機
三、安裝步驟
3.1 配置YUM源
-
YUM 源配置
[root@Server~]# cd /etc/yum.repos.d/ [root@Server/etc/yum.repos.d]# ls rivers.repo [root@Server/etc/yum.repos.d]# mv rivers.repo rivers.repo.bak [root@Server/etc/yum.repos.d]# vim dvd.repo [development] name=Centos7.6 baseurl=file:///mnt enabled=1 gpgcheck=0 [root@Server~]# mount /dev/cdrom /mnt/ mount: /dev/sr0 is write-protected, mounting read-only [root@Server~]# [root@Server~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: development Other repos take up 137 M of disk space (use --verbose for details) [root@Server~]#
3.2 關閉防火墻、selinux
-
關閉防火墻、selinux
[root@Server~]# systemctl disable firewalld --now [root@Server~]#setenforce 0 # selinux 開機才生效,setenforce 0 臨時關閉
3.3 安裝DHCP 、tftp(tftp-server、xinetd)
3.3.1 安裝dhcp、tftp-server、xinetd
-
安裝dhcp、tftp-server
[root@Server~]# yum -y install dhcp tftp-server xinetd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package dhcp.x86_64 12:4.2.5-68.el7.centos.1 will be installed ……
3.3.2 配置DHCP服務
-
配置DHCP檔案
# 1.進入 dhcp目錄 [root@Server~]# cd /etc/dhcp/ [root@Server/etc/dhcp]# ls dhclient.d dhcpd6.conf scripts dhclient-exit-hooks.d dhcpd.conf # 2.查看默認組態檔,是空的,但是/usr/share/doc/dhcp*/目錄下有配置模板,我們可以拷貝 [root@Server/etc/dhcp]# cat dhcpd.conf # # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.example # see dhcpd.conf(5) man page # [root@Server/etc/dhcp]# # 3.拷貝dhcpd 配置模板檔案 [root@Server/etc/dhcp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y # 4. 修改dhcp 檔案,(這里可以不用拷貝組態檔,直接復制下面一段,subnet--filename) # A slightly different configuration for an internal subnet. subnet 10.0.0.0 netmask 255.255.255.0 { range 10.0.0.120 10.0.0.200; option domain-name-servers 10.0.0.5, 10.0.0.6; option domain-name "example.com"; option routers 10.0.0.254; option broadcast-address 10.0.0.255; default-lease-time 600; max-lease-time 7200; next-server 10.0.0.100; filename "pxelinux.0"; } subnet 10.0.0.0 netmask 255.255.255.0 #宣告網段 range 10.0.0.120 10.0.0.200; #分配地址范圍 option domain-name-servers: #dns配置,正常公司會有2個DNS我這里隨意配的 option routers 10.0.0.254; # 設定網關的 option broadcast-address 10.0.0.255; # 設定廣播地址 default-lease-time 600; # 默認租約時間,它的單位為秒 max-lease-time 7200; #最大租約時間,它的單位為秒 next-server 10.0.0.100; # tftp-server IP地址 filename "/pxelinux.0"; # 網路啟動程式,(網路引導) # 5. 啟動dhcp 服務器, [root@Server/etc/dhcp]# systemctl enable dhcpd Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service. [root@Server/etc/dhcp]# systemctl start dhcpd [root@Server/etc/dhcp]# [root@Server/etc/dhcp]# netstat -lantup|grep :67 udp 0 0 0.0.0.0:67 0.0.0.0:* 8503/dhcpd [root@Server/etc/dhcp]# [root@Server/etc/dhcp]# cd [root@Server~]# @補充:如果全域配置了,子配置沒配置,那么將讀取全域設定 如果全域配置了,子的也配置了,那么將以自配置為準,
3.3.3 配置tftp服務
-
開啟tftp服務
# 1.修改tftp組態檔 [root@Server~]# vim /etc/xinetd.d/tftp 將 disable = no 改為 yes #重啟 xinetd [root@Server~]# systemctl restart xinetd.service [root@Server~]# netstat -lntup|grep :69 udp 0 0 0.0.0.0:69 0.0.0.0:* 9071/xinetd [root@Server~]#
3.3.4 安裝syslinux,拷貝pxelinux.0檔案
-
配置tftp-server在哪里
# 1.查找 pxelinux.0檔案是那個包提供的 [root@Server~]# yum provides "*/pxelinux.0" Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile syslinux-4.05-15.el7.x86_64 : Simple kernel loader ...: which boots from a FAT filesystem Repo : development Matched from: Filename : /usr/share/syslinux/pxelinux.0 syslinux-tftpboot-4.05-15.el7.noarch : SYSLINUX ...: modules in /var/lib/tftpboot, available for ...: network booting Repo : development Matched from: Filename : /var/lib/tftpboot/pxelinux.0 # 2.安裝syslinux包,然候拷貝pxelinux.0檔案到 tftp-server目錄 [root@Server~]# yum -y install syslinux [root@Server~]# rpm -ql syslinux|grep pxe /usr/share/doc/syslinux-4.05/pxelinux.txt /usr/share/syslinux/gpxecmd.c32 /usr/share/syslinux/gpxelinux.0 /usr/share/syslinux/gpxelinuxk.0 /usr/share/syslinux/pxechain.com /usr/share/syslinux/pxelinux.0 [root@Server~]# # 3. 拷貝pxelinux.0 檔案到 tftp-server 目錄 [root@Server~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ [root@Server/var/lib/tftpboot]# ls pxelinux.0 # 4.創建一個目錄,用來放啟動組態檔 default的 [root@Server/var/lib/tftpboot]# mkdir pxelinux.cfg [root@Server/var/lib/tftpboot]# ls pxelinux.cfg pxelinux.0 [root@Server/var/lib/tftpboot]# cd pxelinux.cfg [root@Server/var/lib/tftpboot/pxe.cfg]# pwd /var/lib/tftpboot/pxelinux.cfg # 5.將 /mnt/isolinux/目錄下面的所有檔案都考到 /var/lib/tftpboot下面 [root@Server/var/lib/tftpboot]# cd -- [root@Server~]# cd /mnt/isolinux/ [root@Server/mnt/isolinux]# cp -a isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default [root@Server/mnt/isolinux]#cp * /var/lib/tftpboot/ -
驗證
-

1.客戶端啟動系統,選擇從網卡啟動
2.就會從DHCP服務器(10.0.0.81)中獲取IP地址,同時還獲取了 tftp-server IP(10.0.0.81)地址和網路引導程式(pxelinux.0)
3.通過網卡讀取到tftp-server(/var/lib/tftpboot目錄)上的pxelinux.0,讀取到記憶體中
4.在記憶體中執行引導程式
5.讀取引導程式的組態檔(/var/lib/tftpboot/pxe.cfg/default)
3.4 撰寫kickstart.cfg組態檔
3.4.1安裝system-config-kickstart
-
安裝 system-config-kickstart
[root@Server/etc/yum.repos.d]# cd -- # 1. 安裝system-config-kickstart [root@Server~]# yum -y install system-config-kickstart 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile …… #2. 啟動界面,配置ks.cfg [root@Server~]# system-config-kickstart 詳解界面如下:
3.4.2 system-config-kickstart 界面配置
-
基本配置(默認語言、鍵盤、時區、密碼、安裝后重啟)
-

-
安裝方法(全新安裝、HTTP安裝方式)
-

-
安裝新引導裝載程式
-

-
磁區資訊
-

-

-
網路配置
-

-

-

-
防火墻配置
-

-
顯示配置(是否安裝圖形界面)
-

-
軟體包安裝選擇
-

-

-
安裝后腳本
-

-

-
保存
-

3.5 配置 HTTP鏡像源
3.5.1 安裝http
-
安裝httpd
# 1. 安裝httpd [root@Server ~]# yum -y install httpd 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile …… # 2.設定開啟自動、啟動服務 [root@Server ~]# systemctl enable httpd [root@Server ~]# systemctl start httpd #3. 創建 目錄 [root@Server ~]# cd /var/www/html [root@Server/var/www/html]# mkdir ks.cfg [root@Server/var/www/html]# mkdir pub # 4.修改yum 源,將本地改為http [root@Server/var/www/html]# cd [root@Server~]# cat /etc/yum.repos.d/dvd.repo [development] name=rhce7 baseurl=http://10.0.0.100/pub enabled=1 gpgcheck=0 [root@Server~]#
3.5.2 將iso 鏡像檔案掛在設定開機自啟動
-
設定iso開機自啟動
# 1. 在末尾添加以下一條資訊, [root@Server~]# vim /etc/fstab /dev/cdrom /var/www/html/pub iso9660 defaults,loop 0 0 [root@Server~]# tail -1 /etc/fstab /dev/cdrom /var/www/html/pub iso9660 defaults,loop 0 0 [root@Server~]# # 2.掛載鏡像 [root@Server~]# mount -a # 3.用火狐瀏覽器訪問下,如果可以訪問,則說明http 鏡像源沒有問題 [root@Server~]# firefox http://10.0.0.100/pub & @ 7版本上,模式可以識別loop,defaults,loop 后面的loop可以省略
3.6 配置開機選單 default
3.6.1 將ks6.cfg移動到 /var/www/html/ks
-
移動ks6.cfg
# 1.將我們保存在root目錄中的cfg移動到 /var/www/html/ks.cfg/ [root@Server~]# mv ks6.cfg /var/www/html/ks.cfg/ [root@Server/var/www/html/ks.cfg]# ls ks6.cfg [root@Server/var/www/html/ks.cfg]#
3.6.2 配置開機選單
-
撰寫defautl檔案
[root@Server~]# cd /var/lib/tftpboot/pxelinux.cfg/ [root@Server/var/lib/tftpboot/pxelinux.cfg]# ls default # 1.撰寫default檔案,此時在原本的label linux 添加以下內容, # 并洗掉label check里面的 menu defalut(默認啟動方式,設定了,就不需要選擇,默認啟動選項) [root@Server/var/lib/tftpboot/pxelinux.cfg]# vim default label rhce7 menu label ^Install rhce7 menu default kernel vmlinuz append initrd=initrd.img ks=http://10.0.0.100/ks.cfg/ks6.cfg # 2.可以修改下默認的時間,默認是 600(單位是600秒的十分之一,就是60s) # 這里我設定60,就是6s timeout 60 ------------------- 引數介紹 efault vesamenu.c32 # 這是必須項,或者使用menu.c32 timeout 60 # 超時等待時間,60秒內不操作將自動選擇默認的選單來加載 display boot.msg # 這是為選項提供一些說明的檔案 # Clear the screen when exiting the menu, instead of leaving the menu displayed. # For vesamenu, this means the graphical background is still displayed without # the menu itself for as long as the screen remains in graphics mode. menu clear menu background splash.png # 背景圖片 menu title CentOS 7 # 大標題 menu vshift 8 …… label linux menu label ^Install CentOS 7 # 選單文字 kernel vmlinuz # 內核檔案路徑,注意相對路徑是從tftp的根路徑/tftpboot開始的 append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet # 內核啟動選項,其中包括initrd的路徑,同樣要改為"ks=http://10.0.0.100/ks.cfg/ks6.cfg" menu default # menu default表示開機時游標一開始默認停留在此label上 # 一般pxe環境下此路徑直接指向系統安裝檔案的路徑,具體做法見下文示例 # utilities submenu # 子選單項的設定方法 menu begin ^Troubleshooting menu title Troubleshooting
3.6.3 將客戶機 設定網路啟動(raid等),開機啟動即可
四、總結
所謂的無人值守,就是自動應答,當安裝程序中需要人機互動提供某些選項的答案時(如如何磁區),自動應答檔案可以根據對應項自動提供答案,但是,無人值守并不完全是無人值守,至少設定bios從網卡啟動是必須人為設定的,且安裝完系統后設定不從網卡啟動也是需要人為設定的,除此之外,其他的基本上都可以實作無人值守安裝,
在部署時,建議使用 Kickstart+DHCP+HTTP(FTP)+TFTP,安裝dhcp、tftp-server、xinetd、httpd、system-config-kickstart等軟體,
在真實環境中,通常我們會發現一臺服務器好幾塊硬碟,做完raid,整個硬碟有等10T,如果來使用kickstart自動安裝并磁區呢;一般服務器硬碟超過2T,如何來使用kickstart安裝配置呢?這里就不能使用MBR方式來磁區,需要采用GPT格式來引導并磁區,需要在ks.cfg末尾添加如下命令來實作需求:
%pre
parted -s /dev/sdb mklabel gpt
%end
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/356865.html
標籤:其他




