本章是對上篇文章的擴展:
https://blog.csdn.net/qq_50247813/article/details/145286244
上篇文章學習了如何自定義鏡像安裝。這篇介紹如何在定制鏡像的時候安裝其他軟件; (源文件參考上篇文章)
根據上篇文章的步驟,只需要把第6步做完
-
自定義安裝的時候安裝: vim-enhanced,net-tools,telnet,wget,rsync,lsof,docker-ce 軟件
vim 軟件包名全稱是
vim-enhanced
1.1. 將需要安裝的軟件包以及依賴下載到 Centos-install/Packages里面
由于Centos默認的yum源的docker版本很低,所有docker安裝不使用默認的源,使用阿里云的yum源。
# yum install -y yum-utils
# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# yum install --downloadonly --downloaddir=/root/Centos-install/Packages/ vim-enhanced net-tools telnet wget rsync lsof # yum install --downloadonly --enablerepo=docker-ce-stable --downloaddir=/root/Centos-install/Packages/ docker-ce
1.2. 重新修改 *-comps.xml 文件,將vim-enhanced,net-tools,telnet,wget,rsync,lsof,docker添加進去。
必須在最小型安裝后面的
packagelist
里面添加包名。
<packagereq type=“default”>vim-enhanced 中 type=“default” 表示該軟件包是軟件包組的 默認成員,當用戶安裝這個軟件包組時,vim-enhanced 軟件包將被自動安裝,但用戶可以選擇不安裝它。
還有其他選項:
type=“mandatory”:這個屬性表示該軟件包是軟件包組的 強制性成員。當用戶安裝這個軟件包組時,軟件包將被自動安裝,而無需用戶手動選擇。
type=“optional”:這個屬性表示該軟件包是軟件包組的 可選成員。當用戶安裝這個軟件包組時, 軟件包不會自動安裝,用戶可以選擇是否安裝它。# cd /root/Centos-install/repodata/ # shopt -s extglob # rm -f !(*-comps.xml) # mv *-comps.xml comps.xml # cat comps.xml <name xml:lang="zh_CN">核心</name> <name xml:lang="zh_TW">核心</name> <name xml:lang="zu">Okuyikhona</name> <description>Smallest possible installation.</description> <description xml:lang="as">??????? ???????</description> <description xml:lang="bn">??????? ??????????</description> <description xml:lang="cs">Nejmen?í mo?ná instalace.</description> <description xml:lang="de">Kleinstm?gliche Installation.</description> <description xml:lang="de_CH">Kleinstm?gliche Installation.</description> <description xml:lang="es">La instalación más peque?a posible.</description> <description xml:lang="fr">Plus petite installation possible.</description> <description xml:lang="gu">??????? ???? ???? ??????.</description> <description xml:lang="hi">????? ??????? ????????.</description> <description xml:lang="ia">Le minime possibile installation.</description> <description xml:lang="it">Minima installazione possibile.</description> <description xml:lang="ja">最小限のインストール</description> <description xml:lang="kn">???????????? ??????????.</description> <description xml:lang="ko">??? ?? ??</description> <description xml:lang="ml">???????? ??????? ????? ???<200d>??????????<200d>.</description> <description xml:lang="mr">??????? ?????? ???? ???????????.</description> <description xml:lang="or">????????? ???????? ????????</description> <description xml:lang="pa">????-??? ???? ??????????</description> <description xml:lang="pl">Najmniejsza mo?liwa instalacja.</description> <description xml:lang="pt_BR">Menor instala??o possível</description> <description xml:lang="ru">Минимально возможная установка</description> <description xml:lang="sv">Minsta m?jliga installation</description> <description xml:lang="ta">????? ????? ?????????????????? ???????.</description> <description xml:lang="te">???????? ???????? ????????.</description> <description xml:lang="uk">М?н?мально можливе встановлення.</description> <description xml:lang="zh">最小型安裝。</description> <description xml:lang="zh_CN">最小可能安裝。</description> <description xml:lang="zh_TW">最小型安裝。</description> <default>false</default> <uservisible>false</uservisible> <packagelist> ... ...<packagereq type="default">vim-enhanced</packagereq><packagereq type="default">net-tools</packagereq><packagereq type="default">telnet</packagereq><packagereq type="default">wget</packagereq><packagereq type="default">rsync</packagereq><packagereq type="default">lsof</packagereq><packagereq type="default">docker-ce</packagereq> ... ... </packagelist>
1.3. 重新生成yum元數據
# createrepo -g /root/Centos-install/repodata/comps.xml /root/Centos-install Spawning worker 0 with 365 pkgs Workers Finished Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete
-
在ks中配置啟動docker,并把默認的yum源修改為阿里云
由于涉及到uefi和bios引導所有兩個ks文件都需要修改,修改內容一致,這里只展示一個。
在系統安裝完后執行。# cat Centos-install/isolinux/bios.cfg ... ... %postrm -rf /etc/yum.repos.d/* echo "[base] name=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/ http://mirrors.aliyuncs.com/centos/\$releasever/os/\$basearch/ http://mirrors.cloud.aliyuncs.com/centos/\$releasever/os/\$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 " > /etc/yum.repos.d/CentOS-Base.reposystemctl enable docker --now%end ... ...
-
創建自定義iso鏡像。
# cd Centos-install/ # mkisofs -untranslated-filenames -volid "CentOS 7 x86_64" -J -joliet-long -rational-rock -translation-table -input-charset utf-8 -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e images/efiboot.img -no-emul-boot -o /root/Centos-build-20250201.iso -graft-points /root/Centos-install
-
使用自定義的iso鏡像創建系統后,測試效果。
[root@192 ~]# rpm -qa | egrep 'vim-enhanced|net-tools|telnet|wget|rsync|lsof' vim-enhanced-7.4.629-8.el7_9.x86_64 net-tools-2.0-0.25.20131004git.el7.x86_64 lsof-4.87-6.el7.x86_64 rsync-3.1.2-12.el7_9.x86_64 wget-1.14-18.el7_6.1.x86_64 telnet-0.17-66.el7.x86_64 [root@192 ~]# rpm -qa | grep docker docker-ce-26.1.4-1.el7.x86_64 docker-compose-plugin-2.27.1-1.el7.x86_64 docker-ce-cli-26.1.4-1.el7.x86_64 docker-ce-rootless-extras-26.1.4-1.el7.x86_64 docker-buildx-plugin-0.14.1-1.el7.x86_64
[root@192 ~]# systemctl status docker ● docker.service - Docker Application Container EngineLoaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)Active: active (running) since Fri 2025-01-31 20:24:03 EST; 7h leftDocs: https://docs.docker.comMain PID: 866 (dockerd)Tasks: 8Memory: 105.8MCGroup: /system.slice/docker.service└─866 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sockJan 31 20:24:02 localhost.localdomain systemd[1]: Starting Docker Application Container Engine... Jan 31 20:24:02 localhost.localdomain dockerd[866]: time="2025-01-31T20:24:02.852110125-05:00" level=info msg="Starting up" Jan 31 20:24:02 localhost.localdomain dockerd[866]: time="2025-01-31T20:24:02.960516801-05:00" level=info msg="Loading containers: start." Jan 31 20:24:03 localhost.localdomain dockerd[866]: time="2025-01-31T20:24:03.168511723-05:00" level=info msg="Loading containers: done." Jan 31 20:24:03 localhost.localdomain dockerd[866]: time="2025-01-31T20:24:03.182787827-05:00" level=info msg="Docker daemon" commit=de5c9cf containerd-snap...on=26.1.4 Jan 31 20:24:03 localhost.localdomain dockerd[866]: time="2025-01-31T20:24:03.183180333-05:00" level=info msg="Daemon has completed initialization" Jan 31 20:24:03 localhost.localdomain dockerd[866]: time="2025-01-31T20:24:03.252357348-05:00" level=info msg="API listen on /run/docker.sock" Jan 31 20:24:03 localhost.localdomain systemd[1]: Started Docker Application Container Engine. Hint: Some lines were ellipsized, use -l to show in full.
[root@192 ~]# cat /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS- - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos//os// http://mirrors.aliyuncs.com/centos//os// http://mirrors.cloud.aliyuncs.com/centos//os// gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
測試結果與實際情況符合。