本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 AL2023 中管理套件和作業系統更新
與以前版本的 Amazon Linux 不同,AL2023 AMI 被鎖定到 Amazon Linux 存儲庫的特定版本。若要將安全和錯誤修正套用至 AL2023 執行個體,請更新 DNF 組態。或者,啟動較新的 AL2023 執行個體。
本節說明如何在執行中的執行個體管理 DNF 套件和儲存庫。另外說明如何從使用者資料指令碼設定 DNF,以在啟動時啟用最新的 Amazon Linux 儲存庫。如需更多詳細資訊,請參閱 DNF 命令參考
主題
檢查可用的套件更新
您可以使用 dnf check-update
命令來檢查系統是否有任何更新。對於 AL2023,建議您將此 --releasever=
選項新增至命令。version-number
當您新增此選項時,DNF 也會檢查儲存庫較新版本的更新。例如,執行 dnf check-update
命令後,請使用最新傳回的版本作為
的值.version-number
如果執行個體已更新為使用最新版本的存放庫,則輸出會包含所有要更新之套件的清單。
注意
如果您沒有為 dnf check-update
命令指定有選用標誌的發行版本,則僅檢查目前設定的儲存庫版本。這表示不會檢查較新版本儲存庫中的套件。
$
sudo dnf check-update --releasever=2023.0.20230210
Last metadata expiration check: 0:06:13 ago on Mon 13 Feb 2023 10:39:32 PM UTC. bind-libs.x86_64 32:9.16.27-1.amzn2023 amazonlinux bind-license.noarch 32:9.16.27-1.amzn2023 amazonlinux bind-utils.x86_64 32:9.16.27-1.amzn2023 amazonlinux cloud-init.noarch 22.2.2-1.amzn2023.1.4 amazonlinux dnf.noarch 4.12.0-2.amzn2023.0.1 amazonlinux dnf-data.noarch 4.12.0-2.amzn2023.0.1 amazonlinux dracut.x86_64 055-6.amzn2023.0.4 amazonlinux dracut-config-generic.x86_64 055-6.amzn2023.0.4 amazonlinux glib2.x86_64 2.73.2-678.amzn2023 amazonlinux gmp.x86_64 1:6.2.1-2.amzn2023 amazonlinux grep.x86_64 3.8-1.amzn2023.0.1 amazonlinux kpatch-runtime.noarch 0.9.4-7.amzn2023 amazonlinux libgcc.x86_64 11.3.1-2.amzn2023.0.6 amazonlinux libgomp.x86_64 11.3.1-2.amzn2023.0.6 amazonlinux libpkgconf.x86_64 1.7.3-7.amzn2023.0.1 amazonlinux libstdc++.x86_64 11.3.1-2.amzn2023.0.6 amazonlinux lz4-libs.x86_64 1.9.4-1.amzn2023 amazonlinux pkgconf.x86_64 1.7.3-7.amzn2023.0.1 amazonlinux pkgconf-m4.noarch 1.7.3-7.amzn2023.0.1 amazonlinux pkgconf-pkg-config.x86_64 1.7.3-7.amzn2023.0.1 amazonlinux python3-dnf.noarch 4.12.0-2.amzn2023.0.1 amazonlinux python3-rpm.x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux rpm.x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux rpm-build-libs.x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux rpm-libs.x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux rpm-plugin-selinux.x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux rpm-plugin-systemd-inhibit.x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux rpm-sign-libs.x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux slang.x86_64 2.3.2-9.amzn2023.0.1 amazonlinux system-release.noarch 2023.0.20230210-0.amzn2023 amazonlinux systemd.x86_64 250.8-1.amzn2023.0.1 amazonlinux systemd-libs.x86_64 250.8-1.amzn2023.0.1 amazonlinux systemd-networkd.x86_64 250.8-1.amzn2023.0.1 amazonlinux systemd-pam.x86_64 250.8-1.amzn2023.0.1 amazonlinux systemd-resolved.x86_64 250.8-1.amzn2023.0.1 amazonlinux systemd-udev.x86_64 250.8-1.amzn2023.0.1 amazonlinux vim-common.x86_64 2:9.0.327-1.amzn2023.0.1 amazonlinux vim-data.noarch 2:9.0.327-1.amzn2023.0.1 amazonlinux vim-enhanced.x86_64 2:9.0.327-1.amzn2023.0.1 amazonlinux vim-filesystem.noarch 2:9.0.327-1.amzn2023.0.1 amazonlinux vim-minimal.x86_64 2:9.0.327-1.amzn2023.0.1 amazonlinux wget.x86_64 1.21.3-1.amzn2023 amazonlinux yum.noarch 4.12.0-2.amzn2023.0.1 amazonlinux
對於這個命令,如果有更新的套件可用,傳回碼是 100。如果沒有更新的套件可用,傳回碼是 0。此外,輸出也會列出所有要更新的套件。
使用 DNF 和儲存庫版本套用安全更新
新套件更新和安全更新僅適用於新的儲存庫版本。對於從舊版 AL2023 AMI 啟動的執行個體,您必須先更新儲存庫版本,然後才能安裝安全更新。dnf check-release-update
命令包含範例更新命令,可將系統上安裝的所有套件更新為較新儲存庫中的版本。
$
sudo dnf update --releasever=2023.0.20230210
Last metadata expiration check: 0:01:40 ago on Mon 13 Feb 2023 10:39:32 PM UTC. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Upgrading: bind-libs x86_64 32:9.16.27-1.amzn2023 amazonlinux 1.2 M bind-license noarch 32:9.16.27-1.amzn2023 amazonlinux 16 k bind-utils x86_64 32:9.16.27-1.amzn2023 amazonlinux 202 k cloud-init noarch 22.2.2-1.amzn2023.1.4 amazonlinux 1.1 M dnf noarch 4.12.0-2.amzn2023.0.1 amazonlinux 454 k dnf-data noarch 4.12.0-2.amzn2023.0.1 amazonlinux 42 k dracut x86_64 055-6.amzn2023.0.4 amazonlinux 345 k dracut-config-generic x86_64 055-6.amzn2023.0.4 amazonlinux 8.5 k glib2 x86_64 2.73.2-678.amzn2023 amazonlinux 2.7 M gmp x86_64 1:6.2.1-2.amzn2023 amazonlinux 324 k grep x86_64 3.8-1.amzn2023.0.1 amazonlinux 316 k kpatch-runtime noarch 0.9.4-7.amzn2023 amazonlinux 30 k libgcc x86_64 11.3.1-2.amzn2023.0.6 amazonlinux 121 k libgomp x86_64 11.3.1-2.amzn2023.0.6 amazonlinux 296 k libpkgconf x86_64 1.7.3-7.amzn2023.0.1 amazonlinux 37 k libstdc++ x86_64 11.3.1-2.amzn2023.0.6 amazonlinux 758 k lz4-libs x86_64 1.9.4-1.amzn2023 amazonlinux 81 k pkgconf x86_64 1.7.3-7.amzn2023.0.1 amazonlinux 41 k pkgconf-m4 noarch 1.7.3-7.amzn2023.0.1 amazonlinux 15 k pkgconf-pkg-config x86_64 1.7.3-7.amzn2023.0.1 amazonlinux 11 k python3-dnf noarch 4.12.0-2.amzn2023.0.1 amazonlinux 415 k python3-rpm x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux 89 k rpm x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux 487 k rpm-build-libs x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux 92 k rpm-libs x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux 311 k rpm-plugin-selinux x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux 18 k rpm-plugin-systemd-inhibit x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux 19 k rpm-sign-libs x86_64 4.16.1.3-12.amzn2023.0.2 amazonlinux 22 k slang x86_64 2.3.2-9.amzn2023.0.1 amazonlinux 410 k system-release noarch 2023.0.20230210-0.amzn2023 amazonlinux 25 k systemd x86_64 250.8-1.amzn2023.0.1 amazonlinux 4.2 M systemd-libs x86_64 250.8-1.amzn2023.0.1 amazonlinux 615 k systemd-networkd x86_64 250.8-1.amzn2023.0.1 amazonlinux 614 k systemd-pam x86_64 250.8-1.amzn2023.0.1 amazonlinux 335 k systemd-resolved x86_64 250.8-1.amzn2023.0.1 amazonlinux 277 k systemd-udev x86_64 250.8-1.amzn2023.0.1 amazonlinux 1.9 M vim-common x86_64 2:9.0.327-1.amzn2023.0.1 amazonlinux 7.2 M vim-data noarch 2:9.0.327-1.amzn2023.0.1 amazonlinux 27 k vim-enhanced x86_64 2:9.0.327-1.amzn2023.0.1 amazonlinux 1.8 M vim-filesystem noarch 2:9.0.327-1.amzn2023.0.1 amazonlinux 21 k vim-minimal x86_64 2:9.0.327-1.amzn2023.0.1 amazonlinux 764 k wget x86_64 1.21.3-1.amzn2023 amazonlinux 813 k yum noarch 4.12.0-2.amzn2023.0.1 amazonlinux 39 k Transaction Summary ================================================================================ Upgrade 43 Packages ...
您可以新增僅使用安全功能更新套件的 --security
選項。
$
sudo dnf update --releasever=2023.0.20230210 --security
Amazon Linux 2023 repository 18 MB/s | 11 MB 00:00 Last metadata expiration check: 0:00:02 ago on Mon 13 Feb 2023 10:39:32 PM UTC. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Upgrading: bind-libs x86_64 32:9.16.27-1.amzn2023 amazonlinux 1.2 M bind-license noarch 32:9.16.27-1.amzn2023 amazonlinux 16 k bind-utils x86_64 32:9.16.27-1.amzn2023 amazonlinux 202 k gmp x86_64 1:6.2.1-2.amzn2023 amazonlinux 324 k lz4-libs x86_64 1.9.4-1.amzn2023 amazonlinux 81 k vim-common x86_64 2:9.0.327-1.amzn2023.0.1 amazonlinux 7.2 M vim-data noarch 2:9.0.327-1.amzn2023.0.1 amazonlinux 27 k vim-enhanced x86_64 2:9.0.327-1.amzn2023.0.1 amazonlinux 1.8 M vim-filesystem noarch 2:9.0.327-1.amzn2023.0.1 amazonlinux 21 k vim-minimal x86_64 2:9.0.327-1.amzn2023.0.1 amazonlinux 764 k wget x86_64 1.21.3-1.amzn2023 amazonlinux 813 k Transaction Summary ================================================================================ Upgrade 11 Packages ...
若要探索 AL2023 套件版本,請執行以下一或多個項目:
-
執行
dnf check-update
命令。 -
訂閱 Amazon Linux 儲存庫更新 SNS 主題 (
arn:aws:sns:us-east-1:137112412989:amazon-linux-2023-ami-updates
)。如需詳細資訊,請參閱《Amazon Simple Notification Service 開發人員指南》中的訂閱 Amazon SNS 主題。 -
定期參閱 AL2023 版本備註。
重要
當您將安全性更新套用至執行中的執行個體時,請確定 DNF 指向最新的儲存庫版本。
(安全性)更新後自動重新啟動服務
Amazon Linux 現在隨附智能重啟軟件Smart-restart
每當使用系統套件管理員安裝或刪除套件時,系統更新時都會重新啟動 systemd 服務。每當執行時dnf (update|upgrade|downgrade)
會發生這種情況。
Smart-restart
使用來源needs-restarting
套件dnf-utils
和自訂 denylist 機制來決定哪些服務需要重新啟動,以及是否建議重新啟動系統。如果建議重新啟動系統,則會產生重新啟動提示標記檔案 (/run/smart-restart/reboot-hint-marker
)。
安裝 smart-restart
執行下列DNF命令 (如同使用任何其他套件一樣)。
$
sudo dnf install smart-restart
安裝之後,後續的事務將觸發smart-restart
邏輯。
拒絕列表
Smart-restart
可以指示阻止某些服務重新啟動。被阻止的服務不會有助於決定是否需要重新啟動。若要封鎖其他服務,請新增具有尾碼-denylist
的/etc/smart-restart-conf.d/
檔案,如下列範例所示。
$
cat /etc/smart-restart-conf.d/custom-denylist
# Some comments myservice.service
注意
決定是否需要重新開機時,會讀取和評估所有*-denylist
檔案。
自定義掛鉤
除了 denylist 之外,還smart-restart
提供了在嘗試重新啟動服務之前和之後執行自訂指令碼的機制。自訂指令碼可用來手動執行準備步驟,或通知其他元件剩餘或已完成的重新啟動。
中/etc/smart-restart-conf.d/
帶有尾碼-pre-restart
或的所有程序檔-post-restart
都會被執行。如果順序很重要,請在所有指令碼前面加上數字,以確保執行順序,如下列範例所示。
$
ls /etc/smart-restart-conf.d/*-pre-restart
001-my-script-pre-restart 002-some-other-script-pre-restart
啟動已啟用最新儲存庫版本的執行個體
您可以將 DNF 命令新增至使用者資料指令碼,以控制啟動 Amazon Linux AMI 時要安裝哪些 RPM 套件。在下列範例中,使用者資料指令碼是用來確認以使用者資料指令碼啟動的任何執行個體都已安裝相同的套件更新。
#!/bin/bash dnf update --releasever=2023.0.20230210 # Additional setup and install commands below dnf install httpd php7.4 mysql80
您必須以超級使用者 (根使用者) 的身分執行此指令碼。若要進行這項動作,請執行以下命令。
$
sudo sh -c "bash
nameofscript
.sh"
如需詳細資訊,請參閱 Amazon EC2 使用者指南中的使用者資料和殼層指令碼。
注意
不要使用使用者資料指令碼,而是啟動最新的 Amazon Linux AMI 或以 Amazon Linux AMI 為基礎的自訂 AMI。最新的 Amazon Linux AMI 已安裝所有必要的更新,並且設定為指向特定的儲存庫版本。
取得套件支援資訊
AL2023 包含許多不同的開放原始碼軟體專案。這些專案中的每一個都是獨立於 Amazon Linux 進行管理,並具有不同的版本和 end-of-support 排程。為了向您提供有關這些不同套件的 Amazon Linux 特定資訊,DNFsupportinfo
外掛程式會提供有關套件的中繼資料。在下列範例中,dnf
supportinfo
命令會傳回 glibc
套件的中繼資料。
$
sudo dnf supportinfo --pkg
glibc
Last metadata expiration check: 0:07:56 ago on Wed Mar 1 23:21:49 2023. Name : glibc Version : 2.34-52.amzn2023.0.2 State : installed Support Status : supported Support Periods : from 2023-03-15 : supported : from 2028-03-15 : unsupported Support Statement : Amazon Linux 2023 End Of Life Link : https://aws.amazon.com/amazon-linux-ami/faqs/ Other Info : This is the support statement for AL2023. The ...: end of life of Amazon Linux 2023 would be March 2028. ...: From this point, the Amazon Linux 2023 packages (listed ...: below) will no longer, receive any updates from AWS.
檢查較新的儲存庫版本
在 AL2023 執行個體中,您可以使用 DNF 公用程式來管理儲存庫和套用更新的 RPM 套件。這些套件可在 Amazon Linux 儲存庫中取得。您可以使用 DNF 命令 dnf check-release-update
來檢查 DNF 儲存庫的新版本。
$
sudo dnf check-release-update
WARNING: A newer release of "Amazon Linux" is available. Available Versions: Version 2023.0.20230210: Run the following command to update to 2023.0.20230210: dnf update --releasever=2023.0.20230210 Release notes: https://docs.aws.amazon.com/linux/al2023/release-notes/relnotes.html
這將傳回所有可用 DNF 儲存庫新版本的完整清單。如果沒有傳回任何內容,這代表 DNF 目前設定為使用最新的可用版本。目前安裝的 system-release
套件版本設定 releasever
DNF 變數。若要檢查目前儲存庫版本,請執行以下命令。
$
rpm -q system-release --qf "%{VERSION}\n"
當您執行 DNF 套件交易 (例如安裝、更新或移除命令) 時,會出現警告訊息,通知您是否有任何新的儲存庫版本。例如,如果您在從舊版 AL2023 啟動的執行個體上安裝 httpd
套件,則會傳回下列輸出。
$
sudo dnf install httpd -y
Last metadata expiration check: 0:16:52 ago on Wed Mar 1 23:21:49 2023. Dependencies resolved. ==================================================================== Package Arch Version Repository Size ==================================================================== Installing: httpd x86_64 2.4.54-3.amzn2023.0.4 amazonlinux 46 k Installing dependencies: apr x86_64 1.7.2-2.amzn2023.0.2 amazonlinux 129 k apr-util x86_64 1.6.3-1.amzn2023.0.1 amazonlinux 98 k generic-logos-httpd noarch 18.0.0-12.amzn2023.0.3 amazonlinux 19 k httpd-core x86_64 2.4.54-3.amzn2023.0.4 amazonlinux 1.3 M httpd-filesystem noarch 2.4.54-3.amzn2023.0.4 amazonlinux 13 k httpd-tools x86_64 2.4.54-3.amzn2023.0.4 amazonlinux 80 k libbrotli x86_64 1.0.9-4.amzn2023.0.2 amazonlinux 315 k mailcap noarch 2.1.49-3.amzn2023.0.3 amazonlinux 33 k Installing weak dependencies: apr-util-openssl x86_64 1.6.3-1.amzn2023.0.1 amazonlinux 17 k mod_http2 x86_64 1.15.24-1.amzn2023.0.3 amazonlinux 152 k mod_lua x86_64 2.4.54-3.amzn2023.0.4 amazonlinux 60 k Transaction Summary ==================================================================== Install 12 Packages Total download size: 2.3 M Installed size: 6.8 M Downloading Packages: (1/12): apr-util-openssl-1.6.3-1.am 212 kB/s | 17 kB 00:00 (2/12): apr-1.7.2-2.amzn2023.0.2.x8 1.1 MB/s | 129 kB 00:00 (3/12): httpd-core-2.4.54-3.amzn202 8.9 MB/s | 1.3 MB 00:00 (4/12): mod_http2-1.15.24-1.amzn202 1.9 MB/s | 152 kB 00:00 (5/12): apr-util-1.6.3-1.amzn2023.0 1.7 MB/s | 98 kB 00:00 (6/12): mod_lua-2.4.54-3.amzn2023.0 1.4 MB/s | 60 kB 00:00 (7/12): httpd-2.4.54-3.amzn2023.0.4 1.5 MB/s | 46 kB 00:00 (8/12): libbrotli-1.0.9-4.amzn2023. 4.4 MB/s | 315 kB 00:00 (9/12): mailcap-2.1.49-3.amzn2023.0 753 kB/s | 33 kB 00:00 (10/12): httpd-tools-2.4.54-3.amzn2 978 kB/s | 80 kB 00:00 (11/12): httpd-filesystem-2.4.54-3. 210 kB/s | 13 kB 00:00 (12/12): generic-logos-httpd-18.0.0 439 kB/s | 19 kB 00:00 -------------------------------------------------------------------- Total 6.6 MB/s | 2.3 MB 00:00 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : apr-1.7.2-2.amzn2023.0.2.x86_64 1/12 Installing : apr-util-openssl-1.6.3-1.amzn2023.0.1. 2/12 Installing : apr-util-1.6.3-1.amzn2023.0.1.x86_64 3/12 Installing : mailcap-2.1.49-3.amzn2023.0.3.noarch 4/12 Installing : httpd-tools-2.4.54-3.amzn2023.0.4.x86_ 5/12 Installing : generic-logos-httpd-18.0.0-12.amzn2023 6/12 Running scriptlet: httpd-filesystem-2.4.54-3.amzn2023.0.4 7/12 Installing : httpd-filesystem-2.4.54-3.amzn2023.0.4 7/12 Installing : httpd-core-2.4.54-3.amzn2023.0.4.x86_6 8/12 Installing : mod_http2-1.15.24-1.amzn2023.0.3.x86_6 9/12 Installing : libbrotli-1.0.9-4.amzn2023.0.2.x86_64 10/12 Installing : mod_lua-2.4.54-3.amzn2023.0.4.x86_64 11/12 Installing : httpd-2.4.54-3.amzn2023.0.4.x86_64 12/12 Running scriptlet: httpd-2.4.54-3.amzn2023.0.4.x86_64 12/12 Verifying : apr-1.7.2-2.amzn2023.0.2.x86_64 1/12 Verifying : apr-util-openssl-1.6.3-1.amzn2023.0.1. 2/12 Verifying : httpd-core-2.4.54-3.amzn2023.0.4.x86_6 3/12 Verifying : mod_http2-1.15.24-1.amzn2023.0.3.x86_6 4/12 Verifying : apr-util-1.6.3-1.amzn2023.0.1.x86_64 5/12 Verifying : mod_lua-2.4.54-3.amzn2023.0.4.x86_64 6/12 Verifying : libbrotli-1.0.9-4.amzn2023.0.2.x86_64 7/12 Verifying : httpd-2.4.54-3.amzn2023.0.4.x86_64 8/12 Verifying : httpd-tools-2.4.54-3.amzn2023.0.4.x86_ 9/12 Verifying : mailcap-2.1.49-3.amzn2023.0.3.noarch 10/12 Verifying : httpd-filesystem-2.4.54-3.amzn2023.0.4 11/12 Verifying : generic-logos-httpd-18.0.0-12.amzn2023 12/12 Installed: apr-1.7.2-2.amzn2023.0.2.x86_64 apr-util-1.6.3-1.amzn2023.0.1.x86_64 apr-util-openssl-1.6.3-1.amzn2023.0.1.x86_64 generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch httpd-2.4.54-3.amzn2023.0.4.x86_64 httpd-core-2.4.54-3.amzn2023.0.4.x86_64 httpd-filesystem-2.4.54-3.amzn2023.0.4.noarch httpd-tools-2.4.54-3.amzn2023.0.4.x86_64 libbrotli-1.0.9-4.amzn2023.0.2.x86_64 mailcap-2.1.49-3.amzn2023.0.3.noarch mod_http2-1.15.24-1.amzn2023.0.3.x86_64 mod_lua-2.4.54-3.amzn2023.0.4.x86_64 Complete!
新增、啟用或停用新儲存庫
若要使用 DNF
套件管理系統從不同的儲存庫安裝套件,您需要為 /etc/dnf/dnf.conf
檔案或其自身位於
目錄中的 repository.repo
/etc/yum.repos.d
檔案新增儲存庫的資訊。您可以手動執行此作業。但是,大多數 DNF
儲存庫會在其儲存庫 URL 中提供自身的
檔案。repository.repo
注意
目前沒有可新增至 AL2023 的其他儲存庫。這可能會在未來改變。此外,您可以編寫自有套件,並將這些套件提供給 AL2023 企業環境。您必須先新增並啟用儲存套件的儲存庫,才能使用套件。
若要了解目前啟用的儲存庫,可以執行以下命令:
$
dnf repolist all --verbose
Loaded plugins: builddep, changelog, config-manager, copr, debug, debuginfo-install, download, generate_completion_cache, groups-manager, needs-restarting, playground, release-notification, repoclosure, repodiff, repograph, repomanage, reposync, supportinfo DNF version: 4.12.0 cachedir: /var/cache/dnf Last metadata expiration check: 0:00:02 ago on Wed Mar 1 23:40:15 2023. Repo-id : amazonlinux Repo-name : Amazon Linux 2023 repository Repo-status : enabled Repo-revision : 1677203368 Repo-updated : Fri Feb 24 01:49:28 2023 Repo-pkgs : 12632 Repo-available-pkgs: 12632 Repo-size : 12 G Repo-mirrors : https://al2023-repos-us-west-2-de612dc2.s3.dualstack.us-west-2.amazonaws.com/core/mirrors/2023.0.20230222/x86_64/mirror.list Repo-baseurl : https://al2023-repos-us-west-2-de612dc2.s3.dualstack.us-west-2.amazonaws.com/core/guids/cf9296325a6c46ff40c775a8e2d632c4c3fd9d9164014ce3304715d61b90ca8e/x86_64/ : (0 more) Repo-expire : 172800 second(s) (last: Wed Mar 1 23:40:15 : 2023) Repo-filename : /etc/yum.repos.d/amazonlinux.repo Repo-id : amazonlinux-debuginfo Repo-name : Amazon Linux 2023 repository - Debug Repo-status : disabled Repo-mirrors : https://al2023-repos-us-west-2-de612dc2.s3.dualstack.us-west-2.amazonaws.com/core/mirrors/2023.0.20230222/debuginfo/x86_64/mirror.list Repo-expire : 21600 second(s) (last: unknown) Repo-filename : /etc/yum.repos.d/amazonlinux.repo Repo-id : amazonlinux-source Repo-name : Amazon Linux 2023 repository - Source packages Repo-status : disabled Repo-mirrors : https://al2023-repos-us-west-2-de612dc2.s3.dualstack.us-west-2.amazonaws.com/core/mirrors/2023.0.20230222/SRPMS/mirror.list Repo-expire : 21600 second(s) (last: unknown) Repo-filename : /etc/yum.repos.d/amazonlinux.repo Repo-id : kernel-livepatch Repo-name : Amazon Linux 2023 Kernel Livepatch repository Repo-status : disabled Repo-mirrors : https://al2023-repos-us-west-2-de612dc2.s3.dualstack.us-west-2.amazonaws.com/kernel-livepatch/mirrors/al2023/x86_64/mirror.list Repo-expire : 172800 second(s) (last: unknown) Repo-filename : /etc/yum.repos.d/kernel-livepatch.repo Repo-id : kernel-livepatch-source Repo-name : Amazon Linux 2023 Kernel Livepatch repository - : Source packages Repo-status : disabled Repo-mirrors : https://al2023-repos-us-west-2-de612dc2.s3.dualstack.us-west-2.amazonaws.com/kernel-livepatch/mirrors/al2023/SRPMS/mirror.list Repo-expire : 21600 second(s) (last: unknown) Repo-filename : /etc/yum.repos.d/kernel-livepatch.repo Total packages: 12632
注意
如果您未新增 --verbose
選項旗標,輸出只會包含 Repo-id
、Repo-name
和 Repo-status
資訊。
若要將 yum
儲存庫新增至 /etc/yum.repos.d
目錄:
-
尋找
.repo
檔案的位置。在此範例中,.repo
檔案位於
。https://www.example.com/repository.repo
-
使用
dnf config-manager
命令新增儲存庫。
$
sudo dnf config-manager --add-repo
https://www.example.com/repository.repo
Loaded plugins: priorities, update-motd, upgrade-helper adding repo from:
https://www.example.com/repository.repo
grabbing filehttps://www.example.com/repository.repo
to /etc/yum.repos.d/repository.repo
repository.repo
| 4.0 kB 00:00 repo saved to /etc/yum.repos.d/repository.repo
在您安裝儲存庫後,您必須啟用它,如下一個程序中所說明。
若要在 /etc/yum.repos.d
中啟用 yum
儲存庫,請使用有 --enable
旗標和儲存庫
名稱的 dnf config-manager
命令。
$
sudo dnf config-manager --enable
repository
注意
若要停用儲存庫,請使用相同的命令語法,但在命令中以 --disable
取代 --enable
。
使用 cloud-init 新增儲存庫
除了使用上一個方法新增儲存庫外,您還可以使用 cloud-init
架構來新增儲存庫。
若要新增套件儲存庫,建議您使用下列範本。請考慮在本機儲存此檔案。
#cloud-config yum_repos: repository.repo: baseurl: https://www.example.com/ enabled: true gpgcheck: true gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EXAMPLE name: Example Repository
注意
使用 cloud-init
的其中一個優點是您可以在設定檔案中加入 packages:
部分。在本節中,您可以加入要安裝的套件名稱。您可以從預設儲存庫或在 cloud-config
檔案中新增的新儲存庫安裝套件。
如需 YAML 檔案結構的詳細資訊,請參閱 cloud-init
文件中的新增 YUM 儲存庫
設定 YAML 格式檔案後,您可以在 cloud-init
的 AWS CLI架構中執行。務必加入 --userdata
選項和 .yml
檔案的名稱,以呼叫所需的操作。
$
aws ec2 run-instances \ --image-id \ resolve:ssm:/aws/service/ami-amazon-linux-latest/
al2023-ami-kernel-default-x86_64
\ --instance-typem5.xlarge
\ --regionus-east-1
\ --key-nameaws-key-us-east-1
\ --security-group-idssg-004a7650
\ --user-data file://cloud-config.yml