Kickstart 文件是一種配置文件,用于定義 Linux 系統安裝過程中的各種參數,如分區、網絡配置、軟件包選擇等。system-config-kickstart
提供了一個圖形界面,方便用戶快速生成這些配置文件。
用戶可以通過圖形界面進行系統安裝的詳細配置,包括:
-
安裝方法(如網絡安裝、本地安裝等)。
-
網絡設置(如 IP 地址、網關、DNS 等)。
-
分區信息(如分區大小、文件系統類型等)。
-
軟件包選擇(如安裝哪些軟件包或組)。
-
預安裝和安裝后腳本(用于執行自定義操作)。
配置流程
由于system-config-kickstart在redhat7.9以上就不再提供了,所以建議選擇7.9以下的版本或centos7.9以下
邏輯思路:通過一臺服務器httpd服務分享我們之后需要安裝的主機提供光盤文件,和我們使用system-config-kickstart 生成的kickstart配置文件。新主機在安裝的時候不從硬件啟動,先通過DHCP獲取到IP地址和根據下一步的IP去找獲取共享資源的tftp服務器,這個服務器共享一個引導文件pxelinux.0,用于網絡啟動的引導程序文件。讓系統去找pxelinux.cfg/default文件,并定義內核文件、啟動參數,其中就含有我們httpd服務分享的那些資源。然后根據kickstart實現自動化安裝和配置
為了省事兒我們把DHCP、kickstart、httpd和tftp服務都放在一臺主機上提供。主機IP地址為:192.168.118.134
環境準備
由于kickstart它是有界面的,所以我們需要下載界面。如果讀者安裝rhel7是帶有界面的,這一步跳過。
yum group list
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-managerThis system is not registered with an entitlement server. You can use subscription-manager to register.
Repository 'baseos' is missing name in configuration, using id
Installed Environment Groups:
? ?Server with GUI
Available Environment Groups:
? ?Minimal Install
? ?Infrastructure Server
? ?File and Print Server
? ?Basic Web Server
? ?Virtualization Host
Available Groups:
? ?Compatibility Libraries
? ?Console Internet Tools
? ?Development Tools
? ?Graphical Administration Tools
? ?Legacy UNIX Compatibility
? ?Scientific Support
? ?Security Tools
? ?Smart Card Support
? ?System Administration Tools
? ?System Management
Done
查看好我們需要的Server with GUI這個包之后,我們直接安裝,順便安裝上DHCP,httpd,system-config-kickstart這幾個包
yum group install "Server with GUI" -y
yum install system-config-kickstart dhcp httpd -y
準備提供服務的系統盤?
為了避免不必要的麻煩,請事先關閉selinux和防火墻:setenforce 0 && systemctl stop firewalld
我們先將系統盤掛載的目錄創建一個軟連接到httpd服務的目錄下面
ln -s /mnt /var/www/html
[root@localhost ~]# ll /var/www/html/
total 0
lrwxrwxrwx. 1 root root 4 Feb 22 09:19 mnt -> /mntsystemctl start httpd
?啟動之后自己用瀏覽器查看一下
配置kickstart
咱要先進入到GUI界面,然后才能啟動kickstart:init 5進入
然后自己隨便配置一下,找到terminal。在里面輸入system-config-kickstart
?下圖中的Reboot system after installation不能勾上,要不然它之后安裝好重啟又會鏈接到DHCP,然后反復重裝系統
下一步installation method選擇HTTP,寫上server地址,和目錄即可
?第三步的boot loader options保持默認即可
第四步是磁盤分區的,我們不想安裝master那樣分區,選擇Clear Master Boot Recoed,磁盤的標簽也要初始化Initial the disk label
我們需要給上面的Layout添加一個boot分區,一個/分區和一個swap內存分區
把剩下的全部給根分區好了
?
配置好之后,第五步,是配置網絡的,這一步需要添加一塊網卡,要DHCP的
?跳過Authentication Configuration(配置驗證方式的,默認就可以),第六步配置防火墻,關閉就好
?第七步把那個Install a graphicial environment關掉,這個是安裝圖形化界面的
最后一步,可以編寫自己安裝好了系統之后執行的腳本,我們跳過了Package Selection這一步,這一步是可以選擇裝系統是安裝的軟件包,這里沒法配置。我們可以之后在生成的ks.cfg文件中添加上。
我們在Post-Installation Scrpt中寫個腳本,要求它自動掛載
cat > /etc/yum.repo.d/rhel7.repo << EOF
[rhel]
basename=rhel
baseurl=http://192.168.118.134/mnt
gpgcheck=0
enabled=1
EOFyum clean all && yum makecache
?編輯好之后保存即可,我這里不是以root用戶啟動界面的,所以我沒法保存到root目錄下,就保存到Redhat用戶目錄下
init 3回到終端模式
將創建好的ks.cfg給移動到http服務目錄下:mv /home/redhat/ks.cfg /var/www/html/
回到終端模式之后需要重新啟動一下httpd:systemctl start httpd
參考桌面的anaconda.cfg我們在里面添加上需要安裝到軟件包:
%packages
@base #示安裝系統的基礎軟件包組,它提供了一個最小化的、功能完備的 Linux 系統
net-tools
vim
tree
tar
%end
使用syslinux作為引導安裝
這里會帶著大家一步步從官方文檔中找到配置syslinux的方法
yum install syslinux -y
rpm -ql命令用于列出指定 RPM 包中包含的所有文件及其安裝路徑:rpm -ql syslinux
?先看看README這個文件:?more /usr/share/doc/syslinux-4.05/README
?由于我們是使用的pxelinux這個功能,這里要我們去尋找pxelinux.txt文檔
[root@localhost ~]# rpm -ql syslinux | grep pxelinux.txt
/usr/share/doc/syslinux-4.05/pxelinux.txt
?文中提到了需要使用到tftp服務,和需要創建/tftpboot/pxelinux.cfg,并且里面需要存放pxelinux.0文件和任何需要引導的內核和initrd鏡像
?我們下載tftp-server:yum install tftp-server -y,默認情況下/var/lib/tftpboot就是它服務器的默認根目錄。
根據上面圖片提到的信息,我們把pxelinu.0和我們本臺主機的ISO 鏡像或光盤引導系統移動到這個目錄下面
rpm -ql syslinux | grep pxelinux.0
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /mnt/isolinux/* /var/lib/tftpboot/
?注釋:isolinux是專門用于從 ISO 鏡像或光盤引導系統,就是咱們在安裝系統時的初始那個引導界面
最后創建好/var/lib/tftpboot/pxelinux.cfg這個目錄,在這個目錄中的的配置可以從根據syslinux.txt中查看(地址為rpm -ql syslinux | grep syslinux.txt)。
不過可以偷懶: [root@localhost tftpboot]# cp isolinux.cfg ./pxelinux.cfg/default
我們修改一下里面的參數
default vesamenu.c32
timeout 30#3秒鐘,選擇系統的時候不用等默認的60秒...
label linux
? menu label ^Install Red Hat Enterprise Linux 7.9
? menu default
? kernel vmlinuz
? append initrd=initrd.img repo=http://192.168.118.134/mnt/ ks=http://192.168.118.134/ks.cfg quietlabel check
? menu label Test this ^media & install Red Hat Enterprise Linux 7.9
? kernel vmlinuz
? append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 rd.live.check quiet....
?
默認進入安裝引導的時候是:Test this ^media & install Red Hat Enterprise Linux 7.9
改為直接安裝:^Install Red Hat Enterprise Linux 7.9? #這個標簽可以內容可以改,自定義的。然后修改源為我們自己配置的repo=http://192.168.118.134/mnt/ ks=http://192.168.118.134/ks.cfg ,quite表示靜默安裝
配置完之后:wq!退出
systemctl enable --now tftp
配置DHCP服務
這一步是為了需要自動安裝的主機,自動獲取IP之后指定其下一步的行為。讓他通過tftpboot里面的pxelinux.0進行后續的安裝
yum install dhcp -y
[root@localhost pxelinux.cfg]# rpm -ql dhcp
/etc/NetworkManager
/etc/NetworkManager/dispatcher.d
/etc/NetworkManager/dispatcher.d/12-dhcpd
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/dhcp/scripts
/etc/dhcp/scripts/README.scripts
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/usr/bin/omshell
/usr/lib/systemd/system/dhcpd.service
/usr/lib/systemd/system/dhcpd6.service
/usr/lib/systemd/system/dhcrelay.service
/usr/sbin/dhcpd
/usr/sbin/dhcrelay
/usr/share/doc/dhcp-4.2.5
/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
/usr/share/doc/dhcp-4.2.5/dhcpd6.conf.example
顯然/etc/dhcp/dhcpd.conf就是我們需要配置的文件,其中/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example是提供給我們的示例
cp -f /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
進入到這個配置文件中刪除掉dhcp功能之后的所有配置,和bootp功能
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;default-lease-time 600;
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.#subnet 10.152.187.0 netmask 255.255.255.0 {
#}# This is a very basic subnet declaration.
# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.# A slightly different configuration for an internal subnet.
subnet 192.168.118.0 netmask 255.255.255.0 {range 192.168.118.140 192.168.118.180;option domain-name-servers 114.114.114.114;option routers 192.168.118.2;next-server 192.168.118.134;filename "pxelinux.0";
}
當需要安裝的主機在獲取到了IP地址,之后,會通過tftp到192.168.118.134這個主機去找pxelinux.0引導程序。?
以上DHCP就配置好了,在啟動之前需要關閉VMware的DHCP功能,選擇虛擬網絡編輯器
?找到118網段的網卡,關閉DHCP
啟動dhcpd
systemctl enable --now dhcpd
以上就全部配置好了,現在進行測試
測試
先創建一臺虛擬機殼子,直接移除掉CD/DVD,這一步可以不做,為了凸顯效果,我直接移除了
右擊新創建的虛擬機,點擊"打開電源時進入固件"
選擇從網絡啟動,使用shift加+將選項向上移動。之后保存退出
?然后在Exit選擇Exiting Saving?Changes退出即可。正在自動部署
?等待安裝好了之后,重復上面的步驟把我們的從網絡啟動改回到從硬件啟動。進入到"打開電源時進入固件",然后 選擇Hard Drive硬件啟動,再次啟動之后就是我們定制好的系統了
?
?