RHEL7更换yum源

首先给大家推荐一下我老师大神的人工智能教学网站。教学不仅零基础,通俗易懂,而且非常风趣幽默,还时不时有内涵黄段子!点这里可以跳转到网站

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

说明:我下载的是网易的rpm包,因为这些包在不断更新,所以可能失效。但是有方法可以解决,详见下文。
参考:https://blog.csdn.net/hongbin_xu/article/details/79316614
以下rpm包在2018.5.26可用

基本的流程就是:

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

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

2、卸载这些安装包

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

3、保证上网正常

ping www.baidu.com
这里写图片描述

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、找到安装包后下载下来
由于输出结果较多,故省略,下面是指令:

wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-45.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-45.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm

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

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

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

输入指令更新rpm:

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

再次运行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

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

vim /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!

第二种方法:
挂载安装文件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

点这里可以跳转到人工智能网站

发表评论