RedHat7.0更新yum源(踩过的坑)

前言

redhat系统安装好尽管默认带有yum,但是redhat的更新包只对注册用户有效,对于我们这些穷人来说,只有自己手动更改成CentOS的更新包了。
最初在网上查找资料:Redhat 7使用CentOS 7的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

这下面列出来的软件包,要记住一下,后面要根据其来搜索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-154.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-plugin-fastestmirror-1.1.31-42.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-42.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-42.el7.noarch.rpm

6、安装

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

[root@xhb Packages]# rpm -ivh yum-*
warning: yum-3.4.3-154.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
    rpm >= 0:4.11.3-22 is needed by yum-3.4.3-154.el7.centos.noarch

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

wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-4.11.3-25.el7.x86_64.rpm

输入指令更新rpm:

rpm -Uvh rpm-4.11.3-25.el7.x86_64.rpm --nodeps

再次运行rpm -ivh yum-*,可以正常安装了。

[root@xhb Packages]# rpm -ivh yum-*
warning: yum-3.4.3-154.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 ################################# [ 20%]
   2:yum-plugin-fastestmirror-1.1.31-4################################# [ 40%]
   3:yum-3.4.3-154.el7.centos         ################################# [ 60%]
   4:yum-updateonboot-1.1.31-42.el7   ################################# [ 80%]
   5:yum-utils-1.1.31-42.el7          ################################# [100%]

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

8、测试yum是否配置成功

随便下一个软件看看:

[root@xhb yum.repos.d]# 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.
base                                                     | 3.6 kB     00:00     
extras                                                   | 3.4 kB     00:00     
updates                                                  | 3.4 kB     00:00     
(1/4): base/x86_64/group_gz                                | 156 kB   00:00     
(2/4): extras/x86_64/primary_db                            | 166 kB   00:00     
(3/4): base/x86_64/primary_db                              | 5.7 MB   00:02     
(4/4): updates/x86_64/primary_db                           | 6.0 MB   00:02     
Determining fastest mirrors
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     
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) "
 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!

你可能感兴趣的:(linux)