因Redhat 的(yum)更新包只对注册的用户生效,

所以除了配置本地yum源,配置CentOS 7的yum源亦可正常使用yum

下面开始配置CentOS 7 yum源


以下操作本人已实机操作成功。


注意:系统版本一定要相同。

系统:RedHat Enterprise Linux 7.0-x86_64

[root@RHEL7-anker ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.0 (Maipo)



操作步骤如下:


1.首先查看redhat 7.0系统本身所安装的哪些yum 软件包:

  rpm -qa | grep yum              #列出所有已安装的yum包


2.删除这些包:

命令:rpm -qa | grep yum |xargs rpm -e --nodeps     #删除所有以前的yum包

命令执行结束后再次执行:rpm -qa | grep yum 

没有结果即为删除成功


3.下载相关安装包RPM

wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm


wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-161.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-50.el7.noarch.rpm


 

4.安装下载的安装包

[root@RHEL7-anker Downloads]#rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm
[root@RHEL7-anker Downloads]#rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

[root@RHEL7-anker Downloads]#rpm -ivh yum-3.4.3-158.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm --nodeps

注:最后两个rpm要一起安装,不能单个安装,注意后面加上--nodeps参数,不加的话会有依赖问题

 

5.centos7.0的系统

[root@CentOS7 ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)


将centos7.0的系统中的yum源文件  /etc/yum.repos.d/CentOS-Base.repo复制到当前操作系统RedHat Enterprise Linux 7.0-x86_64 的 /etc/yum.repos.d/目录下

 

6.将centos7.0的系统中的/etc/pki/rpm-gpg/*文件复制到当前操作系统RedHat Enterprise Linux 7.0-x86_64 的/etc/pki/rpm-gpg/目录下

 

7.将复制过来的Centos-Base.repo中的$releasever改为Centos的版本号即可

执行命令:sed -i 's#$releasever#7#g' CentOS-Base.repo

cat 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
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os
baseurl=http://mirror.centos.org/centos/7/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-7 - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates
baseurl=http://mirror.centos.org/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

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

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus
baseurl=http://mirror.centos.org/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

注意,红色的是修改后的,原为$releasever,改成的7为版本号.


8.将修改后的Centos-Base.repo文件复制到/etc/yum.repos.d/目录下.

9. yum clean all 清除原有缓存

[root@RHEL7-anker yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors


10. yum makecache 获取yum列表

[root@RHEL7-anker yum.repos.d]# yum makecache
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:00     
extras                                                                                                                         | 3.4 kB  00:00:00     
updates                                                                                                                        | 3.4 kB  00:00:00     
(1/12): base/x86_64/group_gz                                                                                                   | 155 kB  00:00:00     
(2/12): base/x86_64/filelists_db                                                                                               | 6.6 MB  00:00:38     
base/x86_64/primary_db         FAILED                                                                               ] 155 kB/s |  11 MB  00:12:21 ETA
http://mirror.centos.org/centos/7/os/x86_64/repodata/bd50ff3d861cc21d254a390a963e9f0fd7b7b96ed9d31ece2f2b1997aa3a056f-primary.sqlite.bz2: [Errno 12] Timeout on http://120.192.95.138:801/cache/mirror.centos.org/centos/7/os/x86_64/repodata/bd50ff3d861cc21d254a390a963e9f0fd7b7b96ed9d31ece2f2b1997aa3a056f-primary.sqlite.bz2?ich_args=e27b6e155c53ff9bc20853c8be611065_1_0_0_5_94fb044d9b84bf033d68857cb366e888353663b5330c20986259f828775ea78f_85f301fcd124012562514a55b9ed13c1_1_0&ich_ip=159-135: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(3/12): extras/x86_64/prestodelta                                                                                              | 149 kB  00:00:04     
(4/12): extras/x86_64/primary_db                                                                                               | 191 kB  00:00:01     
(5/12): updates/x86_64/prestodelta                                                                                             | 954 kB  00:00:02     
(6/12): extras/x86_64/filelists_db                                                                                             | 1.1 MB  00:00:09     
(7/12): extras/x86_64/other_db                                                                                                 | 905 kB  00:00:07     
(8/12): base/x86_64/other_db                                                                                                   | 2.4 MB  00:00:16     
(9/12): updates/x86_64/filelists_db                                                                                            | 4.4 MB  00:00:21     
(10/12): base/x86_64/primary_db                                                                                                | 5.6 MB  00:00:12     
(11/12): updates/x86_64/primary_db                                                                                             | 7.8 MB  00:00:51     
updates/x86_64/other_db        FAILED                                          ========-                            ]   81 B/s |  54 MB 247:20:22 ETA
http://mirror.centos.org/centos/7/updates/x86_64/repodata/36288cdc93433b594aed022edabca28fe92c3497e23da598c59f890c0ddd7255-other.sqlite.bz2: [Errno 12] Timeout on http://mirror.centos.org/centos/7/updates/x86_64/repodata/36288cdc93433b594aed022edabca28fe92c3497e23da598c59f890c0ddd7255-other.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
updates/x86_64/other_db        FAILED                                          ===================-                 ]  100 B/s |  80 MB 123:36:37 ETA
http://mirror.centos.org/centos/7/updates/x86_64/repodata/36288cdc93433b594aed022edabca28fe92c3497e23da598c59f890c0ddd7255-other.sqlite.bz2: [Errno 12] Timeout on http://mirror.centos.org/centos/7/updates/x86_64/repodata/36288cdc93433b594aed022edabca28fe92c3497e23da598c59f890c0ddd7255-other.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
Trying other mirror.
(12/12): updates/x86_64/other_db                                                                                               |  93 MB  00:03:40     
Determining fastest mirrors
Metadata Cache Created

到此yum就可以在线安装软件了。

 

测试一下是否能安装:

[root@RHEL7-anker ~]# yum install nmap -y
Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package nmap.x86_64 2:6.40-7.el7 will be installed
--> Processing Dependency: nmap-ncat = 2:6.40-7.el7 for package: 2:nmap-6.40-7.el7.x86_64
--> Running transaction check
---> Package nmap-ncat.x86_64 2:6.40-4.el7 will be updated
---> Package nmap-ncat.x86_64 2:6.40-7.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch            Version                 Repository     Size
================================================================================
Installing:
 nmap               x86_64          2:6.40-7.el7            base          4.0 M
Updating for dependencies:
 nmap-ncat          x86_64          2:6.40-7.el7            base          201 k

Transaction Summary
================================================================================
Install  1 Package
Upgrade             ( 1 Dependent package)

Total download size: 4.2 M
Downloading packages:
No Presto metadata available for base
(1/2): nmap-ncat-6.40-7.el7.x86_64.rpm                     | 201 kB   00:02     
(2/2): nmap-6.40-7.el7.x86_64.rpm                          | 4.0 MB   00:23     
--------------------------------------------------------------------------------
Total                                              177 kB/s | 4.2 MB  00:24     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 2:nmap-ncat-6.40-7.el7.x86_64                                1/3
  Installing : 2:nmap-6.40-7.el7.x86_64                                     2/3
  Cleanup    : 2:nmap-ncat-6.40-4.el7.x86_64                                3/3
  Verifying  : 2:nmap-ncat-6.40-7.el7.x86_64                                1/3
  Verifying  : 2:nmap-6.40-7.el7.x86_64                                     2/3
  Verifying  : 2:nmap-ncat-6.40-4.el7.x86_64                                3/3

Installed:
  nmap.x86_64 2:6.40-7.el7                                                      

Dependency Updated:
  nmap-ncat.x86_64 2:6.40-7.el7                                                 

Complete!

看到Complete!,恭喜你修改成功。