做集群測試,最基礎也最耗時的一步永遠是裝系統。靠十幾台光驅並排安裝的日子已經過去,有了 PXE,一兩天搭好一個叢集並非夢想。做久了會發現,運維的門檻不在技術而在效率,而 PXE 正好是把效率拉滿的那把工具。以下記錄完整搭建過程。
關閉防火牆
service iptables stop service ip6tables stop chkconfig iptables off chkconfig ip6tables off
關閉 SELinux
setenforce 0 # 臨時關閉,重開機失效 # 永久關閉:/etc/selinux/config 中設為 disabled
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf chkconfig dhcpd on service dhcpd start ss -nul # 看到 67 埠被監聽即成功
修改 dhcpd.conf 時,記得指定要分發的網段、租約時間與 next-server(指向 TFTP 伺服器)。DNS 這裡可以省略。
TFTP 是瞬時服務進程,無法自我管理,必須透過超級服務進程 xinetd 託管,因此安裝 tftp-server 時會一併拉進 xinetd 相依。
chkconfig xinetd on service xinetd start chkconfig --list xinetd ss -nul # 69 埠被監聽即成功 # 若系統沒有 tftp: yum -y install tftp tftp-server
編輯
/etc/xinetd.d/tftp,把
disable = yes改成
disable = no,然後驗證:
# 建立測試檔 echo test > /var/lib/tftpboot/test.txt # 在本機測試 tftp 192.168.1.205 tftp> get test.txt tftp> quit
根目錄下出現 test.txt 即代表成功,測試完記得刪除。
mkdir /nfsroot echo '/nfsroot *(rw,wdelay,crossmnt,insecure,root_squash,no_subtree_check,fsid=0)' >> /etc/exports exportfs -a chkconfig rpcbind on && service rpcbind start chkconfig nfs on && service nfs start
mount -o loop /opt/rhel6.5.iso /mnt
在
/etc/yum.repos.d/建立
rhel65.repo:
[rhel65] name=rhel65 baseurl=file:///mnt enabled=1 gpgcheck=0
yum clean all # 刷新快取
常用指令:
yum install package1 # 安裝 yum groupinstall group1 # 安裝程式組 yum update package1 # 更新 yum check-update # 檢查可更新項目 yum upgrade package1 # 升級 yum groupupdate group1 # 升級程式組 yum info package1 # 檢視資訊 yum list # 列出已安裝與可安裝的套件 yum remove package1 # 移除 yum groupremove group1 # 移除程式組
先確定本地 yum 源可用,再執行
system-config-kickstart開啟圖形化製作介面。
Basic Configuration:設定主機名、時區與 root 密碼。
Installation Method:選 NFS,NFS Server 填伺服器 IP,NFS Directory 填
/nfsroot。
Boot Loader Options:保持預設。分区:使用 sda,
/boot給 200M,
/吃掉剩餘空間。
Network:eth0 設為 DHCP。
Firewall:關閉防火牆與 SELinux。
Package Selection 若看不到套件清單,回頭確認本地源是否生效。Pre/Post Script 保持預設,最後 File → Save 存成
/opt/ks.cfg。
# 1. 複製 PXE 引導程式 cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ # 2. 複製開機核心與 initrd
# 3. 複製開機選單所需檔案
cp /mnt/isolinux/{boot.msg,splash.jpg,vesamenu.c32} /var/lib/tftpboot/
# 4. 複製並改名為 default,用來引導客戶端 cp /mnt/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
接著修改
/var/lib/tftpboot/pxelinux.cfg/default,把 ks 檔的載入位置指到 NFS 上的
/ks.cfg。
# 5. 把 images 目錄與 ISO 放進 NFS 分享目錄 cp -r /mnt/images /nfsroot/ cp /opt/rhel6.5.iso /nfsroot/
這樣一來,客戶端開機 → DHCP 取址 → TFTP 抓 pxelinux.0 與核心 → NFS 掛載套件來源 → 依 ks.cfg 自動完成分區與安裝,全程不用人盯著。小補充:裝完重開機後,可用
gdm指令切換桌面環境。