RHEL 7配置CentOS yum源

因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-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-plugin-fastestmirror-1.1.31-45.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!,恭喜你修改成功。






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章