如何在 RHEL 中使用订阅管理器启用软件仓库
RedHat RHEL 订阅

> 
> 了解如何在 RHEL 中使用订阅管理器来启用软件仓库。 这篇文章还包括了将系统注册到 Red Hat 的步骤、添加订阅和发生错误时的解决方案。
> 
> 
> 


![Enable repository using subscription-manager](/data/attachment/album/201806/12/102117vbr929yzx2m8hmpf.png)


在本文中，我们将逐步介绍如何在刚安装的 RHEL 服务器中启用 Red Hat 软件仓库。


可以利用 `subscription-manager` 命令启用软件仓库，如下所示：



```
root@kerneltalks # subscription-manager repos --enable rhel-6-server-rhv-4-agent-beta-debug-rpms
Error: 'rhel-6-server-rhv-4-agent-beta-debug-rpms' does not match a valid repository ID. Use "subscription-manager repos --list" to see valid repositories.

```

当您的订阅没有配置好时，您会看到上述错误。让我们一步一步地通过 `subscription-manager` 来启用软件仓库。


### 步骤 1：使用 Red Hat 注册您的系统


这里假设您已经安装了新系统并且尚未在 Red Hat 上注册。如果您已经注册了该系统，那么您可以忽略此步骤。


您可以使用下面的命令来检查您的系统是否已在 Red Hat 注册了该订阅：



```
# subscription-manager version
server type: This system is currently not registered.
subscription management server: Unknown
subscription management rules: Unknown
subscription-manager: 1.18.10-1.el6
python-rhsm: 1.18.6-1.el6

```

在这里输出的第一行中，您可以看到该系统未注册。那么，让我们开始注册系统。您需要在 `subscription-manager` 命令中使用 `register` 选项。在这一步需要使用您的 Red Hat 帐户凭证。



```
root@kerneltalks # subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: admin@kerneltalks.com
Password:
Network error, unable to connect to server. Please see /var/log/rhsm/rhsm.log for more information.

```

如果您遇到上述错误，那么表明您的服务器无法连接到 RedHat。检查您的网络连接，或者您能[解决网站名称解析的问题](https://kerneltalks.com/howto/how-to-configure-nameserver-in-linux/)。有时候，即使你能够 ping 通订阅服务器，你也会看到这个错误。这可能是因为您的环境中有代理服务器。在这种情况下，您需要将其详细信息添加到文件 `/etc/rhsm/rhsm.conf` 中。以下详细的代理信息应根据你的环境填充：



```
# an http proxy server to use
 proxy_hostname =

# port for http proxy server
 proxy_port =

# user name for authenticating to an http proxy, if needed
 proxy_user =

# password for basic http proxy auth, if needed
 proxy_password =

```

一旦你完成了这些，通过使用下面的命令重新检查 `subscription-manager` 是否获得了新的代理信息：



```
root@kerneltalks # subscription-manager config
[server]
 hostname = [subscription.rhsm.redhat.com]
 insecure = [0]
 port = [443]
 prefix = [/subscription]
 proxy_hostname = [kerneltalksproxy.abc.com]
 proxy_password = [asdf]
 proxy_port = [3456]
 proxy_user = [user2]
 server_timeout = [180]
 ssl_verify_depth = [3]

[rhsm]
 baseurl = [https://cdn.redhat.com]
 ca_cert_dir = [/etc/rhsm/ca/]
 consumercertdir = [/etc/pki/consumer]
 entitlementcertdir = [/etc/pki/entitlement]
 full_refresh_on_yum = [0]
 manage_repos = [1]
 pluginconfdir = [/etc/rhsm/pluginconf.d]
 plugindir = [/usr/share/rhsm-plugins]
 productcertdir = [/etc/pki/product]
 repo_ca_cert = /etc/rhsm/ca/redhat-uep.pem
 report_package_profile = [1]

[rhsmcertd]
 autoattachinterval = [1440]
 certcheckinterval = [240]

[logging]
 default_log_level = [INFO]

[] - Default value in use

```

现在，请尝试重新注册您的系统。



```
root@kerneltalks # subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: admin@kerneltalks.com
Password:
You must first accept Red Hat's Terms and conditions. Please visit https://www.redhat.com/wapps/tnc/termsack?event[]=signIn . You may have to log out of and back into the Customer Portal in order to see the terms.

```

如果您是第一次将服务器添加到 Red Hat 帐户，您将看到上述错误。转到该 [URL](https://www.redhat.com/wapps/tnc/termsack?event%5B%5D=signIn)并接受条款。回到终端，然后再试一次。



```
oot@kerneltalks # subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: admin@kerneltalks.com
Password:
The system has been registered with ID: xxxxb2-xxxx-xxxx-xxxx-xx8e199xxx

```

Bingo！系统现在已在 Red Hat 上注册。你可以再次用 `version` 选项来验证它。



```
#subscription-managerversionservertype:RedHatSubscriptionManagementsubscriptionmanagementserver:2.0.43-1subscriptionmanagementrules:5.26subscription-manager:1.18.10-1.el6python-rhsm:1.18.6-1.el6" decode="true"  ]root@kerneltalks # subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 2.0.43-1
subscription management rules: 5.26
subscription-manager: 1.18.10-1.el6
python-rhsm: 1.18.6-1.el6

```

### 步骤 2：将订阅添加到您的服务器


首先尝试列出软件仓库。您将无法列出任何内容，因为我们尚未在我们的服务器中添加任何订阅。



```
root@kerneltalks # subscription-manager repos --list
This system has no repositories available through subscriptions.

```

正如您所看到 `subscription-manager` 找不到任何软件仓库，您需要将订阅添加到您的服务器上。一旦订阅被添加，`subscription-manager` 将能够列出下列的软件仓库。


要添加订阅，请先使用以下命令检查服务器的所有可用订阅：



```
root@kerneltalks # subscription-manager list --available
+-------------------------------------------+
Available Subscriptions
+-------------------------------------------+
Subscription Name: Red Hat Enterprise Linux for Virtual Datacenters, Standard
Provides: Red Hat Beta
Red Hat Software Collections (for RHEL Server)
Red Hat Enterprise Linux Atomic Host Beta
Oracle Java (for RHEL Server)
Red Hat Enterprise Linux Server
dotNET on RHEL (for RHEL Server)
Red Hat Enterprise Linux Atomic Host
Red Hat Software Collections Beta (for RHEL Server)
Red Hat Developer Tools Beta (for RHEL Server)
Red Hat Developer Toolset (for RHEL Server)
Red Hat Developer Tools (for RHEL Server)
SKU: RH00050
Contract: xxxxxxxx
Pool ID: 8a85f98c6011059f0160110a2ae6000f
Provides Management: Yes
Available: Unlimited
Suggested: 0
Service Level: Standard
Service Type: L1-L3
Subscription Type: Stackable (Temporary)
Ends: 12/01/2018
System Type: Virtual

```

您将获得可用于您的服务器的此类订阅的软件仓库列表。您需要阅读它提供的内容并记下对您有用或需要的订阅的 `Pool ID`。


现在，使用 pool ID 将订阅添加到您的服务器。



```
# subscription-manager attach --pool=8a85f98c6011059f0160110a2ae6000f
Successfully attached a subscription for: Red Hat Enterprise Linux for Virtual Datacenters, Standard

```

如果您不确定选择哪一个，则可以使用下面的命令自动地添加最适合您的服务器的订阅：



```
root@kerneltalks # subscription-manager attach --auto
Installed Product Current Status:
Product Name: Red Hat Enterprise Linux Server
Status: Subscribed

```

接下来是最后一步启用软件仓库。


### 步骤 3：启用软件仓库


现在您将能够启用软件仓库，该软件仓库在您的附加订阅下可用。



```
root@kerneltalks # subscription-manager repos --enable rhel-6-server-rhv-4-agent-beta-debug-rpms
Repository 'rhel-6-server-rhv-4-agent-beta-debug-rpms' is enabled for this system.

```

到这里，您已经完成了。您可以[用 yum 命令列出软件仓库](https://kerneltalks.com/howto/how-to-list-yum-repositories-in-rhel-centos/)并确认。




---


via: <https://kerneltalks.com/howto/how-to-enable-repository-using-subscription-manager-in-rhel/>


作者：[kerneltalks](https://kerneltalks.com) 译者：[S9mtAt](https://github.com/S9mtAt) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
*Learn how to enable repository using subscription-manager in RHEL. The article also includes steps to register system with Red Hat, attach subscription and errors along with resolutions.*

![](https://z5.kerneltalks.com/wp-content/uploads/2020/06/enable-repository-in-rhel.png)

In this article, we will walk you through step by step process to enable Red Hat repository in RHEL fresh installed server.

The repository can be enabled using `subscription-manager`

command like below –

```
root@kerneltalks # subscription-manager repos --enable rhel-6-server-rhv-4-agent-beta-debug-rpms
Error: 'rhel-6-server-rhv-4-agent-beta-debug-rpms' does not match a valid repository ID. Use "subscription-manager repos --list" to see valid repositories.
```

You will see the above error when your subscription is not in place. Let’s go through step by step procedure to enable repositories via `subscription-manager`


### Step 1 : Register your system with Red Hat

We are considering you have a freshly installed system and it’s not yet registered with Red Hat. If you have a registered system already then you can ignore this step.

You can check if your system is registered with Red Hat for the subscription using below command –

```
# subscription-manager version
server type: This system is currently not registered.
subscription management server: Unknown
subscription management rules: Unknown
subscription-manager: 1.18.10-1.el6
python-rhsm: 1.18.6-1.el6
```

Here, in the first line of output, you can see the system is not registered. So, let’s start with the registering system. You need to use the `subscription-manager`

command with `register`

switch. You need to use your Red Hat account credentials here.

```
root@kerneltalks # subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: admin@kerneltalks.com
Password:
Network error, unable to connect to server. Please see /var/log/rhsm/rhsm.log for more information.
```

If you are getting above error then your server is not able to reach RedHat. Check internet connection & if you are able to [resolve site name](https://kerneltalks.com/howto/how-to-configure-nameserver-in-linux/)s. Sometimes even if you are able to ping the subscription server, you will see this error. This might be because you have the proxy server in your environment. In such a case, you need to add its details in file `/etc/rhsm/rhsm.conf`

. Below proxy details should be populated :

```
# an http proxy server to use
proxy_hostname =
# port for http proxy server
proxy_port =
# user name for authenticating to an http proxy, if needed
proxy_user =
# password for basic http proxy auth, if needed
proxy_password =
```

Once you are done, recheck if `subscription-manager`

taken up new proxy details by using below command –

```
root@kerneltalks # subscription-manager config
[server]
hostname = [subscription.rhsm.redhat.com]
insecure = [0]
port = [443]
prefix = [/subscription]
proxy_hostname = [kerneltalksproxy.abc.com]
proxy_password = [asdf]
proxy_port = [3456]
proxy_user = [user2]
server_timeout = [180]
ssl_verify_depth = [3]
[rhsm]
baseurl = [https://cdn.redhat.com]
ca_cert_dir = [/etc/rhsm/ca/]
consumercertdir = [/etc/pki/consumer]
entitlementcertdir = [/etc/pki/entitlement]
full_refresh_on_yum = [0]
manage_repos = [1]
pluginconfdir = [/etc/rhsm/pluginconf.d]
plugindir = [/usr/share/rhsm-plugins]
productcertdir = [/etc/pki/product]
repo_ca_cert = /etc/rhsm/ca/redhat-uep.pem
report_package_profile = [1]
[rhsmcertd]
autoattachinterval = [1440]
certcheckinterval = [240]
[logging]
default_log_level = [INFO]
[] - Default value in use
```

Now, try registering your system again.

```
root@kerneltalks # subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: admin@kerneltalks.com
Password:
You must first accept Red Hat's Terms and conditions. Please visit https://www.redhat.com/wapps/tnc/termsack?event[]=signIn . You may have to log out of and back into the Customer Portal in order to see the terms.
```

You will see the above error if you are adding the server to your Red Hat account for the first time. Go to the [URL ](https://www.redhat.com/wapps/tnc/termsack?event[]=signIn)and accept the terms. Come back to the terminal and try again.

```
root@kerneltalks # subscription-manager register
Registering to: subscription.rhsm.redhat.com:443/subscription
Username: admin@kerneltalks.com
Password:
The system has been registered with ID: xxxxb2-xxxx-xxxx-xxxx-xx8e199xxx
```

Bingo! The system is registered with Red Hat now. You can again verify it with `version`

switch.

```
root@kerneltalks # subscription-manager version
server type: Red Hat Subscription Management
subscription management server: 2.0.43-1
subscription management rules: 5.26
subscription-manager: 1.18.10-1.el6
python-rhsm: 1.18.6-1.el6
```

### Step 2: Attach subscription to your server

First, try to list repositories. You won’t be able to list any since we haven’t attached any subscription to our server yet.

```
root@kerneltalks # subscription-manager repos --list
This system has no repositories available through subscriptions.
```

As you can see `subscription-manager`

couldn’t found any repositories, you need to attach subscriptions to your server. Once the subscription is attached, `subscription-manager`

will be able to list repositories under it.

To attach subscription, check all available subscriptions for your server with below command –

```
root@kerneltalks # subscription-manager list --available
+-------------------------------------------+
Available Subscriptions
+-------------------------------------------+
Subscription Name: Red Hat Enterprise Linux for Virtual Datacenters, Standard
Provides: Red Hat Beta
Red Hat Software Collections (for RHEL Server)
Red Hat Enterprise Linux Atomic Host Beta
Oracle Java (for RHEL Server)
Red Hat Enterprise Linux Server
dotNET on RHEL (for RHEL Server)
Red Hat Enterprise Linux Atomic Host
Red Hat Software Collections Beta (for RHEL Server)
Red Hat Developer Tools Beta (for RHEL Server)
Red Hat Developer Toolset (for RHEL Server)
Red Hat Developer Tools (for RHEL Server)
SKU: RH00050
Contract: xxxxxxxx
Pool ID: 8a85f98c6011059f0160110a2ae6000f
Provides Management: Yes
Available: Unlimited
Suggested: 0
Service Level: Standard
Service Type: L1-L3
Subscription Type: Stackable (Temporary)
Ends: 12/01/2018
System Type: Virtual
```

You will get the list of such subscriptions available for your server. You need to read through what it provides and note down `Pool ID`

of subscriptions that are useful/required for you.

Now, attach subscriptions to your server by using pool ID.

```
root@kerneltalks # subscription-manager attach --pool=8a85f98c6011059f0160110a2ae6000f
Successfully attached a subscription for: Red Hat Enterprise Linux for Virtual Datacenters, Standard
```

If you are not sure which one to pick, you can simply attach subscriptions automatically which are best suited for your server with below command –

```
root@kerneltalks # subscription-manager attach --auto
Installed Product Current Status:
Product Name: Red Hat Enterprise Linux Server
Status: Subscribed
```

Move on to the final step to enable repository.

### Step 3: Enable repository

Now you will enable repository which is available under your attached subscription.

```
root@kerneltalks # subscription-manager repos --enable rhel-6-server-rhv-4-agent-beta-debug-rpms
Repository 'rhel-6-server-rhv-4-agent-beta-debug-rpms' is enabled for this system.
```

That’s it. You are done. You can [list repositories with yum command](https://kerneltalks.com/howto/how-to-list-yum-repositories-in-rhel-centos/) and confirm.

you are fantastic, straight to the point. IT worked perfectly

Do you need a paid redhat subscription for this?

Excellent, thanks for the contribution.

Do you need a paid redhat subscription for this?

Excellent, I followed your exact steps and was successful.

Thank you for your contribution! 🙂

Agent for Linux has been tested on Ubuntu 18.04, 19.10, Debian 10 and Linux Mint 19.3.

Other distributions might require further dependencies. Alternately, extra superior customers

with specific server needs should consider Debian. Who ought to use this:

ClearOS is a devoted Linux server operating.

In the same manner, use ‘cls’ for the primary argument for the class technique.

Documenting every technique with proper specification of parameters,

return sort, and data types. All managed disks running Cloud PCs are encrypted, all

stored knowledge is encrypted at rest, and all network traffic

to and from your Cloud PCs is also encrypted. Use tuples when data

is non-changeable, dictionaries when you want to map

things, and lists in case your data can change later on. This will not assist that a lot on a

pre-compiled Arch Linux kernel, since a decided attacker might simply download the kernel

bundle and get the symbols manually from there, but if you are compiling your personal kernel, this may

also help mitigating native root exploits. In this text we are going to learn about a few of the benefits of using

Amazon Web Services (AWS) and easy methods to dynamically create virtual machines (EC2) that will help with these limitations in minutes.

One among the nice advantages of using EC2 is the

financial savings in administrative value, planning and funding in further-hardware that is

not necessary, which turns corporations large costs

into much smaller one.

im getting problem after this command “subscription-manager list –available”

saying “No available subscription pools to list”