[转帖]如何在 CentOS 中添加、启用和禁用一个仓库

如何,centos,添加,启用,禁用,一个,仓库 · 浏览次数 : 0

小编点评

** 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” 仓库是否被禁用。

正文

https://linux.cn/article-10219-1.html

yum repolist
yum-config-manager --enable --disable

 

在基于 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 系统:

  1. # yum repolist
  2. Loaded plugins: fastestmirror, security
  3. Loading mirror speeds from cached hostfile
  4. repo id repo name status
  5. base CentOS-6 - Base 6,706
  6. extras CentOS-6 - Extras 53
  7. updates CentOS-6 - Updates 1,255
  8. repolist: 8,014

对于 Fedora 系统:

  1. # dnf repolist

如何在系统中添加一个新仓库

每个仓库通常都提供自己的 .repo 文件。要将此类仓库添加到系统中,使用 root 用户运行以下命令。在我们的例子中将添加 EPEL 仓库 和 IUS 社区仓库,见下文。

但是没有 .repo 文件可用于这些仓库。因此,我们使用以下方法进行安装。

对于 EPEL 仓库,因为它可以从 CentOS 额外仓库获得,所以运行以下命令来安装它。

  1. # yum install epel-release -y

对于 IUS 社区仓库,运行以下 bash 脚本来安装。

  1. # curl 'https://setup.ius.io/' -o setup-ius.sh
  2. # sh setup-ius.sh

如果你有 .repo 文件,在 RHEL/CentOS/OEL 中,只需运行以下命令来添加一个仓库。

  1. # yum-config-manager --add-repo http://www.example.com/example.repo
  2. Loaded plugins: product-id, refresh-packagekit, subscription-manager
  3. adding repo from: http://www.example.com/example.repo
  4. grabbing file http://www.example.com/example.repo to /etc/yum.repos.d/example.repo
  5. example.repo | 413 B 00:00
  6. repo saved to /etc/yum.repos.d/example.repo

对于 Fedora 系统,运行以下命令来添加一个仓库:

  1. # dnf config-manager --add-repo http://www.example.com/example.repo
  2. adding repo from: http://www.example.com/example.repo

如果在添加这些仓库之后运行 yum repolist 命令,你就可以看到新添加的仓库了。Yes,我看到了。

注意:每当运行 yum repolist 命令时,该命令会自动从相应的仓库获取更新,并将缓存保存在本地系统中。

  1. # yum repolist
  2. Loaded plugins: fastestmirror, security
  3. Loading mirror speeds from cached hostfile
  4. epel/metalink | 6.1 kB 00:00
  5. * epel: epel.mirror.constant.com
  6. * ius: ius.mirror.constant.com
  7. ius | 2.3 kB 00:00
  8. repo id repo name status
  9. base CentOS-6 - Base 6,706
  10. epel Extra Packages for Enterprise Linux 6 - x86_64 12,505
  11. extras CentOS-6 - Extras 53
  12. ius IUS Community Packages for Enterprise Linux 6 - x86_64 390
  13. updates CentOS-6 - Updates 1,255
  14. repolist: 20,909

每个仓库都有多个渠道,比如测试(Testing)、开发(Dev)和存档(Archive)等。通过导航到仓库文件位置,你可以更好地理解这一点。

  1. # ls -lh /etc/yum.repos.d
  2. total 64K
  3. -rw-r--r-- 1 root root 2.0K Apr 12 02:44 CentOS-Base.repo
  4. -rw-r--r-- 1 root root 647 Apr 12 02:44 CentOS-Debuginfo.repo
  5. -rw-r--r-- 1 root root 289 Apr 12 02:44 CentOS-fasttrack.repo
  6. -rw-r--r-- 1 root root 630 Apr 12 02:44 CentOS-Media.repo
  7. -rw-r--r-- 1 root root 916 May 18 11:07 CentOS-SCLo-scl.repo
  8. -rw-r--r-- 1 root root 892 May 18 10:36 CentOS-SCLo-scl-rh.repo
  9. -rw-r--r-- 1 root root 6.2K Apr 12 02:44 CentOS-Vault.repo
  10. -rw-r--r-- 1 root root 7.9K Apr 12 02:44 CentOS-Vault.repo.rpmnew
  11. -rw-r--r-- 1 root root 957 May 18 10:41 epel.repo
  12. -rw-r--r-- 1 root root 1.1K Nov 4 2012 epel-testing.repo
  13. -rw-r--r-- 1 root root 1.2K Feb 23 2017 ius-archive.repo
  14. -rw-r--r-- 1 root root 1.2K Feb 23 2017 ius-dev.repo
  15. -rw-r--r-- 1 root root 1.1K May 18 10:41 ius.repo
  16. -rw-r--r-- 1 root root 1.2K Feb 23 2017 ius-testing.repo

如何在系统中启用一个仓库

当你在默认情况下添加一个新仓库时,它将启用它们的稳定仓库,这就是为什么我们在运行 yum repolist 命令时获取了仓库信息。在某些情况下,如果你希望启用它们的测试、开发或存档仓库,使用以下命令。另外,我们还可以使用此命令启用任何禁用的仓库。

为了验证这一点,我们将启用 epel-testing.repo,运行下面的命令:

  1. # yum-config-manager --enable epel-testing
  2. Loaded plugins: fastestmirror
  3. ==================================================================================== repo: epel-testing =====================================================================================
  4. [epel-testing]
  5. bandwidth = 0
  6. base_persistdir = /var/lib/yum/repos/x86_64/6
  7. baseurl =
  8. cache = 0
  9. cachedir = /var/cache/yum/x86_64/6/epel-testing
  10. cost = 1000
  11. enabled = 1
  12. enablegroups = True
  13. exclude =
  14. failovermethod = priority
  15. ftp_disable_epsv = False
  16. gpgcadir = /var/lib/yum/repos/x86_64/6/epel-testing/gpgcadir
  17. gpgcakey =
  18. gpgcheck = True
  19. gpgdir = /var/lib/yum/repos/x86_64/6/epel-testing/gpgdir
  20. gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
  21. hdrdir = /var/cache/yum/x86_64/6/epel-testing/headers
  22. http_caching = all
  23. includepkgs =
  24. keepalive = True
  25. mdpolicy = group:primary
  26. mediaid =
  27. metadata_expire = 21600
  28. metalink =
  29. mirrorlist = https://mirrors.fedoraproject.org/metalink?repo=testing-epel6&arch=x86_64
  30. mirrorlist_expire = 86400
  31. name = Extra Packages for Enterprise Linux 6 - Testing - x86_64
  32. old_base_cache_dir =
  33. password =
  34. persistdir = /var/lib/yum/repos/x86_64/6/epel-testing
  35. pkgdir = /var/cache/yum/x86_64/6/epel-testing/packages
  36. proxy = False
  37. proxy_dict =
  38. proxy_password =
  39. proxy_username =
  40. repo_gpgcheck = False
  41. retries = 10
  42. skip_if_unavailable = False
  43. ssl_check_cert_permissions = True
  44. sslcacert =
  45. sslclientcert =
  46. sslclientkey =
  47. sslverify = True
  48. throttle = 0
  49. timeout = 30.0
  50. username =

运行 yum repolist 命令来检查是否启用了 “epel-testing”。它被启用了,我可以从列表中看到它。

  1. # yum repolist
  2. Loaded plugins: fastestmirror, security
  3. Determining fastest mirrors
  4. epel/metalink | 18 kB 00:00
  5. epel-testing/metalink | 17 kB 00:00
  6. * epel: mirror.us.leaseweb.net
  7. * epel-testing: mirror.us.leaseweb.net
  8. * ius: mirror.team-cymru.com
  9. base | 3.7 kB 00:00
  10. centos-sclo-sclo | 2.9 kB 00:00
  11. epel | 4.7 kB 00:00
  12. epel/primary_db | 6.0 MB 00:00
  13. epel-testing | 4.7 kB 00:00
  14. epel-testing/primary_db | 368 kB 00:00
  15. extras | 3.4 kB 00:00
  16. ius | 2.3 kB 00:00
  17. ius/primary_db | 216 kB 00:00
  18. updates | 3.4 kB 00:00
  19. updates/primary_db | 8.1 MB 00:00 ...
  20. repo id repo name status
  21. base CentOS-6 - Base 6,706
  22. centos-sclo-sclo CentOS-6 - SCLo sclo 495
  23. epel Extra Packages for Enterprise Linux 6 - x86_64 12,509
  24. epel-testing Extra Packages for Enterprise Linux 6 - Testing - x86_64 809
  25. extras CentOS-6 - Extras 53
  26. ius IUS Community Packages for Enterprise Linux 6 - x86_64 390
  27. updates CentOS-6 - Updates 1,288
  28. repolist: 22,250

如果你想同时启用多个仓库,使用以下格式。这个命令将启用 epel、epel-testing 和 ius 仓库:

  1. # yum-config-manager --enable epel epel-testing ius

对于 Fedora 系统,运行下面的命令来启用仓库:

  1. # dnf config-manager --set-enabled epel-testing

如何在系统中禁用一个仓库

无论何时你在默认情况下添加一个新的仓库,它都会启用它们的稳定仓库,这就是为什么我们在运行 yum repolist 命令时获取了仓库信息。如果你不想使用仓库,那么可以通过下面的命令来禁用它。

为了验证这点,我们将要禁用 epel-testing.repo 和 ius.repo,运行以下命令:

  1. # yum-config-manager --disable epel-testing ius
  2. Loaded plugins: fastestmirror
  3. ==================================================================================== repo: epel-testing =====================================================================================
  4. [epel-testing]
  5. bandwidth = 0
  6. base_persistdir = /var/lib/yum/repos/x86_64/6
  7. baseurl =
  8. cache = 0
  9. cachedir = /var/cache/yum/x86_64/6/epel-testing
  10. cost = 1000
  11. enabled = 0
  12. enablegroups = True
  13. exclude =
  14. failovermethod = priority
  15. ftp_disable_epsv = False
  16. gpgcadir = /var/lib/yum/repos/x86_64/6/epel-testing/gpgcadir
  17. gpgcakey =
  18. gpgcheck = True
  19. gpgdir = /var/lib/yum/repos/x86_64/6/epel-testing/gpgdir
  20. gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
  21. hdrdir = /var/cache/yum/x86_64/6/epel-testing/headers
  22. http_caching = all
  23. includepkgs =
  24. keepalive = True
  25. mdpolicy = group:primary
  26. mediaid =
  27. metadata_expire = 21600
  28. metalink =
  29. mirrorlist = https://mirrors.fedoraproject.org/metalink?repo=testing-epel6&arch=x86_64
  30. mirrorlist_expire = 86400
  31. name = Extra Packages for Enterprise Linux 6 - Testing - x86_64
  32. old_base_cache_dir =
  33. password =
  34. persistdir = /var/lib/yum/repos/x86_64/6/epel-testing
  35. pkgdir = /var/cache/yum/x86_64/6/epel-testing/packages
  36. proxy = False
  37. proxy_dict =
  38. proxy_password =
  39. proxy_username =
  40. repo_gpgcheck = False
  41. retries = 10
  42. skip_if_unavailable = False
  43. ssl_check_cert_permissions = True
  44. sslcacert =
  45. sslclientcert =
  46. sslclientkey =
  47. sslverify = True
  48. throttle = 0
  49. timeout = 30.0
  50. username =
  51. ========================================================================================= repo: ius =========================================================================================
  52. [ius]
  53. bandwidth = 0
  54. base_persistdir = /var/lib/yum/repos/x86_64/6
  55. baseurl =
  56. cache = 0
  57. cachedir = /var/cache/yum/x86_64/6/ius
  58. cost = 1000
  59. enabled = 0
  60. enablegroups = True
  61. exclude =
  62. failovermethod = priority
  63. ftp_disable_epsv = False
  64. gpgcadir = /var/lib/yum/repos/x86_64/6/ius/gpgcadir
  65. gpgcakey =
  66. gpgcheck = True
  67. gpgdir = /var/lib/yum/repos/x86_64/6/ius/gpgdir
  68. gpgkey = file:///etc/pki/rpm-gpg/IUS-COMMUNITY-GPG-KEY
  69. hdrdir = /var/cache/yum/x86_64/6/ius/headers
  70. http_caching = all
  71. includepkgs =
  72. keepalive = True
  73. mdpolicy = group:primary
  74. mediaid =
  75. metadata_expire = 21600
  76. metalink =
  77. mirrorlist = https://mirrors.iuscommunity.org/mirrorlist?repo=ius-centos6&arch=x86_64&protocol=http
  78. mirrorlist_expire = 86400
  79. name = IUS Community Packages for Enterprise Linux 6 - x86_64
  80. old_base_cache_dir =
  81. password =
  82. persistdir = /var/lib/yum/repos/x86_64/6/ius
  83. pkgdir = /var/cache/yum/x86_64/6/ius/packages
  84. proxy = False
  85. proxy_dict =
  86. proxy_password =
  87. proxy_username =
  88. repo_gpgcheck = False
  89. retries = 10
  90. skip_if_unavailable = False
  91. ssl_check_cert_permissions = True
  92. sslcacert =
  93. sslclientcert =
  94. sslclientkey =
  95. sslverify = True
  96. throttle = 0
  97. timeout = 30.0
  98. username =

运行 yum repolist 命令检查 “epel-testing” 和 “ius” 仓库是否被禁用。它被禁用了,我不能看到那些仓库,除了 “epel”。

  1. # yum repolist
  2. Loaded plugins: fastestmirror, security
  3. Loading mirror speeds from cached hostfile
  4. * epel: mirror.us.leaseweb.net
  5. repo id repo name status
  6. base CentOS-6 - Base 6,706
  7. centos-sclo-sclo CentOS-6 - SCLo sclo 495
  8. epel Extra Packages for Enterprise Linux 6 - x86_64 12,505
  9. extras CentOS-6 - Extras 53
  10. updates CentOS-6 - Updates 1,288
  11. repolist: 21,051

或者,我们可以运行以下命令查看详细信息:

  1. # yum repolist all | grep "epel*\|ius*"
  2. * epel: mirror.steadfast.net
  3. epel Extra Packages for Enterprise Linux 6 enabled: 12,509
  4. epel-debuginfo Extra Packages for Enterprise Linux 6 disabled
  5. epel-source Extra Packages for Enterprise Linux 6 disabled
  6. epel-testing Extra Packages for Enterprise Linux 6 disabled
  7. epel-testing-debuginfo Extra Packages for Enterprise Linux 6 disabled
  8. epel-testing-source Extra Packages for Enterprise Linux 6 disabled
  9. ius IUS Community Packages for Enterprise disabled
  10. ius-archive IUS Community Packages for Enterprise disabled
  11. ius-archive-debuginfo IUS Community Packages for Enterprise disabled
  12. ius-archive-source IUS Community Packages for Enterprise disabled
  13. ius-debuginfo IUS Community Packages for Enterprise disabled
  14. ius-dev IUS Community Packages for Enterprise disabled
  15. ius-dev-debuginfo IUS Community Packages for Enterprise disabled
  16. ius-dev-source IUS Community Packages for Enterprise disabled
  17. ius-source IUS Community Packages for Enterprise disabled
  18. ius-testing IUS Community Packages for Enterprise disabled
  19. ius-testing-debuginfo IUS Community Packages for Enterprise disabled
  20. ius-testing-source IUS Community Packages for Enterprise disabled

对于 Fedora 系统,运行以下命令来启用一个仓库:

  1. # dnf config-manager --set-disabled epel-testing

或者,可以通过手动编辑适当的 repo 文件来完成。为此,打开相应的 repo 文件并将值从 enabled=0 改为 enabled=1(启用仓库)或从 enabled=1 变为 enabled=0(禁用仓库)。

即从:

  1. [epel]
  2. name=Extra Packages for Enterprise Linux 6 - $basearch
  3. #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
  4. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
  5. failovermethod=priority
  6. enabled=0
  7. gpgcheck=1
  8. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

改为:

  1. [epel]
  2. name=Extra Packages for Enterprise Linux 6 - $basearch
  3. #baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
  4. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
  5. failovermethod=priority
  6. enabled=1
  7. gpgcheck=1
  8. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

via: https://www.2daygeek.com/how-to-add-enable-disable-a-repository-dnf-yum-config-manager-on-linux/

与[转帖]如何在 CentOS 中添加、启用和禁用一个仓库相似的内容:

[转帖]如何在 CentOS 中添加、启用和禁用一个仓库

https://linux.cn/article-10219-1.htmlyum repolistyum-config-manager --enable --disable 在基于 RPM 的系统上,例如 RHEL、CentOS 等,我们中的许多人使用 yum 包管理器来管理软件的安装、删除、更新、

[转帖]CentOS8完美升级gcc版本方法

https://blog.whsir.com/post-6114.html 在CentOS8系统中,默认gcc版本已经是8.x.x版本,但是在一些场景中,还是需要高版本的gcc,网上一些作死的文章还在复制粘贴的告诉你如何编译升级gcc版本。 之前吴昊也写过CentOS完美升级gcc版本方法:http

[转帖]linux中内核的一个不错的参数somaxconn

最近发现很多内核优化参数都记不住了,写下文章来备记,方便以后查看. 编辑 /etc/sysctl.conf 文件,在里面加入如下内容:(有注释) #设置系统对最大跟踪的TCP连接数的限制(CentOS 5.6无此参数) net.ipv4.ip_conntrack_max = 25000000 #最大

[转帖]如何在CentOS 7上使用Barman备份,恢复和迁移PostgreSQL数据库

http://www.manongjc.com/detail/52-bdglcaimnhmjvkm.html 本文章向大家介绍如何在CentOS 7上使用Barman备份,恢复和迁移PostgreSQL数据库,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的

[转帖]在 CentOS 7 上安装并配置 Python 3.6环境

https://www.jianshu.com/p/b978e46de442 拖了很久没有更新,抱歉啦~ 今天受邀写篇如何在 CentOS 7 上配置 Python 3 环境的文章。往常我都选择直接把我早年写的一篇文章《源码编译MongoDB》丢过去,让他们看其中的源码编译 Python 那一节,不

[转帖]CentOS 7 systemd service 设置limit,不生效问题

https://www.jianshu.com/p/1d02c97f3573 问题简述:Centos7下修改系统的最大文件打开数的时候,对系统启动的进程不生效问题详述:Centos7下需修改系统最大文件打开数为100000,进程数为50000,于是做了如下操作 说 明:此问题只出现在centos7下

[转帖]centos7.6编写自己的启动服务,运行systemctl后卡住了的解决方案

https://www.cnblogs.com/niway/p/15346572.html 问题:centos7.6编写自己的启动服务,运行systemctl后卡住了,表现为当我执行systemctl命令后shell阻塞在那里,没有像平时执行命令那样自动结束(只能自己按Ctrl+C强制结束),情况如

[转帖]The necessary bits to build these optional modules were not found: _uuid _bz2 _curse _curses_panel

在安装Python3.7可能遇到如题的错误,只需安装uuid库就可以 ubuntu下安装uuid链接库 sudo apt-get install uuid-dev CentOS yum install libuuid-devel 对于以下的问题 The necessary bits to build

[转帖]操作系统性能参数调优

https://www.bookstack.cn/read/TiDB-4.0/tune-operating-system.md 本文档仅用于描述如何优化 CentOS 7 的各个子系统。 注意: CentOS 7 操作系统的默认配置适用于中等负载下运行的大多数服务。调整特定子系统的性能可能会对其他子

[转帖]nmcli管理网络 RHEL8和CentOS8怎么重启网络

1. 前言 本文主要讲解如何重启RHEL 8或者CentOS 8网络以及如何解决RHEL8和CentOS8系统的网络管理服务报错,当我们安装好RHEL 8或者 CentOS 8,重启启动网络时,会出现以下报错: # systemctl restart network.service 报错信息如下 F