PXE+KickStart 全自動化部署
PXE 簡介
-
PXE (preboot execute environment ,預啓動執行環境)工作於 Client/Server 的網絡模式,支持工作站通過網絡從遠端服務器下載映像,並由此支持通過網絡啓動操作系統,
-
進行 PXE 安裝的必要條件是要安裝的計算機中包含一個 PXE 支持的網卡(NIC),即網卡中必須要有 PXE Client。PXE 協議使計算機可以通過網絡啓動。
-
協議分爲 client 和 server 端,PXE client 在網卡的 ROM 中,當計算機引導時,BIOS 把 PXE client 調入內存執行,由 PXE client 將放置在遠端的文件通過網絡下載到本地運行。
-
運行 PXE 協議需要設置 DHCP 服務器和 TFTP 服務器。
DHCP 服務器用來給 PXE client(將要安裝系統的主機)分配一個 IP 地址,由於是給 PXE client 分配 IP 地址,所以在配置 DHCP 服務器時需要增加相應的 PXE 設置。(bootp booting等選項) -
此外,在 PXE client 的 ROM 中,已經集合了 TFTP Client。PXE Client 通過 TFTP 協議就可以 到 TFTP Server 上下載網絡引導 所需的文件
工作過程
1)、PXE Client 從自己的PXE網卡啓動,向本網絡中的DHCP服務器索取IP;
2)、DHCP 服務器返回分配給客戶機的 IP 以及PXE文件的放置位置(該文件一般是放在一臺TFTP服務器上) ;
3)、PXE Client 向本網絡中的TFTP服務器索取pxelinux.0 文件;
4)、PXE Client 取得pxelinux.0 文件後之執行該文件;
5)、根據pxelinux.0 的執行結果,通過TFTP服務器加載內核和文件系統 ;
6)、進入安裝畫面, 此時可以通過選擇HTTP、FTP、NFS 方式之一進行安裝;
Kickstart 的概述
-
Kickstart是一種無人值守的安裝方式。它的工作原理是在安裝過程中記錄典型的需要人工干預填寫的各種參數,並生成一個名爲ks.cfg的文件。如果在安裝過程中(不只侷限於生成Kickstart安裝文件的機器)出現要填寫參數的情況,安裝程序首先會去查找Kickstart生成的文件,如果找到合適的參數,就採用所找到的參數;如果沒有找到合適的參數,便需要安裝者手工干預了。所以,如果Kickstart文件涵蓋了安裝過程中可能出現的所有需要填寫的參數,那麼安裝者完全可以只告訴安裝程序從何處取ks.cfg文件,然後就去忙自己的事情。等安裝完畢,安裝程序會根據ks.cfg中的設置重啓系統,並結束安裝。
-
目的是爲了 減少系統安裝的過程中的人機交互,提高安裝效率
實現部署的環境要求
1、客戶端可以是裸機,客戶端和服務器,必須處於同一 廣播域
2、客戶端的網卡,必須擁有 PXE ROM (preboot execution Enviroment)芯片,遠程引導技術。(一般有)
3、客戶端的 BIOS 開啓網絡啓動功能,並將網絡引導作爲首選啓動項。
使用一臺服務器搭建,實現全自動化部署
dhcp + tftp + syslinux + NFS + kickstart
一、配置 dhcp 服務器
[root@rehl-14 ~]# yum install -y dhcp #安裝dhcp服務
[root@rehl-14 ~]# vim /etc/dhcpd/dhcpd.conf #修改dhcp配置
ddns-update-style interim;
ignore client-updates;
subnet 192.168.10.0 netmask 255.255.255.0 {
option routers 192.168.10.2;
option subnet-mask 255.255.255.0;
option domain-name "gz.com";
option domain-name-servers 202.96.128.166;
range dynamic-bootp 192.168.10.20 192.168.10.30;
default-lease-time 21600;
max-lease-time 43200;
allow bootp;
allow booting;
next-server 192.168.10.14;
filename "pxelinux.0"; ##不要寫路徑,只需要寫文件名稱即可
}
[root@rehl-14 ~]# service dhcpd start #啓動服務
二、安裝 tftp服務
[root@rehl-14 ~]# yum install -y tftp tftp-server #安裝tftp服務
[root@rehl-14 ~]# systemctl start tftp #啓動tftp服務
三、安裝 syslinux 提供引導文件 pxelinux.0 和菜單
1、提供的 pxelinux.0 複製到 tftp 工作目錄 /var/lib/tftpboot/ 下
[root@rehl-14 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
2、拷貝各個版本啓動所需的文件內核以及鏡像文件
[root@rehl-14 ~]# cp /iso/isolinux/vmlinuz /var/lib/tftpboot/rhel7-vmlinuz
[root@rehl-14 ~]# cp /iso/isolinux/initrd.img /var/lib/tftpboot/rhel7-initrd.img
3、創建 pxelinux 的配置文件, 已經啓動歡迎信息文件
**注意:**rhel7-vmlinuz 內核的命名 和 rhel7-initrd.img 引導啓動程序命名必須要和引導配置文件的命名一樣;否則會找不到內核和啓動程序導致引導失敗無法安裝 …
[root@rehl-14 tftpboot]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@rehl-14 tftpboot]# vim /var/lib/tftpboot/pxelinux.cfg/default
default 1
timeout 600
display boot.msg
prompt 1
label 1
kernel rhel7-vmlinuz
append initrd=rhel7-initrd.img method=nfs://192.168.10.14/iso
label 2
kernel centos7-vmlinuz
append initrd=centos7-initrd.img method=nfs://192.168.10.73/iso
4、創建並編輯 boot.msg 歡迎界面(自定義編輯)
[root@rehl-14 ~]# vim /var/lib/tftpboot/boot.msg
#############################################################
# WELCOME #
# please select the system you want to install #
# #
# ----1-To Install RHEL7.4 Press Enter ------- #
# #
# ----2-To Install CentOS7.4 Type 2 And Press Enter ------ #
# #
# ----3-To Install CentOS6 Type 3 And Press Enter ------ #
# #
#############################################################
5、檢查, /var/lib/tftpboot 目錄
檢查是否存在如下文件
[root@rehl-14 tftpboot]# ls
boot.msg pxelinux.0 pxelinux.cfg rhel7-initrd.img rhel7-vmlinuz
四、配置好NFS 服務器
[root@rehl-14 ~]# yum install -y nfs-utils rpcbind
[root@rehl-14 ~]# vim /etc/exports
/iso 192.168.10.0/255.255.255.0(ro)
[root@rehl-14 ~]# exportfs -rv #直接生效
五、安裝 kickstart (確保有圖形安裝界面)
[root@rehl-14 ~]# yum install -y system-config-kickstart
[root@rehl-14 ~]# system-config-kickstart #啓動Kickstart
對配置程序進行修改
保存生成對應的腳本配置文件(可自定義命名後,但綴必須是 .cfg)
如果沒有圖形化界面,那就引用圖形化界面操作生成的腳本配置文件。配置模板 ks.cfg
[root@rehl-14 ~]# vim /root/ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$R3/f9TQa$Zm8fEGCP55jeEPXBsk7bg. ##密碼123123
# System language
lang zh_CN
# Firewall configuration
firewall --disabled
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Use NFS installation media
nfs --server=192.168.10.12 --dir=iso
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part / --asprimary --fstype="ext4" --size=10240
part /data --fstype="ext4" --grow --size=1
%packages
@base
@core
wget
tree
psmisc
vsftpd
%end
修改配置文件 /var/lib/tftboot/pxelinux.cfg/defautl
[root@rehl-14 ~]# vim /var/lib/tftboot/pxelinux.cfg/defautl
......
abel 1
kernel vmlinuz7-4
append initrd=initrd7-4.img method=nfs://192.168.10.14/iso ks=http://192.168.10.14/ks.cfg
......
六、啓動測試機進行自動化部署安裝
在 VMware 上添加新的虛擬機進行安裝測試
選擇 1,回車確認,接下來就是等待他自個完成就行
安裝完成後會來到這個界面,那表示已經安裝成功了