Translated message

A translation of this page exists in English.

Warning message

This translation is outdated. For the most up-to-date information, please refer to the English version.

使用 Red Hat Subscription Management 启用或禁用软件仓库

Solution Verified - Updated -

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-Utils 提供的 yum-config-manager:

可以使用 yum-config-manager 命令(由 yum-utils 软件包提供)启用禁用仓库。

注意: 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 Repos


常用的软件仓库

您要启用的软件仓库取决于您需要安装的软件包以及您要使用的产品。对于 RHEL 7 及以下版本,名称通常采用 rhel-<Major Release>-<Product>-rpms 格式。例如,rhel-7-server-rpmsrhel-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 文件。

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