RHEL 7 更换YUM源(更新于2020.4)

转载自博友“feng_zhiyu”的文章,并对文章的部分内容做了修改以适应自身情况
出处:https://blog.csdn.net/feng_zhiyu/article/details/80464336

实验环境:REHL 7.X
redhat系统安装好尽管默认带有yum,但是redhat的更新包只对注册用户有效(收费)。所以需要更换yum源。

基本的流程就是:

1.删除redhat7.0系统自带的yum软件包;
2.自行下载所需要的软件包;
3.根据依赖项安装;
4.新建repo配置文件。
一般来说,之后就可以正常使用了。可能还会遇到一些依赖项的问题,后面会提到。

流程
1、查看自带的yum软件包

[root@xhb yum.repos.d]# rpm -qa | grep yum
yum-utils-1.1.31-24.el7.noarch
yum-langpacks-0.4.2-3.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-rhn-plugin-2.0.1-4.el7.noarch
PackageKit-yum-0.8.9-11.el7.x86_64
yum-3.4.3-118.el7.noarch
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

这下面列出来的软件包,要记住一下,后面要根据其来搜索rpm包来安装新版本。比如”yum-utils”、”yum-langpacks”等等。

2、卸载这些安装包

rpm -qa | grep yum | xargs rpm -e --nodeps
 
 
  • 1

3、保证上网正常

ping www.baidu.com
 
 
  • 1

4、进入以下网站下载对应的rpm包
阿里云网络源地址:https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
网易163网络源地址:http://mirrors.163.com/
CentOS网络源地址:http://centos.ustc.edu.cn/centos/
使用CTRL+F输入关键字查找对应的安装包即可。
这里写图片描述

5.下载
因为镜像站中的安装包时常更新,所以下载链接有时效性。
正确的办法是在开源镜像站里搜索流程1中的包,找到对应的当前版本下载。
在找到的安装包链接处右键选择复制下载链接,然后在Linux终端使用wget + 复制的下载地址进行下载。

6、安装
输入指令rpm -ivh yum-*,遇到报错,依赖项问题。

[root@linuxprobe home]# rpm -ivh yum-*
warning: yum-3.4.3-158.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
    python-urlgrabber >= 3.10-8 is needed by yum-3.4.3-158.el7.centos.noarch
    rpm >= 0:4.11.3-22 is needed by yum-3.4.3-158.el7.centos.noarch

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

另外再回去找安装包下载下来:

wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-4.11.3-32.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
 
 
  • 1
  • 2

输入指令更新rpm:

rpm -Uvh rpm-4.11.3-32.el7.x86_64.rpm --nodeps
rpm -Uvh python-urlgrabber-3.10-8.el7.noarch.rpm --nodeps
 
 
  • 1
  • 2

再次运行rpm -ivh yum-*。

[root@linuxprobe home]# rpm -ivh yum-*
warning: yum-3.4.3-158.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 25%]
   2:yum-plugin-fastestmirror-1.1.31-4################################# [ 50%]
   3:yum-3.4.3-158.el7.centos         ################################# [ 75%]
   4:yum-utils-1.1.31-45.el7          ################################# [100%]
[root@linuxprobe home]# 

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

如果在下载完依赖包后还是显示无法安装可以使用“rpm -ivh --force --nodeps yum-*”命令强制安装所下载的所有YUM相关安装包。

7、新建repo配置文件
创建repo文件:

vim /etc/yum.repos.d/CentOS-Base.repo
 
 
  • 1

输入以下内容:

**建议直接将/etc/yum.repos.d/CentOS-Base.repo中的文件直接替换成此文**
#CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$7 - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$7 - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$7 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41

8、测试yum是否配置成功
随便下一个软件看看:

[root@linuxprobe home]# yum -y install tree
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Determining fastest mirrors
base                                                                 | 3.6 kB  00:00:00     
extras                                                               | 3.4 kB  00:00:00     
updates                                                              | 3.4 kB  00:00:00     
base/x86_64/group_gz           FAILED                                          
http://mirrors.163.com/centos/7/os/x86_64/repodata/29b154c359eaf12b9e35d0d5c649ebd62ce43333f39f02f33ed7b08c3b927e20-c7-x86_64-comps.xml.gz: [Errno 14] curl#6 - "Could not resolve host: mirrors.163.com; Unknown error"
Trying other mirror.
updates/x86_64/primary_db      FAILED                                          
http://mirrors.163.com/centos/7/updates/x86_64/repodata/d94a7500ce5b2da5a87ec4a88472b7d4668293b0aea3704dbbe23ef9819dbef0-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.163.com; Unknown error"
Trying other mirror.
extras/x86_64/primary_db       FAILED                                          
http://mirrors.163.com/centos/7/extras/x86_64/repodata/e4b5b58cea2f141b821193fbe5b791fd8dec29014091f45b3101d08ae8eb1e1b-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.163.com:80; Connection refused"
Trying other mirror.
(1/4): extras/x86_64/primary_db                                      | 146 kB  00:00:00     
base/x86_64/primary_db         FAILED                                          
http://mirrors.163.com/centos/7/os/x86_64/repodata/03d0a660eb33174331aee3e077e11d4c017412d761b7f2eaa8555e7898e701e0-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.163.com:80; Operation now in progress"
Trying other mirror.
base/x86_64/primary_db         FAILED                                          
http://mirrors.163.com/centos/7/os/x86_64/repodata/03d0a660eb33174331aee3e077e11d4c017412d761b7f2eaa8555e7898e701e0-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.163.com:80; Operation now in progress"
Trying other mirror.
base/x86_64/primary_db         FAILED                                          
http://mirrors.163.com/centos/7/os/x86_64/repodata/03d0a660eb33174331aee3e077e11d4c017412d761b7f2eaa8555e7898e701e0-primary.sqlite.bz2: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
Trying other mirror.
(1/2): updates/x86_64/primary_db                                     | 2.0 MB  00:00:07     
(2/2): base/x86_64/primary_db                                        | 5.9 MB  00:00:14     
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================
 Package           Arch                Version                      Repository         Size
============================================================================================
Installing:
 tree              x86_64              1.6.0-10.el7                 base               46 k

Transaction Summary
============================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Downloading packages:
warning: /var/cache/yum/x86_64/$releasever/base/packages/tree-1.6.0-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for tree-1.6.0-10.el7.x86_64.rpm is not installed
tree-1.6.0-10.el7.x86_64.rpm                                         |  46 kB  00:00:05     
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
Warning: RPMDB altered outside of yum.
** Found 4 pre-existing rpmdb problem(s), 'yum check' output follows:
PackageKit-0.8.9-11.el7.x86_64 has missing requires of PackageKit-backend
rhn-check-2.0.2-5.el7.noarch has missing requires of yum-rhn-plugin >= ('0', '1.6.4', '1')
rpm-libs-4.11.1-16.el7.x86_64 has missing requires of rpm = ('0', '4.11.1', '16.el7')
rpm-python-4.11.1-16.el7.x86_64 has missing requires of rpm = ('0', '4.11.1', '16.el7')
  Installing : tree-1.6.0-10.el7.x86_64                                                 1/1 
  Verifying  : tree-1.6.0-10.el7.x86_64                                                 1/1 

Installed:
  tree.x86_64 0:1.6.0-10.el7                                                                

Complete!
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

第二种方法:
挂载安装文件ISO里面的yum源
参考:
https://www.jianshu.com/p/25a63cbf1e9d
https://www.cnblogs.com/kerrycode/p/4723637.html
https://blog.csdn.net/qq_37460356/article/details/79568387

    • 9
      点赞
    • 18
      收藏
      觉得还不错? 一键收藏
    • 2
      评论
    RHEL 7的在线yum源是通过Red Hat订阅提供的。要设置RHEL 7的在线yum源,请按照以下步骤进行操作: 1. 首先,确保你已经购买了有效的Red Hat订阅,并且拥有订阅账户。 2. 登录到你的RHEL 7服务器。 3. 打开终端,并使用root用户或具有sudo权限的用户。 4. 运行以下命令来备份现有的yum源文件: ``` cp /etc/yum.repos.d/redhat.repo /etc/yum.repos.d/redhat.repo.bak ``` 5. 编辑yum源文件: ``` vi /etc/yum.repos.d/redhat.repo ``` 6. 将文件中的"enabled=0"改为"enabled=1",以启用在线yum源。 7. 添加你的Red Hat订阅信息。在文件末尾添加以下内容: ``` [rhel-7-server-rpms] name = Red Hat Enterprise Linux 7 Server (RPMs) baseurl = https://cdn.redhat.com/content/rhel/server/7/$releasever/$basearch/os gpgcheck = 1 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release [rhel-7-server-extras-rpms] name = Red Hat Enterprise Linux 7 Server - Extras (RPMs) baseurl = https://cdn.redhat.com/content/rhel/server/7/$releasever/$basearch/extras/os gpgcheck = 1 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release enabled = 1 [rhel-7-server-optional-rpms] name = Red Hat Enterprise Linux 7 Server - Optional (RPMs) baseurl = https://cdn.redhat.com/content/rhel/server/7/$releasever/$basearch/optional/os gpgcheck = 1 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release enabled = 1 ``` 8. 保存并退出文件。 9. 清除和重建yum缓存: ``` yum clean all yum makecache ``` 现在,你的RHEL 7服务器应该已经配置了在线yum源,可以使用yum命令来安装和更新软件包了。
    评论 2
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值