rhel7 配置国内163 Centos yum 源,会因为未注册而不能使用;
红帽需要操作系统注册后才能使用yum。如果是这样就很头疼了,如果我们内网环境无法注册,或者我们不想注册难道不能使用了吗?
办法还是有的,那就让我们把这个功能关掉。
[问题分析]
1、yum源调用订阅管理器插件(其实是一个脚本)
/usr/lib/yum-plugins/subscription-manager.py
这个脚本中定义了订阅管理器的配置文件
2、订阅管理器配置文件定义功能启停
/etc/yum/pluginconf.d/subscription-manager.conf
[main]
enabled=1
3、如果订阅管理器是开启的,就会更新repo文件
/etc/yum.repos.d/redhat.repo
也就是说开启订阅管理器,就会更新或者重置redhat.repo,即使你把这个文件删掉,也不管用。
[解决方法]
关闭订阅管理器功能
[root@localhost yum.repos.d]# vim /etc/yum/pluginconf.d/subscription-manager.conf
[main]
enabled=0
将enabled置为0即可。
测试过程:
- 首先移除/etc/yum.repos.d/ 下的 rhel 源
[root@mysqlhost ~]# cd /etc/yum.repos.d/
[root@mysqlhost yum.repos.d]# ls
redhat.repo
[root@mysqlhost yum.repos.d]# rm *
rm: remove regular file ‘redhat.repo’? y
[root@mysqlhost yum.repos.d]# ll
total 0
[root@mysqlhost yum.repos.d]#
- 下载163 镜像仓库的yum源,然后查看文件
[root@mysqlhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2023-02-14 20:11:21-- http://mirrors.163.com/.help/CentOS7-Base-163.repo
Resolving mirrors.163.com (mirrors.163.com)... 101.71.33.11
Connecting to mirrors.163.com (mirrors.163.com)|101.71.33.11|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1572 (1.5K) [application/octet-stream]
Saving to: ‘CentOS7-Base-163.repo’
100%[=======================================================================================>] 1,572 --.-K/s in 0s
2023-02-14 20:11:21 (102 MB/s) - ‘CentOS7-Base-163.repo’ saved [1572/1572]
[root@mysqlhost yum.repos.d]# ls
CentOS7-Base-163.repo
- 使用 yum clean all 清除yum 缓存
[root@mysqlhost yum.repos.d]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: base extras updates
[root@mysqlhost yum.repos.d]# ls
CentOS7-Base-163.repo redhat.repo
发现清理过程中报错该系统未注册,您可以使用订阅管理器进行注册。并且会讲原有的redat.repo 回复回来,
- 配置关闭订阅管理器功能
[root@mysqlhost yum.repos.d]# vim /etc/yum/pluginconf.d/subscription-manager.conf
[main]
enabled=0
- 关闭订阅管理器后再次执行:
a. 移除rhel 的repl 源
b. 执行 yum makecache
[root@mysqlhost yum.repos.d]# ls
CentOS7-Base-163.repo redhat.repo
[root@mysqlhost yum.repos.d]# rm redhat.repo
rm: remove regular file ‘redhat.repo’? y
[root@mysqlhost yum.repos.d]# ll
total 4
-rw-r--r--. 1 root root 1572 Dec 1 2016 CentOS7-Base-163.repo
[root@mysqlhost yum.repos.d]# yum makecache
Loaded plugins: langpacks, product-id, search-disabled-repos
http://mirrors.163.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article
https://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.
One of the configured repositories failed (CentOS-7Server - Base - 163.com),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=base ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable base
or
subscription-manager repos --disable=base
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=base.skip_if_unavailable=true
failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
http://mirrors.163.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
发现报错为找不到对应的路径:
http://mirrors.163.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
6 、查看163 的repl源文件,并查看源地址的网站,以及前面的报错找不到的对应路径。
发现是因为 repo 中 的
/$releasever/
获取的值获取错误了,因为系统是rhel,而我们用的源是Centos 因此将 /$releasever/
直接改为/7/
即可。再次执行yum makecache ,并尝试使用yum 安装lrzsz 工具
[root@mysqlhost yum.repos.d]# yum makecache
Loaded plugins: langpacks, product-id, search-disabled-repos
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/x86_64/group_gz | 153 kB 00:00:00
(2/10): base/x86_64/primary_db | 6.1 MB 00:00:01
(3/10): base/x86_64/filelists_db | 7.2 MB 00:00:01
(4/10): extras/x86_64/primary_db | 249 kB 00:00:00
(5/10): extras/x86_64/filelists_db | 276 kB 00:00:00
(6/10): base/x86_64/other_db | 2.6 MB 00:00:00
(7/10): extras/x86_64/other_db | 149 kB 00:00:00
(8/10): updates/x86_64/filelists_db | 11 MB 00:00:00
(9/10): updates/x86_64/other_db | 1.3 MB 00:00:00
(10/10): updates/x86_64/primary_db | 19 MB 00:00:01
Metadata Cache Created
[root@mysqlhost yum.repos.d]#
[root@mysqlhost yum.repos.d]#
[root@mysqlhost yum.repos.d]# yum -y install lrzsz
Loaded plugins: langpacks, product-id, search-disabled-repos
Resolving Dependencies
--> Running transaction check
---> Package lrzsz.x86_64 0:0.12.20-36.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================
Installing:
lrzsz x86_64 0.12.20-36.el7 base 78 k
Transaction Summary
=================================================================================================================================
Install 1 Package
Total download size: 78 k
Installed size: 181 k
Downloading packages:
warning: /var/cache/yum/x86_64/7Server/base/packages/lrzsz-0.12.20-36.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for lrzsz-0.12.20-36.el7.x86_64.rpm is not installed
lrzsz-0.12.20-36.el7.x86_64.rpm | 78 kB 00:00:00
Retrieving key from http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
From : http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : lrzsz-0.12.20-36.el7.x86_64 1/1
Verifying : lrzsz-0.12.20-36.el7.x86_64 1/1
Installed:
lrzsz.x86_64 0:0.12.20-36.el7
Complete!
[root@mysqlhost yum.repos.d]#
最终成功。