设为首页 收藏本站
查看: 531|回复: 0

[经验分享] RHEL 7配置CentOS yum源

[复制链接]

尚未签到

发表于 2018-4-21 10:47:33 | 显示全部楼层 |阅读模式
  因Redhat 的(yum)更新包只对注册的用户生效,所以我们使用centos7.0的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-150.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-40.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-150.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-40.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复制到当前操作系统RedHatEnterprise Linux 7.0-x86_64 的 /etc/yum.repos.d/目录下
  6.将centos7.0的系统中的/etc/pki/rpm-gpg/*文件复制到当前操作系统RedHatEnterprise 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 existingpackages
[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!,恭喜你修改成功。

  

  

  

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-449958-1-1.html 上篇帖子: centos7(常用命令大全) 下篇帖子: CentOS 7.3 安装 Nagios 4.3.4 和 Nagios Plugins 2.2.1
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表