PXE(preboot execute environment,預啟動執行環境)可通過CS網絡模式,實作無盤作業系統安裝;其工作原理如下:當計算機引導時,BIOS把 PXE Client 調入記憶體中執行,然後由 PXE Client 将放置在遠端的檔案通過網絡下載下傳到本地運作;效率是有盤情況下的3倍。下面我們通過vmware虛拟機搭建一個PXE環境
環境:
Server: RHEL7.4 x86_64(192.168.101.130)
vmware:vmware workstation 14 pro
DHCP:range 192.168.101.140~192.168.101.150
提示:
為了vmware更好的實作DHCP動态位址擷取,我們需要關閉vmware自身的DHCP服務,僅開啟NAT模式;具體方法為:【編輯】--->【虛拟網絡編輯器】,選中【nat模式】--->【更改配置】,去掉【使用本地DHCP服務将IP位址配置設定給虛拟機】前面的√即可,【應用】或者【确定】之後便可。
搭建DHCP服務
1、yum安裝DHCPD
[[email protected] ~]# yum install -y dhcp
2、DHCPD配置
[[email protected] ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
/* 因為yum安裝的DHCP是不提供配置檔案的,需要複制一個模闆并重命名後使用
[[email protected] ~]# vim /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
# option definitions common to all supported networks…
option domain-name “example.org”; /*全局變量,域名
option domain-name-servers ns1.example.org, ns2.example.org;
default-lease-time 600; /*全局變量,預設的租約時長(1/10s)
max-lease-time 7200; /*全局變量,最大的租約時長
# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;
# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
# This is a very basic subnet declaration.
subnet 192.168.101.0 netmask 255.255.255.0 {
range 192.168.101.160 192.168.101.170;
option routers 192.168.101.2;
option broadcast-address 192.168.101.255;
next-server 192.168.101.130;
filename “pxelinux.0”;
}
3、啟動服務
[[email protected] ~]# systemctl start dhcpd.service /*啟動DHCPD服務
[[email protected] ~]# systemctl enable dhcpd.service /*加入開機自啟動
安裝syslinux
1、安裝
[[email protected] ~]# yum install -y syslinux
2、RHEL7環境下所需的檔案如下:menu.c32、memdisk、pxelinux.0、chain.c32
[[email protected] tftpboot]# cd /usr/share/syslinux/
[[email protected] syslinux]# ls
altmbr.bin diag gptmbr_f.bin int18.com kbdmap.c32 memdump.com reboot.c32 vesainfo.c32
altmbr_c.bin disk.c32 gpxecmd.c32 isohdpfx.bin linux.c32 meminfo.c32 rosh.c32 vesamenu.c32
altmbr_f.bin dmitest.c32 gpxelinux.0 isohdpfx_c.bin ls.c32 menu.c32 sanboot.c32 vpdtest.c32
cat.c32 dosutil gpxelinuxk.0 isohdpfx_f.bin lua.c32 pcitest.c32 sdi.c32 whichsys.c32
chain.c32 elf.c32 hdt.c32 isohdppx.bin mboot.c32 pmload.c32 sysdump.c32 zzjson.c32
cmd.c32 ethersel.c32 host.c32 isohdppx_c.bin mbr.bin poweroff.com syslinux64.exe
config.c32 gfxboot.c32 ifcpu64.c32 isohdppx_f.bin mbr_c.bin pwd.c32 syslinux.com
cpuid.c32 gptmbr.bin ifcpu.c32 isolinux.bin mbr_f.bin pxechain.com syslinux.exe
cpuidtest.c32 gptmbr_c.bin ifplop.c32 isolinux-debug.bin memdisk pxelinux.0 ver.com
搭建HTTPD服務##
1、yum 安裝httpd
[[email protected] ~]#yum install -y httpd
2、搭建本地鏡像倉及KS目錄
[[email protected] ~]#mkdir -pv /var/www/html/{ksdir,centos/7.4} /*建立鏡像所需目錄centos/7.4,和存放kickstart.cfg檔案的ksdir目錄
[[email protected] ~]#cp -r /mnt/* /var/www/html/centos/7.4/ /*将7.4鏡像複制至本機
3、啟動服務
[[email protected] ~]#systemctl start httpd.service
[[email protected] ~]#systemctl enable httpd.service
搭建TFTP服務
TFTP(Trivial File Transfer Protocol,簡單檔案傳輸協定)是TCP/IP協定族中的一個用來在客戶機與伺服器之間進行簡單檔案傳輸的協定,提供不複雜、開銷不大的檔案傳輸服務。是進行小檔案傳輸的。是以它不具備通常的FTP的許多功能,它隻能從檔案伺服器上獲得或寫入檔案,不能列出目錄,不進行認證,它傳輸8位資料。是進行小檔案傳輸的。是以它不具備通常的FTP的許多功能,它隻能從檔案伺服器上獲得或寫入檔案,不能列出目錄,不進行認證,它傳輸8位資料。端口号為69。
1、yum安裝tftp-server
[ro[email protected] ~]#yum install -y tftp-server
2、修改tftp配置檔案
[[email protected] ~]# vi /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no /*修改為NO
per_source = 11
cps = 100 2
flags = IPv4
}
3、建立pxe所需目錄及檔案,多系統安裝時将vmlinuz等檔案單獨存放在各自目錄下,此時在配置相對應的kernel、initrd檔案指向時需要帶上一級目錄,tftp-server預設根目錄為:/var/lib/tftpboot
[[email protected] ~]# cd /var/lib/tftpboot/
[[email protected] tftpboot]#cp /usr/share/syslinux/{chain.c32,memdisk,menu.c32,pxelinux.0} ./
[[email protected] tftpboot]#mkdir pxelinux.cfg /*建立MENU default目錄
[[email protected] tftpboot]#mkdir centos7 /*建立存放centos7的vmlinuz等檔案的目錄,如果存在多系統安裝時,可建立各自目錄存放檔案
[[email protected] tftpboot]#vim pxelinux.cfg/default
default menu.c32
prompt 1
timeout 30
display boot.msg
menu background timg.jpg
menu title ############PXE boot Menu###########
label Centos7.4
menu label Kickstart RHEL7.4
kernel centos7/vmlinuz
append initrd=centos7/initrd.img ks=http://192.168.101.130/ksdir/7.4/ks7.4.cfg inst repo=http://192.168.101.130/centos/7.4/ /*指定鏡像所在路徑及KS配置檔案所在目錄
[[email protected] centos7]#cp /mnt/images/pxeboot/* /var/lib/tftpboot/centos7/
[[email protected] centos7]#ls -al
total 108567
dr-xr-xr-x. 2 root root 2048 Jul 11 2017 .
dr-xr-xr-x. 3 root root 2048 Jul 11 2017 ..
-r--r--r--. 2 root root 49763300 Jul 11 2017 initrd.img
-r--r--r--. 1 root root 664 Jul 11 2017 TRANS.TBL
-r--r--r--. 2 root root 55528012 Jul 11 2017 upgrade.img
-r-xr-xr-x. 2 root root 5875184 Jul 7 2017 vmlinuz
4、啟動服務
[[email protected] ~]#systemctl start tftp.socket
[[email protected] ~]#systemctl enable tftp.service
System-config-kickstart
kickstart工具是由Redhat開發,也是目前比較通用的自動化部署工具之一,system-config-kickstart是需要在圖形化界面下工作生成ks.cfg檔案;如果熟練文法的話,也可以手動書寫ks.cfg。
在圖形界面下,打開Terminal,執行【system-config-kickstart】即可
結尾
在虛拟機中建立虛拟機,便可測試無人值守自動化安裝作業系統