您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么在CentOS中添加、啟用和禁用一個倉庫”,在日常操作中,相信很多人在怎么在CentOS中添加、啟用和禁用一個倉庫問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么在CentOS中添加、啟用和禁用一個倉庫”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
在基于 RPM 的系統上,例如 RHEL、CentOS 等,我們中的許多人使用 yum 包管理器來管理軟件的安裝、刪除、更新、搜索等。
Linux 發行版的大部分軟件都來自發行版官方倉庫。官方倉庫包含大量免費和開源的應用和軟件。它很容易安裝和使用。
由于一些限制和專有問題,基于 RPM 的發行版在其官方倉庫中沒有提供某些包。另外,出于穩定性考慮,它不會提供***版本的核心包。
為了克服這種情況,我們需要安裝或啟用需要的第三方倉庫。對于基于 RPM 的系統,有許多第三方倉庫可用,但所建議使用的倉庫很少,因為這些不會替換大量的基礎包。
這可以在基于 RPM 的系統上完成,比如 RHEL, CentOS, OEL, Fedora 等。
Fedora 系統使用 dnf config-manager [options] [section …]
其它基于 RPM 的系統使用 yum-config-manager [options] [section …]
只需運行以下命令即可檢查系統上啟用的倉庫列表。
對于 CentOS/RHEL/OLE 系統:
# yum repolistLoaded plugins: fastestmirror, securityLoading mirror speeds from cached hostfilerepo id repo name statusbase CentOS-6 - Base 6,706extras CentOS-6 - Extras 53updates CentOS-6 - Updates 1,255repolist: 8,014
對于 Fedora 系統:
# dnf repolist
每個倉庫通常都提供自己的 .repo
文件。要將此類倉庫添加到系統中,使用 root 用戶運行以下命令。在我們的例子中將添加 EPEL 倉庫 和 IUS 社區倉庫,見下文。
但是沒有 .repo
文件可用于這些倉庫。因此,我們使用以下方法進行安裝。
對于 EPEL 倉庫,因為它可以從 CentOS 額外倉庫獲得,所以運行以下命令來安裝它。
# yum install epel-release -y
對于 IUS 社區倉庫,運行以下 bash 腳本來安裝。
# curl 'https://setup.ius.io/' -o setup-ius.sh# sh setup-ius.sh
如果你有 .repo
文件,在 RHEL/CentOS/OEL 中,只需運行以下命令來添加一個倉庫。
# yum-config-manager --add-repo http://www.example.com/example.repo Loaded plugins: product-id, refresh-packagekit, subscription-manageradding repo from: http://www.example.com/example.repograbbing file http://www.example.com/example.repo to /etc/yum.repos.d/example.repoexample.repo | 413 B 00:00repo saved to /etc/yum.repos.d/example.repo
對于 Fedora 系統,運行以下命令來添加一個倉庫:
# dnf config-manager --add-repo http://www.example.com/example.repoadding repo from: http://www.example.com/example.repo
如果在添加這些倉庫之后運行 yum repolist
命令,你就可以看到新添加的倉庫了。Yes,我看到了。
注意:每當運行 yum repolist
命令時,該命令會自動從相應的倉庫獲取更新,并將緩存保存在本地系統中。
# yum repolist Loaded plugins: fastestmirror, securityLoading mirror speeds from cached hostfileepel/metalink | 6.1 kB 00:00* epel: epel.mirror.constant.com* ius: ius.mirror.constant.comius | 2.3 kB 00:00repo id repo name statusbase CentOS-6 - Base 6,706epel Extra Packages for Enterprise Linux 6 - x86_64 12,505extras CentOS-6 - Extras 53ius IUS Community Packages for Enterprise Linux 6 - x86_64 390updates CentOS-6 - Updates 1,255repolist: 20,909
每個倉庫都有多個渠道,比如測試(Testing)、開發(Dev)和存檔(Archive)等。通過導航到倉庫文件位置,你可以更好地理解這一點。
# ls -lh /etc/yum.repos.dtotal 64K-rw-r--r-- 1 root root 2.0K Apr 12 02:44 CentOS-Base.repo-rw-r--r-- 1 root root 647 Apr 12 02:44 CentOS-Debuginfo.repo-rw-r--r-- 1 root root 289 Apr 12 02:44 CentOS-fasttrack.repo-rw-r--r-- 1 root root 630 Apr 12 02:44 CentOS-Media.repo-rw-r--r-- 1 root root 916 May 18 11:07 CentOS-SCLo-scl.repo-rw-r--r-- 1 root root 892 May 18 10:36 CentOS-SCLo-scl-rh.repo-rw-r--r-- 1 root root 6.2K Apr 12 02:44 CentOS-Vault.repo-rw-r--r-- 1 root root 7.9K Apr 12 02:44 CentOS-Vault.repo.rpmnew-rw-r--r-- 1 root root 957 May 18 10:41 epel.repo-rw-r--r-- 1 root root 1.1K Nov 4 2012 epel-testing.repo-rw-r--r-- 1 root root 1.2K Feb 23 2017 ius-archive.repo-rw-r--r-- 1 root root 1.2K Feb 23 2017 ius-dev.repo-rw-r--r-- 1 root root 1.1K May 18 10:41 ius.repo-rw-r--r-- 1 root root 1.2K Feb 23 2017 ius-testing.repo
當你在默認情況下添加一個新倉庫時,它將啟用它們的穩定倉庫,這就是為什么我們在運行 yum repolist
命令時獲取了倉庫信息。在某些情況下,如果你希望啟用它們的測試、開發或存檔倉庫,使用以下命令。另外,我們還可以使用此命令啟用任何禁用的倉庫。
為了驗證這一點,我們將啟用 epel-testing.repo
,運行下面的命令:
# yum-config-manager --enable epel-testing Loaded plugins: fastestmirror==================================================================================== repo: epel-testing =====================================================================================[epel-testing]bandwidth = 0base_persistdir = /var/lib/yum/repos/x86_64/6baseurl =cache = 0cachedir = /var/cache/yum/x86_64/6/epel-testingcost = 1000enabled = 1enablegroups = Trueexclude =failovermethod = priorityftp_disable_epsv = Falsegpgcadir = /var/lib/yum/repos/x86_64/6/epel-testing/gpgcadirgpgcakey =gpgcheck = Truegpgdir = /var/lib/yum/repos/x86_64/6/epel-testing/gpgdirgpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6hdrdir = /var/cache/yum/x86_64/6/epel-testing/headershttp_caching = allincludepkgs =keepalive = Truemdpolicy = group:primarymediaid =metadata_expire = 21600metalink =mirrorlist = https://mirrors.fedoraproject.org/metalink?repo=testing-epel6&arch=x86_64mirrorlist_expire = 86400name = Extra Packages for Enterprise Linux 6 - Testing - x86_64old_base_cache_dir =password =persistdir = /var/lib/yum/repos/x86_64/6/epel-testingpkgdir = /var/cache/yum/x86_64/6/epel-testing/packagesproxy = Falseproxy_dict =proxy_password =proxy_username =repo_gpgcheck = Falseretries = 10skip_if_unavailable = Falsessl_check_cert_permissions = Truesslcacert =sslclientcert =sslclientkey =sslverify = Truethrottle = 0timeout = 30.0username =
運行 yum repolist
命令來檢查是否啟用了 “epel-testing”。它被啟用了,我可以從列表中看到它。
# yum repolistLoaded plugins: fastestmirror, securityDetermining fastest mirrorsepel/metalink | 18 kB 00:00epel-testing/metalink | 17 kB 00:00 * epel: mirror.us.leaseweb.net * epel-testing: mirror.us.leaseweb.net * ius: mirror.team-cymru.combase | 3.7 kB 00:00centos-sclo-sclo | 2.9 kB 00:00epel | 4.7 kB 00:00epel/primary_db | 6.0 MB 00:00epel-testing | 4.7 kB 00:00epel-testing/primary_db | 368 kB 00:00extras | 3.4 kB 00:00ius | 2.3 kB 00:00ius/primary_db | 216 kB 00:00updates | 3.4 kB 00:00updates/primary_db | 8.1 MB 00:00 ...repo id repo name statusbase CentOS-6 - Base 6,706centos-sclo-sclo CentOS-6 - SCLo sclo 495epel Extra Packages for Enterprise Linux 6 - x86_64 12,509epel-testing Extra Packages for Enterprise Linux 6 - Testing - x86_64 809extras CentOS-6 - Extras 53ius IUS Community Packages for Enterprise Linux 6 - x86_64 390updates CentOS-6 - Updates 1,288repolist: 22,250
如果你想同時啟用多個倉庫,使用以下格式。這個命令將啟用 epel、epel-testing 和 ius 倉庫:
# yum-config-manager --enable epel epel-testing ius
對于 Fedora 系統,運行下面的命令來啟用倉庫:
# dnf config-manager --set-enabled epel-testing
無論何時你在默認情況下添加一個新的倉庫,它都會啟用它們的穩定倉庫,這就是為什么我們在運行 yum repolist
命令時獲取了倉庫信息。如果你不想使用倉庫,那么可以通過下面的命令來禁用它。
為了驗證這點,我們將要禁用 epel-testing.repo
和 ius.repo
,運行以下命令:
# yum-config-manager --disable epel-testing ius Loaded plugins: fastestmirror==================================================================================== repo: epel-testing =====================================================================================[epel-testing]bandwidth = 0base_persistdir = /var/lib/yum/repos/x86_64/6baseurl =cache = 0cachedir = /var/cache/yum/x86_64/6/epel-testingcost = 1000enabled = 0enablegroups = Trueexclude =failovermethod = priorityftp_disable_epsv = Falsegpgcadir = /var/lib/yum/repos/x86_64/6/epel-testing/gpgcadirgpgcakey =gpgcheck = Truegpgdir = /var/lib/yum/repos/x86_64/6/epel-testing/gpgdirgpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6hdrdir = /var/cache/yum/x86_64/6/epel-testing/headershttp_caching = allincludepkgs =keepalive = Truemdpolicy = group:primarymediaid =metadata_expire = 21600metalink =mirrorlist = https://mirrors.fedoraproject.org/metalink?repo=testing-epel6&arch=x86_64mirrorlist_expire = 86400name = Extra Packages for Enterprise Linux 6 - Testing - x86_64old_base_cache_dir =password =persistdir = /var/lib/yum/repos/x86_64/6/epel-testingpkgdir = /var/cache/yum/x86_64/6/epel-testing/packagesproxy = Falseproxy_dict =proxy_password =proxy_username =repo_gpgcheck = Falseretries = 10skip_if_unavailable = Falsessl_check_cert_permissions = Truesslcacert =sslclientcert =sslclientkey =sslverify = Truethrottle = 0timeout = 30.0username = ========================================================================================= repo: ius =========================================================================================[ius]bandwidth = 0base_persistdir = /var/lib/yum/repos/x86_64/6baseurl =cache = 0cachedir = /var/cache/yum/x86_64/6/iuscost = 1000enabled = 0enablegroups = Trueexclude =failovermethod = priorityftp_disable_epsv = Falsegpgcadir = /var/lib/yum/repos/x86_64/6/ius/gpgcadirgpgcakey =gpgcheck = Truegpgdir = /var/lib/yum/repos/x86_64/6/ius/gpgdirgpgkey = file:///etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEYhdrdir = /var/cache/yum/x86_64/6/ius/headershttp_caching = allincludepkgs =keepalive = Truemdpolicy = group:primarymediaid =metadata_expire = 21600metalink =mirrorlist = https://mirrors.iuscommunity.org/mirrorlist?repo=ius-centos6&arch=x86_64&protocol=httpmirrorlist_expire = 86400name = IUS Community Packages for Enterprise Linux 6 - x86_64old_base_cache_dir =password =persistdir = /var/lib/yum/repos/x86_64/6/iuspkgdir = /var/cache/yum/x86_64/6/ius/packagesproxy = Falseproxy_dict =proxy_password =proxy_username =repo_gpgcheck = Falseretries = 10skip_if_unavailable = Falsessl_check_cert_permissions = Truesslcacert =sslclientcert =sslclientkey =sslverify = Truethrottle = 0timeout = 30.0username =
運行 yum repolist
命令檢查 “epel-testing” 和 “ius” 倉庫是否被禁用。它被禁用了,我不能看到那些倉庫,除了 “epel”。
# yum repolistLoaded plugins: fastestmirror, securityLoading mirror speeds from cached hostfile * epel: mirror.us.leaseweb.netrepo id repo name statusbase CentOS-6 - Base 6,706centos-sclo-sclo CentOS-6 - SCLo sclo 495epel Extra Packages for Enterprise Linux 6 - x86_64 12,505extras CentOS-6 - Extras 53updates CentOS-6 - Updates 1,288repolist: 21,051
或者,我們可以運行以下命令查看詳細信息:
# yum repolist all | grep "epel*\|ius*" * epel: mirror.steadfast.netepel Extra Packages for Enterprise Linux 6 enabled: 12,509epel-debuginfo Extra Packages for Enterprise Linux 6 disabledepel-source Extra Packages for Enterprise Linux 6 disabledepel-testing Extra Packages for Enterprise Linux 6 disabledepel-testing-debuginfo Extra Packages for Enterprise Linux 6 disabledepel-testing-source Extra Packages for Enterprise Linux 6 disabledius IUS Community Packages for Enterprise disabledius-archive IUS Community Packages for Enterprise disabledius-archive-debuginfo IUS Community Packages for Enterprise disabledius-archive-source IUS Community Packages for Enterprise disabledius-debuginfo IUS Community Packages for Enterprise disabledius-dev IUS Community Packages for Enterprise disabledius-dev-debuginfo IUS Community Packages for Enterprise disabledius-dev-source IUS Community Packages for Enterprise disabledius-source IUS Community Packages for Enterprise disabledius-testing IUS Community Packages for Enterprise disabledius-testing-debuginfo IUS Community Packages for Enterprise disabledius-testing-source IUS Community Packages for Enterprise disabled
對于 Fedora 系統,運行以下命令來啟用一個倉庫:
# dnf config-manager --set-disabled epel-testing
或者,可以通過手動編輯適當的 repo 文件來完成。為此,打開相應的 repo 文件并將值從 enabled=0
改為 enabled=1
(啟用倉庫)或從 enabled=1
變為 enabled=0
(禁用倉庫)。
即從:
[epel]name=Extra Packages for Enterprise Linux 6 - $basearch#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearchmirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearchfailovermethod=priorityenabled=0gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
改為:
[epel]name=Extra Packages for Enterprise Linux 6 - $basearch#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearchmirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearchfailovermethod=priorityenabled=1gpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
到此,關于“怎么在CentOS中添加、啟用和禁用一個倉庫”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。