配置和使用PEX自動化安裝centos 7 修訂版

安裝及配置流程:
1. 安裝前的準備工作
2. 配置 DHCP 服務
3. 配置 TFTP 服務
4. 配置http做文件倉庫和修改ks.cfg文件
5. 相關係統引導文件存儲
6. 配置default系統啓動文件
7. 檢查PXEServer的狀態並啓動PXE Client


安裝環境:
一臺已安裝Linux系統的主機作爲PXE Server, 本文中PXE Server使用的系統是CentOS 7;
若干臺待安裝CentOS7的裸主機作爲PXE Client;
PXE Server與所有PXEClient處於同一局域網中;
所有主機支持PXE啓動安裝方式。
PXEServer安裝及配置具體步驟:
1.安裝前的準備
關閉防火牆和SEINUX ,DHCP靜態服務器IP
2. 配置DHCP服務
安裝DHCP
# yum install -y dhcp
當前PXE Server的IP地址爲192.168.52.132,DHCP、TFTP與http均部署在該臺主機上,配置dhcp配置文件/etc/dhcp/dhcpd.conf如下
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
ddns-update-style interim;
ignore client-updates;
allow booting;
allow bootp;
class “pxeclients”{
match if substring(option vendor-class-identifier,0,9)=”PXEClient”;
filename “pxelinux.0”;#pxe boot需要的啓動文件名, 相當於bootloader
next-server 192.168.52.132; #tftp server的ip
}
subnet 192.168.52.0 netmask 255.255.255.0{
default-lease-time 216000;
max-lease-time 432000;
option time-offset -18000;
range dynamic-bootp 192.168.52.150 192.168.52.160;#地址池範圍
option subnet-mask 255.255.255.0;
option routers 192.168.52.1;
}
啓動並且配置開機啓動dhcpd服務
# systemctl start dhcpd
# systemctl enable dhcpd
3. 配置TFTP服務
安裝tftp的server和client包
# yum install -y tftp*
安裝xinetd守護進程,因爲tftp依賴於xinetd
# yum install -y xinetd
修改tftp配置文件/etc/xinetd.d/tftp,將disable= yes改爲disable=no
# default: off
# description: The tftp server serves filesusing the trivial file transfer
# protocol. The tftp protocol isoften used to boot diskless
# workstations, download configuration files to network-aware printers,
# and to start the installation process for some operating systems.
servicetftp
{
socket_type =dgram
protocol =udp
wait =yes
user =root
server =/usr/sbin/in.tftpd
server_args =-s/var/lib/tftpboot
disable = on
per_source =11
cps =1002
flags =IPv4
}
關閉並配置開機自動關閉系統防火牆(重要!否則會導致PXE Client無法訪問TFPT服務)
# systemctl stop firewalld
# systemctl disable firewalld
啓動並配置開機自動啓動xinetd進程
# systemctl start xinetd
# systemctl enable xinetd
# systemctl start tftp
4. 配置http做文件倉庫和修改ks.cfg文件
安裝httpd服務
# yum install –y httpd
啓動並且配置開機啓動httpd服務
# systemctl start httpd
# systemctl enable httpd
放入待安裝系統盤,並直接用光盤的package當做安裝倉庫
# mkdir /var/www/html/centos7  
#mount /dev/sr0 /var/www/html/centos7
cp /run/media/pex/CentOS\ 7\ x86_64* /var/www/html/centos7 -r
將當前系統中的ks文件拷貝到/var/www/html/路徑下

# cp /root/anaconda-ks.cfg /var/www/html/ks.cfg

chmod +r /var/www/html/ks.cfg  

修改ks.cfg配置文件/var/www/html/ks.cfg

ks.cfg的作用是預先指定好需要的安裝選項(包括系統鏡像路徑,安裝組件,系統語言,網絡配置,用戶及密碼等),當正式安裝時PXE Client將會很據該文件去自動配置安裝,從而避免了大規模部署時的大量重複操作。

主要修改的地方是將
# Use CDROM installation media
cdrom
修改爲
# Use network installation
url –url=http://192.168.52.132/centos7
從而指定PXE Client從哪裏去獲得鏡像文件,ks.cfg文件修改後如下,
#version=DEVEL
# System authorization information
auth –enableshadow –passalgo=sha512
# Use network installation
url –url=”http://192.168.52.132/centos7″
# Use graphical install
graphical
# Run the Setup Agent on first boot
firstboot –enable
# Keyboard layouts
keyboard –vckeymap=cn –xlayouts=’cn’
# System language
lang zh_CN.UTF-8
# Network information
network –bootproto=dhcp–device=eno16777736 –ipv6=auto –activate
network –hostname=localhost.localdomain
# Root password
rootpw –iscrypted$6$qUeqvWWOr921mWBY$h5wjwdcnIOC/FS6rCaZblKNGELwN9jrGwJZuwlrNi9OHzI.n1lxaKKrkwdN7nadXP5f2mFRDrW9D9gYStXGZu/
# System timezone
timezone Asia/Shanghai –isUtc
user –groups=wheel –name=pxetest–password=$6$.hgpJdCAhSMaf7yB$5GKYIAgTkLxfS1JHK5KSpN96LXhkKGFX3FbnQl0hTME3wbF1njxyezmPF/HXAtI9Bp8U6MsF3hRXlFvFfn9Nm/–iscrypted –gecos=”pxetest”
# System bootloader configuration
bootloader –append=” crashkernel=auto”–location=mbr –boot-drive=sda
autopart –type=lvm
# Partition clearing information
clearpart –none –initlabel
%packages
@^infrastructure-server-environment
@base
@compat-libraries
@core
@debugging
@development
@dns-server
@file-server
@ftp-server
@security-tools
@smart-card
kexec-tools
%end
%addon com_redhat_kdump –enable–reserve-mb=’auto’
%end
關於ks.cfg的詳細介紹及配置見另一篇文章《PXE配置中ks.cfg文件介紹》
5. 相關係統引導文件存儲
安裝syslinux,它是一個功能強大的引導加載程序,而且兼容各種介質。
# yum install -y syslinux
pxelinux.0文件名要和dhcp配置文件內的一致
# cp /usr/share/syslinux/pxelinux.0  /var/lib/tftpboot/
copy光盤目錄中的vmlinuz和initrd.img,這兩個文件相當於系統啓動時/boot目錄下的啓動文件,這個用來引導anacoda而不是根
# cp /mnt/cdrom/images/pxeboot/{vmlinuz,initrd.img} /
/var/lib/tftpboot/
copy pxe引導所需要的配置文件,splash.png:背景圖.boot.msg啓動標語,vesamenu.c32:顯示同行界面用的程序.
# cp /mnt/cdrom/isolinux/{boot.msg,vesamenu.c32,splash.png}/
/var/lib/tftpboot/
pxe啓動時顯示配置文件信息,和光盤啓動類似.
# mkdir/var/lib/tftpboot/pxelinux.cfg
# cp/mnt/cdrom/isolinux/isolinux.cfg/
/var/lib/tftpboot/pxelinux.cfg/default
6. 配置default系統啓動文件
在default配置文件/var/lib/tftpboot/pxelinux.cfg/default中找到下面標籤
label linux
menu label^Install CentOS 7
kernel vmlinuz
menu default
appendinitrd=initrd.img 
repo=http://192.168.52.132/centos7
inst.stage2=http://192.168.52.132/centos7/
inst.ks=http://192.168.52.132/ks.cfg quiet
注意標紅的地方,它的目的是用於告訴PXEClient去哪裏可以找到鏡像文件以及ks.cfg配置文件。
7. 檢查PXE Server的狀態並啓動PXE Client
# service dhcpd status
# service tftp status
# service httpd status
以上三者結果都應該爲active(running)
# service firewalld status
結果都應該爲inactive(dead)
檢查待安裝系統盤是否以及掛載或者拷貝到指定目錄下(/var/www/html/centos7/)
如果以上狀態均正常,可以開始啓動PXEClient,並將啓動方式設置爲網卡啓動。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章