VMware實(shí)現(xiàn)PXE+kickstart無人值守安裝Centos7系統(tǒng)的詳細(xì)過程
PXE實(shí)現(xiàn)無人值批量部署服務(wù)器
一、PXE概述
1.1 什么是PXE
PEX (Pre-Boot Execution E nvironment 預(yù)啟動(dòng)執(zhí)行環(huán)境),是一種引導(dǎo)方式,并不是一種安裝方式。基于 Client/Server的工作模式PXE在網(wǎng)卡的ROM 中,當(dāng)計(jì)算機(jī)引導(dǎo)時(shí),BIOS把PXE Client調(diào)入內(nèi)存執(zhí)行,PXE Client 將放置在遠(yuǎn)端的文件通過網(wǎng)絡(luò)下載到本地運(yùn)行。
1.2 什么是KickStart
KickStart 是一種無人值守的安裝方式,KickStart 的工作原理是通過 記錄典型的安裝過程中記錄所需要填寫的各種參數(shù)(語言、時(shí)區(qū)、密碼、分區(qū)、鍵盤等),并生成一個(gè)ks.cfg的文件。(名字可以修改,默認(rèn)ks.cfg)
在其后的安裝過程中,當(dāng)出現(xiàn)要求填寫參數(shù)的情況時(shí),安裝程序會(huì)首先去查找KickStart 生成的文件,當(dāng)找到合適的參數(shù)時(shí),就采用找到的參數(shù),當(dāng)沒有找到合適的參數(shù),就會(huì)卡著,需要人工干預(yù)。
如果KickStart 文件涵蓋安裝過程中所有需要填寫的參數(shù)時(shí),只需要告訴安裝程序從何處取得 ks.cfg文件。安裝完畢后,安裝程序會(huì)根據(jù)ks.cfg中設(shè)置的重啟選項(xiàng)重啟系統(tǒng),并結(jié)束安裝。
1. 3 安裝的必要條件
BIOS 支持PXE,需要在BIOS開啟
NIC 網(wǎng)卡支持
二、PXE工作原理
2.1 工作原理
拓?fù)鋱D
PXE工作原理
1.首先 PXE Client 向 DHCP 服務(wù)器發(fā)起請求分配IP(網(wǎng)卡需要向DHCP請求地址,獲取信息)
2. DHCP 除了給你分配地址外,還會(huì)給你分配 boot-loader name(引導(dǎo)程序的名字) 以及Tftp 服務(wù)器IP地址
3.網(wǎng)卡使用Tftp 的客戶端,向tftp服務(wù)器發(fā)起請求,把引導(dǎo)程序(pxelinux.0)加載到內(nèi)存中來
4.然后 BIOS會(huì)執(zhí)行這個(gè)引導(dǎo)程序。
5.引導(dǎo)程序會(huì) boot-loader會(huì)從tftp去查找它的配置文件(default)
6.根據(jù)配置文件來引導(dǎo)
2.2 本次實(shí)驗(yàn)環(huán)境
實(shí)驗(yàn)環(huán)境
主機(jī)名 | 網(wǎng)絡(luò)模式 | IP地址 |
---|---|---|
Server | 僅主機(jī) vmware 需要關(guān)閉DHP |
10.0.0.100 |
Client | 僅主機(jī) | DHCP分配 |
2.3 執(zhí)行PXE+KiskStart安裝需要準(zhǔn)備內(nèi)容
- DHCP 服務(wù)器 用來給客戶機(jī)分配IP
- TFTP 服務(wù)器 用來存放PXE 的相關(guān)文件:系統(tǒng)引導(dǎo)文件
- FTP|NFS|HTTP服務(wù)器 用來存放系統(tǒng)安裝文件
- KickStart所生成的ks.cfg配置文件
- 帶有一個(gè) PXE支持網(wǎng)卡的 將安裝的 主機(jī)
三、安裝步驟
3.1 配置YUM源
YUM 源配置
[root@Server~]# cd /etc/yum.repos.d/ [root@Server/etc/yum.repos.d]# ls rivers.repo [root@Server/etc/yum.repos.d]# mv rivers.repo rivers.repo.bak [root@Server/etc/yum.repos.d]# vim dvd.repo [development] name=Centos7.6 baseurl=file:///mnt enabled=1 gpgcheck=0 [root@Server~]# mount /dev/cdrom /mnt/ mount: /dev/sr0 is write-protected, mounting read-only [root@Server~]# [root@Server~]# yum clean all Loaded plugins: fastestmirror Cleaning repos: development Other repos take up 137 M of disk space (use --verbose for details) [root@Server~]#
3.2 關(guān)閉防火墻、selinux
關(guān)閉防火墻、selinux
[root@Server~]# systemctl disable firewalld --now [root@Server~]#setenforce 0 # selinux 開機(jī)才生效,setenforce 0 臨時(shí)關(guān)閉
3.3 安裝DHCP 、tftp(tftp-server、xinetd)
3.3.1 安裝dhcp、tftp-server、xinetd
安裝dhcp、tftp-server
[root@Server~]# yum -y install dhcp tftp-server xinetd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package dhcp.x86_64 12:4.2.5-68.el7.centos.1 will be installed ……
3.3.2 配置DHCP服務(wù)
配置DHCP文件
# 1.進(jìn)入 dhcp目錄 [root@Server~]# cd /etc/dhcp/ [root@Server/etc/dhcp]# ls dhclient.d dhcpd6.conf scripts dhclient-exit-hooks.d dhcpd.conf # 2.查看默認(rèn)配置文件,是空的,但是/usr/share/doc/dhcp*/目錄下有配置模板,我們可以拷貝 [root@Server/etc/dhcp]# cat dhcpd.conf # # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.example # see dhcpd.conf(5) man page # [root@Server/etc/dhcp]# # 3.拷貝dhcpd 配置模板文件 [root@Server/etc/dhcp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf cp: overwrite ‘/etc/dhcp/dhcpd.conf'? y # 4. 修改dhcp 文件,(這里可以不用拷貝配置文件,直接復(fù)制下面一段。subnet--filename) # A slightly different configuration for an internal subnet. subnet 10.0.0.0 netmask 255.255.255.0 { range 10.0.0.120 10.0.0.200; option domain-name-servers 10.0.0.5, 10.0.0.6; option domain-name "example.com"; option routers 10.0.0.254; option broadcast-address 10.0.0.255; default-lease-time 600; max-lease-time 7200; next-server 10.0.0.100; filename "pxelinux.0"; } subnet 10.0.0.0 netmask 255.255.255.0 #宣告網(wǎng)段 range 10.0.0.120 10.0.0.200; #分配地址范圍 option domain-name-servers: #dns配置,正常公司會(huì)有2個(gè)DNS我這里隨意配的 option routers 10.0.0.254; # 設(shè)置網(wǎng)關(guān)的 option broadcast-address 10.0.0.255; # 設(shè)置廣播地址 default-lease-time 600; # 默認(rèn)租約時(shí)間,它的單位為秒 max-lease-time 7200; #最大租約時(shí)間,它的單位為秒 next-server 10.0.0.100; # tftp-server IP地址 filename "/pxelinux.0"; # 網(wǎng)絡(luò)啟動(dòng)程序,(網(wǎng)絡(luò)引導(dǎo)) # 5. 啟動(dòng)dhcp 服務(wù)器, [root@Server/etc/dhcp]# systemctl enable dhcpd Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service. [root@Server/etc/dhcp]# systemctl start dhcpd [root@Server/etc/dhcp]# [root@Server/etc/dhcp]# netstat -lantup|grep :67 udp 0 0 0.0.0.0:67 0.0.0.0:* 8503/dhcpd [root@Server/etc/dhcp]# [root@Server/etc/dhcp]# cd [root@Server~]# @補(bǔ)充:如果全局配置了,子配置沒配置,那么將讀取全局設(shè)置 如果全局配置了,子的也配置了,那么將以自配置為準(zhǔn)。
3.3.3 配置tftp服務(wù)
開啟tftp服務(wù)
# 1.修改tftp配置文件 [root@Server~]# vim /etc/xinetd.d/tftp 將 disable = no 改為 yes #重啟 xinetd [root@Server~]# systemctl restart xinetd.service [root@Server~]# netstat -lntup|grep :69 udp 0 0 0.0.0.0:69 0.0.0.0:* 9071/xinetd [root@Server~]#
3.3.4 安裝syslinux,拷貝pxelinux.0文件
配置tftp-server在哪里
# 1.查找 pxelinux.0文件是那個(gè)包提供的 [root@Server~]# yum provides "*/pxelinux.0" Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile syslinux-4.05-15.el7.x86_64 : Simple kernel loader ...: which boots from a FAT filesystem Repo : development Matched from: Filename : /usr/share/syslinux/pxelinux.0 syslinux-tftpboot-4.05-15.el7.noarch : SYSLINUX ...: modules in /var/lib/tftpboot, available for ...: network booting Repo : development Matched from: Filename : /var/lib/tftpboot/pxelinux.0 # 2.安裝syslinux包,然候拷貝pxelinux.0文件到 tftp-server目錄 [root@Server~]# yum -y install syslinux [root@Server~]# rpm -ql syslinux|grep pxe /usr/share/doc/syslinux-4.05/pxelinux.txt /usr/share/syslinux/gpxecmd.c32 /usr/share/syslinux/gpxelinux.0 /usr/share/syslinux/gpxelinuxk.0 /usr/share/syslinux/pxechain.com /usr/share/syslinux/pxelinux.0 [root@Server~]# # 3. 拷貝pxelinux.0 文件到 tftp-server 目錄 [root@Server~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ [root@Server/var/lib/tftpboot]# ls pxelinux.0 # 4.創(chuàng)建一個(gè)目錄,用來放啟動(dòng)配置文件 default的 [root@Server/var/lib/tftpboot]# mkdir pxelinux.cfg [root@Server/var/lib/tftpboot]# ls pxelinux.cfg pxelinux.0 [root@Server/var/lib/tftpboot]# cd pxelinux.cfg [root@Server/var/lib/tftpboot/pxe.cfg]# pwd /var/lib/tftpboot/pxelinux.cfg # 5.將 /mnt/isolinux/目錄下面的所有文件都考到 /var/lib/tftpboot下面 [root@Server/var/lib/tftpboot]# cd -- [root@Server~]# cd /mnt/isolinux/ [root@Server/mnt/isolinux]# cp -a isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default [root@Server/mnt/isolinux]#cp * /var/lib/tftpboot/
驗(yàn)證
1.客戶端啟動(dòng)系統(tǒng),選擇從網(wǎng)卡啟動(dòng)
2.就會(huì)從DHCP服務(wù)器(10.0.0.81)中獲取IP地址,同時(shí)還獲取了 tftp-server IP(10.0.0.81)地址和網(wǎng)絡(luò)引導(dǎo)程序(pxelinux.0)
3.通過網(wǎng)卡讀取到tftp-server(/var/lib/tftpboot目錄)上的pxelinux.0,讀取到內(nèi)存中
4.在內(nèi)存中執(zhí)行引導(dǎo)程序
5.讀取引導(dǎo)程序的配置文件(/var/lib/tftpboot/pxe.cfg/default)
3.4 編寫kickstart.cfg配置文件
3.4.1安裝system-config-kickstart
安裝 system-config-kickstart
[root@Server/etc/yum.repos.d]# cd -- # 1. 安裝system-config-kickstart [root@Server~]# yum -y install system-config-kickstart 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile …… #2. 啟動(dòng)界面,配置ks.cfg [root@Server~]# system-config-kickstart 詳解界面如下:
3.4.2 system-config-kickstart 界面配置
基本配置(默認(rèn)語言、鍵盤、時(shí)區(qū)、密碼、安裝后重啟)
安裝方法(全新安裝、HTTP安裝方式)
安裝新引導(dǎo)裝載程序
分區(qū)信息
網(wǎng)絡(luò)配置
防火墻配置
顯示配置(是否安裝圖形界面)
軟件包安裝選擇
安裝后腳本
保存
3.5 配置 HTTP鏡像源
3.5.1 安裝http
安裝httpd
# 1. 安裝httpd [root@Server ~]# yum -y install httpd 已加載插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile …… # 2.設(shè)置開啟自動(dòng)、啟動(dòng)服務(wù) [root@Server ~]# systemctl enable httpd [root@Server ~]# systemctl start httpd #3. 創(chuàng)建 目錄 [root@Server ~]# cd /var/www/html [root@Server/var/www/html]# mkdir ks.cfg [root@Server/var/www/html]# mkdir pub # 4.修改yum 源,將本地改為http [root@Server/var/www/html]# cd [root@Server~]# cat /etc/yum.repos.d/dvd.repo [development] name=rhce7 baseurl=http://10.0.0.100/pub enabled=1 gpgcheck=0 [root@Server~]#
3.5.2 將iso 鏡像文件掛在設(shè)置開機(jī)自啟動(dòng)
設(shè)置iso開機(jī)自啟動(dòng)
# 1. 在末尾添加以下一條信息。 [root@Server~]# vim /etc/fstab /dev/cdrom /var/www/html/pub iso9660 defaults,loop 0 0 [root@Server~]# tail -1 /etc/fstab /dev/cdrom /var/www/html/pub iso9660 defaults,loop 0 0 [root@Server~]# # 2.掛載鏡像 [root@Server~]# mount -a # 3.用火狐瀏覽器訪問下,如果可以訪問,則說明http 鏡像源沒有問題 [root@Server~]# firefox http://10.0.0.100/pub & @ 7版本上,模式可以識(shí)別loop,defaults,loop 后面的loop可以省略
3.6 配置開機(jī)菜單 default
3.6.1 將ks6.cfg移動(dòng)到 /var/www/html/ks
移動(dòng)ks6.cfg
# 1.將我們保存在root目錄中的cfg移動(dòng)到 /var/www/html/ks.cfg/ [root@Server~]# mv ks6.cfg /var/www/html/ks.cfg/ [root@Server/var/www/html/ks.cfg]# ls ks6.cfg [root@Server/var/www/html/ks.cfg]#
3.6.2 配置開機(jī)菜單
編寫defautl文件
[root@Server~]# cd /var/lib/tftpboot/pxelinux.cfg/ [root@Server/var/lib/tftpboot/pxelinux.cfg]# ls default # 1.編寫default文件,此時(shí)在原本的label linux 添加以下內(nèi)容, # 并刪除label check里面的 menu defalut(默認(rèn)啟動(dòng)方式,設(shè)置了,就不需要選擇,默認(rèn)啟動(dòng)選項(xiàng)) [root@Server/var/lib/tftpboot/pxelinux.cfg]# vim default label rhce7 menu label ^Install rhce7 menu default kernel vmlinuz append initrd=initrd.img ks=http://10.0.0.100/ks.cfg/ks6.cfg # 2.可以修改下默認(rèn)的時(shí)間,默認(rèn)是 600(單位是600秒的十分之一,就是60s) # 這里我設(shè)置60,就是6s timeout 60 ------------------- 參數(shù)介紹 efault vesamenu.c32 # 這是必須項(xiàng),或者使用menu.c32 timeout 60 # 超時(shí)等待時(shí)間,60秒內(nèi)不操作將自動(dòng)選擇默認(rèn)的菜單來加載 display boot.msg # 這是為選項(xiàng)提供一些說明的文件 # Clear the screen when exiting the menu, instead of leaving the menu displayed. # For vesamenu, this means the graphical background is still displayed without # the menu itself for as long as the screen remains in graphics mode. menu clear menu background splash.png # 背景圖片 menu title CentOS 7 # 大標(biāo)題 menu vshift 8 …… label linux menu label ^Install CentOS 7 # 菜單文字 kernel vmlinuz # 內(nèi)核文件路徑,注意相對路徑是從tftp的根路徑/tftpboot開始的 append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet # 內(nèi)核啟動(dòng)選項(xiàng),其中包括initrd的路徑,同樣要改為"ks=http://10.0.0.100/ks.cfg/ks6.cfg" menu default # menu default表示開機(jī)時(shí)光標(biāo)一開始默認(rèn)停留在此label上 # 一般pxe環(huán)境下此路徑直接指向系統(tǒng)安裝文件的路徑,具體做法見下文示例 # utilities submenu # 子菜單項(xiàng)的設(shè)置方法 menu begin ^Troubleshooting menu title Troubleshooting
3.6.3 將客戶機(jī) 設(shè)置網(wǎng)絡(luò)啟動(dòng)(raid等),開機(jī)啟動(dòng)即可
四、總結(jié)
所謂的無人值守,就是自動(dòng)應(yīng)答,當(dāng)安裝過程中需要人機(jī)交互提供某些選項(xiàng)的答案時(shí)(如如何分區(qū)),自動(dòng)應(yīng)答文件可以根據(jù)對應(yīng)項(xiàng)自動(dòng)提供答案。但是,無人值守并不完全是無人值守,至少設(shè)置bios從網(wǎng)卡啟動(dòng)是必須人為設(shè)置的,且安裝完系統(tǒng)后設(shè)置不從網(wǎng)卡啟動(dòng)也是需要人為設(shè)置的。除此之外,其他的基本上都可以實(shí)現(xiàn)無人值守安裝。
在部署時(shí),建議使用 Kickstart+DHCP+HTTP(FTP)+TFTP,安裝dhcp、tftp-server、xinetd、httpd、system-config-kickstart等軟件。
在真實(shí)環(huán)境中,通常我們會(huì)發(fā)現(xiàn)一臺(tái)服務(wù)器好幾塊硬盤,做完raid,整個(gè)硬盤有等10T,如果來使用kickstart自動(dòng)安裝并分區(qū)呢;一般服務(wù)器硬盤超過2T,如何來使用kickstart安裝配置呢?這里就不能使用MBR方式來分區(qū),需要采用GPT格式來引導(dǎo)并分區(qū)。需要在ks.cfg末尾添加如下命令來實(shí)現(xiàn)需求:
%pre parted -s /dev/sdb mklabel gpt %end
到此這篇關(guān)于VMware實(shí)現(xiàn)PXE+kickstart無人值守安裝Centos7系統(tǒng)的文章就介紹到這了,更多相關(guān)VMware無人值守安裝Centos7系統(tǒng)內(nèi)容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。