VMware實現(xiàn)PXE+kickstart無人值守安裝Centos7系統(tǒng)的詳細過程
PXE實現(xiàn)無人值批量部署服務器
一、PXE概述
1.1 什么是PXE
PEX (Pre-Boot Execution E nvironment 預啟動執(zhí)行環(huán)境),是一種引導方式,并不是一種安裝方式。基于 Client/Server的工作模式PXE在網(wǎng)卡的ROM 中,當計算機引導時,BIOS把PXE Client調入內存執(zhí)行,PXE Client 將放置在遠端的文件通過網(wǎng)絡下載到本地運行。
1.2 什么是KickStart
KickStart 是一種無人值守的安裝方式,KickStart 的工作原理是通過 記錄典型的安裝過程中記錄所需要填寫的各種參數(shù)(語言、時區(qū)、密碼、分區(qū)、鍵盤等),并生成一個ks.cfg的文件。(名字可以修改,默認ks.cfg)
在其后的安裝過程中,當出現(xiàn)要求填寫參數(shù)的情況時,安裝程序會首先去查找KickStart 生成的文件,當找到合適的參數(shù)時,就采用找到的參數(shù),當沒有找到合適的參數(shù),就會卡著,需要人工干預。
如果KickStart 文件涵蓋安裝過程中所有需要填寫的參數(shù)時,只需要告訴安裝程序從何處取得 ks.cfg文件。安裝完畢后,安裝程序會根據(jù)ks.cfg中設置的重啟選項重啟系統(tǒng),并結束安裝。
1. 3 安裝的必要條件
BIOS 支持PXE,需要在BIOS開啟
NIC 網(wǎng)卡支持
二、PXE工作原理
2.1 工作原理
拓撲圖
PXE工作原理
1.首先 PXE Client 向 DHCP 服務器發(fā)起請求分配IP(網(wǎng)卡需要向DHCP請求地址,獲取信息)
2. DHCP 除了給你分配地址外,還會給你分配 boot-loader name(引導程序的名字) 以及Tftp 服務器IP地址
3.網(wǎng)卡使用Tftp 的客戶端,向tftp服務器發(fā)起請求,把引導程序(pxelinux.0)加載到內存中來
4.然后 BIOS會執(zhí)行這個引導程序。
5.引導程序會 boot-loader會從tftp去查找它的配置文件(default)
6.根據(jù)配置文件來引導
2.2 本次實驗環(huán)境
實驗環(huán)境
主機名 | 網(wǎng)絡模式 | IP地址 |
---|---|---|
Server | 僅主機 vmware 需要關閉DHP |
10.0.0.100 |
Client | 僅主機 | DHCP分配 |
2.3 執(zhí)行PXE+KiskStart安裝需要準備內容
- DHCP 服務器 用來給客戶機分配IP
- TFTP 服務器 用來存放PXE 的相關文件:系統(tǒng)引導文件
- FTP|NFS|HTTP服務器 用來存放系統(tǒng)安裝文件
- KickStart所生成的ks.cfg配置文件
- 帶有一個 PXE支持網(wǎng)卡的 將安裝的 主機
三、安裝步驟
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 關閉防火墻、selinux
關閉防火墻、selinux
[root@Server~]# systemctl disable firewalld --now [root@Server~]#setenforce 0 # selinux 開機才生效,setenforce 0 臨時關閉
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服務
配置DHCP文件
# 1.進入 dhcp目錄 [root@Server~]# cd /etc/dhcp/ [root@Server/etc/dhcp]# ls dhclient.d dhcpd6.conf scripts dhclient-exit-hooks.d dhcpd.conf # 2.查看默認配置文件,是空的,但是/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 文件,(這里可以不用拷貝配置文件,直接復制下面一段。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配置,正常公司會有2個DNS我這里隨意配的 option routers 10.0.0.254; # 設置網(wǎng)關的 option broadcast-address 10.0.0.255; # 設置廣播地址 default-lease-time 600; # 默認租約時間,它的單位為秒 max-lease-time 7200; #最大租約時間,它的單位為秒 next-server 10.0.0.100; # tftp-server IP地址 filename "/pxelinux.0"; # 網(wǎng)絡啟動程序,(網(wǎng)絡引導) # 5. 啟動dhcp 服務器, [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~]# @補充:如果全局配置了,子配置沒配置,那么將讀取全局設置 如果全局配置了,子的也配置了,那么將以自配置為準。
3.3.3 配置tftp服務
開啟tftp服務
# 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文件是那個包提供的 [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)建一個目錄,用來放啟動配置文件 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/
驗證
1.客戶端啟動系統(tǒng),選擇從網(wǎng)卡啟動
2.就會從DHCP服務器(10.0.0.81)中獲取IP地址,同時還獲取了 tftp-server IP(10.0.0.81)地址和網(wǎng)絡引導程序(pxelinux.0)
3.通過網(wǎng)卡讀取到tftp-server(/var/lib/tftpboot目錄)上的pxelinux.0,讀取到內存中
4.在內存中執(zhí)行引導程序
5.讀取引導程序的配置文件(/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. 啟動界面,配置ks.cfg [root@Server~]# system-config-kickstart 詳解界面如下:
3.4.2 system-config-kickstart 界面配置
基本配置(默認語言、鍵盤、時區(qū)、密碼、安裝后重啟)
安裝方法(全新安裝、HTTP安裝方式)
安裝新引導裝載程序
分區(qū)信息
網(wǎng)絡配置
防火墻配置
顯示配置(是否安裝圖形界面)
軟件包安裝選擇
安裝后腳本
保存
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.設置開啟自動、啟動服務 [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 鏡像文件掛在設置開機自啟動
設置iso開機自啟動
# 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版本上,模式可以識別loop,defaults,loop 后面的loop可以省略
3.6 配置開機菜單 default
3.6.1 將ks6.cfg移動到 /var/www/html/ks
移動ks6.cfg
# 1.將我們保存在root目錄中的cfg移動到 /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 配置開機菜單
編寫defautl文件
[root@Server~]# cd /var/lib/tftpboot/pxelinux.cfg/ [root@Server/var/lib/tftpboot/pxelinux.cfg]# ls default # 1.編寫default文件,此時在原本的label linux 添加以下內容, # 并刪除label check里面的 menu defalut(默認啟動方式,設置了,就不需要選擇,默認啟動選項) [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.可以修改下默認的時間,默認是 600(單位是600秒的十分之一,就是60s) # 這里我設置60,就是6s timeout 60 ------------------- 參數(shù)介紹 efault vesamenu.c32 # 這是必須項,或者使用menu.c32 timeout 60 # 超時等待時間,60秒內不操作將自動選擇默認的菜單來加載 display boot.msg # 這是為選項提供一些說明的文件 # 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 # 大標題 menu vshift 8 …… label linux menu label ^Install CentOS 7 # 菜單文字 kernel vmlinuz # 內核文件路徑,注意相對路徑是從tftp的根路徑/tftpboot開始的 append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet # 內核啟動選項,其中包括initrd的路徑,同樣要改為"ks=http://10.0.0.100/ks.cfg/ks6.cfg" menu default # menu default表示開機時光標一開始默認停留在此label上 # 一般pxe環(huán)境下此路徑直接指向系統(tǒng)安裝文件的路徑,具體做法見下文示例 # utilities submenu # 子菜單項的設置方法 menu begin ^Troubleshooting menu title Troubleshooting
3.6.3 將客戶機 設置網(wǎng)絡啟動(raid等),開機啟動即可
四、總結
所謂的無人值守,就是自動應答,當安裝過程中需要人機交互提供某些選項的答案時(如如何分區(qū)),自動應答文件可以根據(jù)對應項自動提供答案。但是,無人值守并不完全是無人值守,至少設置bios從網(wǎng)卡啟動是必須人為設置的,且安裝完系統(tǒng)后設置不從網(wǎng)卡啟動也是需要人為設置的。除此之外,其他的基本上都可以實現(xiàn)無人值守安裝。
在部署時,建議使用 Kickstart+DHCP+HTTP(FTP)+TFTP,安裝dhcp、tftp-server、xinetd、httpd、system-config-kickstart等軟件。
在真實環(huán)境中,通常我們會發(fā)現(xiàn)一臺服務器好幾塊硬盤,做完raid,整個硬盤有等10T,如果來使用kickstart自動安裝并分區(qū)呢;一般服務器硬盤超過2T,如何來使用kickstart安裝配置呢?這里就不能使用MBR方式來分區(qū),需要采用GPT格式來引導并分區(qū)。需要在ks.cfg末尾添加如下命令來實現(xiàn)需求:
%pre parted -s /dev/sdb mklabel gpt %end
到此這篇關于VMware實現(xiàn)PXE+kickstart無人值守安裝Centos7系統(tǒng)的文章就介紹到這了,更多相關VMware無人值守安裝Centos7系統(tǒng)內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
VMware中讓CentOS利用橋接上網(wǎng)的方法教程
在 VMware 中可以使用三種方式上網(wǎng):橋接(Bridge)、網(wǎng)絡地址轉換(NAT)、僅主機(HOST-ONLY)。下面這篇文章主要給大家介紹了在VMware中讓CentOS利用橋接上網(wǎng)的方法教程,有需要的朋友可以參考借鑒,下面來一起看看吧。2017-02-02VMware虛擬機系統(tǒng)無法使用橋接聯(lián)網(wǎng)的解決方法
這篇文章主要介紹了VMware虛擬機系統(tǒng)無法使用橋接聯(lián)網(wǎng)的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-08-08vmware workstation12安裝centos提示VMware Player與Device/Credentia
這篇文章主要介紹了vmware workstation12安裝centos提示VMware Player與Device/Credential Guard不兼容原因及解決方案,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05VMware WorkStation 14 pro安裝Ubuntu 17.04教程
這篇文章主要為大家詳細介紹了VMware WorkStation 14 pro安裝Ubuntu17.04教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-03-03VMware15/16解鎖VMware安裝MacOS的步驟詳解
這篇文章主要介紹了VMware15/16解鎖VMware安裝MacOS的步驟詳解,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12VMWare中Ubuntu重啟后無法上網(wǎng)的解決方法
這篇文章主要為大家詳細介紹了VMWare中Ubuntu重啟后無法上網(wǎng)的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-03-03