看過好多人使用pxe無人值守的文檔,寫的總歸缺少一些東西,通過自己的使用以及結合各位運維人員的文檔,寫一篇比較初級的pxe的部署,适合剛入門的菜鳥使用。
實驗環境:cnetos6.6 ip:192.168.153.2
1.安裝軟體
[root@pxe-server~]# yum -y install dhcp tftp-server httpd syslinux
2.dhcp
[root@pxe-server~]# cp -rf /usr/share/doc/dhcp*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
cp:是否覆寫"/etc/dhcp/dhcpd.conf"? y
[root@pxe-server~]# vim /etc/dhcp/dhcpd.conf
添加以下:
ddns-update-style interim; #設定dhcp伺服器模式
ignore client-updates; #禁止用戶端更新
allow booting; #定義能夠pxe啟動
allow bootp; #定義支援bootp
subnet 192.168.153.0 netmask 255.255.255.0 { #設定網段
option routers 192.168.153.1 ;
option subnet-mask 255.255.255.0; #設定掩碼子網
range dynamic-bootp 192.168.153.50 192.168.153.100; #設定dhcp伺服器ip位址租用的範圍,dynamic-bootp代表該dhcp伺服器支援pxe
default-lease-time 64600; #預設租約時間
max-lease-time 43200; #最大租約時間
next-server 192.168.153.2; #tftp伺服器位址
filename "pxelinux.0"; #最基本的啟動檔案。指向的是tftp-sever的根目錄
}
[root@pxe-server~]# service dhcpd restart
[root@pxe-server~]# chkconfig dhcpd on
3.tftp
(1).pxelinux.0
[root@pxe-server~]# find / -name pxelinux.0
/usr/share/syslinux/pxelinux.0
[root@pxe-server~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
(2).提供引導菜單所需的檔案(從系統CD光牒上的isolinux目錄中找)
[root@pxe-server~]# cp -rf /media/centos_6.6_final/isolinux/* /var/lib/tftpboot/ (/media/centos_6.6_final是系統CD光牒挂載點)
[root@pxe-server~]# mkdir /var/lib/tftpboot/pxelinux.cfg
複制isolinux.cfg到pxelinux.cfg下并改名為default:
[root@pxe-server~]# cd /var/lib/tftpboot/
[root@pxe-server tftpboot]# cp isolinux.cfg pxelinux.cfg/default
(3).編輯啟動菜單
[root@pxe-server~]# vim pxelinux.cfg/default
default vesamenu.c32
#prompt 1
timeout 20 #系統選擇安裝時的時間,預設是600(60秒),為了減少等待時間改為2秒
...
label linux
menu label ^install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://192.168.153.2/ks.cfg #指定ks的路徑,本機位址
...
(4).修改tftp-server的配置檔案
[root@pxe-server~]# vim /etc/xinetd.d/tftp
...
disable = no #yes改為no
[root@pxe-server~]# service xinetd restart
[root@pxe-server~]# netstat -an|grep :69
出現以下資訊代表已經啟動:
udp 0 0 0.0.0.0:69 0.0.0.0:*
4.通過ftp|httpd|nfs提供安裝樹(以httpd為例)
在http的根目錄中建立目錄,用于挂載系統鏡像檔案
[root@pxe-server~]# mkdir /var/www/html/centos6.6
[root@pxe-server~]# mount /dev/cdrom /var/www/html/centos6.6
[root@pxe-server~]# service httpd restart
[root@pxe-server~]# chkoconfig httpd on
5.通過kickstart實作自動安裝
把整個安裝過程中要回答或者要做的事全部展現在應答檔案中。
建立ks.cfg檔案
[root@pxe-server~]# yum install -y system-config-kickstart
[root@pxe-server~]# system-config-kickstart
ks.cfg預覽如下:
#platform=x86, amd64, 或 intel em64t
#version=devel
# firewall configuration
firewall --disabled
# install os instead of upgrade
install
# use network installation
url --url="http://192.168.153.2/centos6.6"
# root password
rootpw --iscrypted $1$m7iicv7p$udxtdpf4oxxrqd2pi1o5t/
# system authorization information
auth --useshadow --passalgo=sha512
# use graphical install
graphical
firstboot --disable
# system keyboard
keyboard us
# system language
lang en_us
# selinux configuration
selinux --disabled
# installation logging level
logging --level=info
# reboot after installation
reboot
# system timezone
timezone asia/shanghai
# network information
network --bootproto=dhcp --device=eth0 --onboot=on
# system bootloader configuration
bootloader --location=mbr
# clear the master boot record
zerombr
# partition clearing information
clearpart --all --initlabel
# disk partitioning information
part / --fstype="ext4" --size=15350
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=2048
part /var --fstype="ext4" --grow --size=1
%packages
@base
@basic-desktop
@desktop-debugging
@desktop-platform
@fonts
@general-desktop
@graphical-admin-tools
@input-methods
@internet-applications
@legacy-x
@print-client
@remote-desktop-clients
@x11
%end
可以直接使用ks.cfg,根據自己需求修改防火牆,url,分區資訊(紅色标記的地方,注:root密碼是passw0rd)
需要注意的是,如上操作是在實驗環境中,生産環境中伺服器網卡是em(x)的,需要修改部分如下:
[root@pxe-server~]# vim /var/lib/tftpboot/pxelinux.cfg/default
append initrd=initrd.img ks=http://192.168.153.2/ks.cfg ksdrive=em1 #指定網卡
[root@pxe-server~]# vim /var/www/html/ks.cfg
network --bootproto=dhcp --device=em1 --onboot=on
測試:用戶端開機即可
如果是新的伺服器,建議使用pxe自動安裝,可以保證初始系統的相同。