使用 Red Hat Subscription Management 启用或禁用软件仓库
Environment
- Red Hat Enterprise Linux
- Red Hat Subscription Management (RHSM)
Issue
- 如何使用 Red Hat Subscription Manager 启用软件仓库
- 需要使用 Red Hat Subscription Manager 访问软件仓库
- 如何使用 Subscription Manager 禁用软件仓库
- 如何使用 Red Hat Subscription-Manager 订阅子频道
- 如何编辑 /etc/yum.repos.d/redhat.repo 文件?
- 每当 yum 或 subscription-manager 运行时,对 redhat.repo 所做的更改都会被恢复
Resolution
当系统订阅到相关产品时,相关的内容仓库(在授权证书中指定)对于系统可用。内容仓库是基于产品,由内容交付网络提供,它在 rhsm.conf 文件的 baseurl 参数中定义。
列出所有系统可用的软件仓库,包括禁用的软件仓库:
# yum repolist all repo id repo name status rhel-6-server Red Hat Enterprise Linux 6Server enabled rhel-6-server-optional-rpms Red Hat Enterprise Linux 6Server - Optional disabled rhel-6-server-extras Red Hat Enterprise Linux 6Server - Extras disabled
使用 Subscription-Manager
subscription-manager
提供了自己的、用于仅在 redhat.repo 文件中启用和禁用仓库的工具:
查看可用仓库列表:
# subscription-manager repos --list
启用一个特定的红帽软件仓库:
# subscription-manager repos --enable=rhel-6-server-optional-rpms
禁用一个特定的红帽软件仓库:
# subscription-manager repos --disable=rhel-6-server-optional-rpms
使用由 yum-config-manager 提供的 Yum-Utils:
仓库可以通过由 yum-utils
软件包提供的 yum-config-manager
命令 启用或禁用:
备注:yum-config-manager
仅适用于 RHEL 6 及更新的版本
# yum install -y yum-utils # yum-config-manager --enable <repo-id> # yum-config-manager --disable <repo-id>
为单个 yum 事务启用软件仓库
可以使用 --enablerepo=
选项临时启用一个仓库。例如:
# yum install rubygems --enablerepo=rhel-6-server-optional-rpms
注意:如果在禁用的仓库中有一个更新,在重新启用该仓库前,新的更新不会应用于系统。如果一个软件包由基本仓库更新,且需要已禁用的仓库中的更新,则用户可能会遇到依赖项问题
禁用 Subscription-Manager 仓库
当系统使用 Subscription-Manager 进行注册,rhsmcertd 进程会创建一个特殊的 yum 仓库 - redhat.repo。
在某些环境中,维护一个 redhat.repo 文件可能并不是一个理想的情况。如果该仓库没有实际用于订阅,则可能会对内容管理操作造成影响。例如,对于一个断开连接的系统,或使用本地内容镜像的系统。
您可以编辑 Subscription-Manager 配置,将 manage_repos 值设置为 0 来禁用此默认 redhat.repo 仓库。
# subscription-manager config --rhsm.manage_repos=0
更多信息:使用 yum 仓库
常用的软件仓库
您要启用的软件仓库取决于您需要安装的软件包以及您要使用的产品。对于 RHEL 7 及以下版本,名称通常遵循 rhel-
格式。例如 rhel-7-server-rpms
与 rhel-6-workstation-rpms
。
要识别哪个仓库包含一个软件包,您可以在红帽客户门户中使用 Package Browser 找到我们的所有软件包。某些软件包或勘误仅适用于特定的产品,可能不适用于您的产品。您可以搜索产品页的 Packages
标签页来查看适用于您的产品的软件包。
Base Repos | Optional/Development Repos | |
---|---|---|
RHEL 6 | rhel-6-server-rpms | rhel-6-server-optional-rpms |
RHEL 7 | rhel-7-server-rpms | rhel-7-server-optional-rpms |
RHEL 8 | rhel-8-for-x86_64-baseos-rpms rhel-8-for-x86_64-appstream-rpms |
codeready-builder-for-rhel-8-x86_64-rpms |
RHEL 9 | rhel-9-for-x86_64-baseos-rpms rhel-9-for-x86_64-appstream-rpms |
codeready-builder-for-rhel-9-x86_64-rpms |
它们将提供基本系统上使用的最常见的软件包。如果您使用一个不同的基本产品,如 Workstation,将 "server" 替换为 "workstation"。如果您在不同的架构中使用 RHEL 8,这会反映在仓库名称中。
如果您使用更高级的红帽产品,请参阅产品文档来决定需要启用哪些特定仓库。
Root Cause
subscription-manager 维护 redhat.repo 文件。每当运行它或作为 yum 插件运行时,它会将 redhat.repo 设置恢复到最后保存的状态,从而覆盖了所做的所有手动更改。
# head /etc/yum.repos.d/redhat.repo
#
# Certificate-Based Repositories
# Managed by (rhsm) subscription-manager
#
# *** This file is auto-generated. Changes made here will be over-written. ***
# *** Use "subscription-manager repo-override --help" if you wish to make changes. ***
#
# If this file is empty and this system is subscribed consider
# a "yum repolist" to refresh available repos
#
您可以通过在 /etc/rhsm/rhsm.conf 中禁用 "manage_repos",或使用 repo-override 命令修改 redhat.repo 文件来禁用这个行为。
Diagnostic Steps
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments