Red hat7替换centos7的Yum源

RedHat Yum源是收费的,没有成功注册RedHat的机器无法正常使用Yum源,而CentOS Yum源是免费的,国内网易、阿里的Yum源,稳定可靠,并且ReHat和Centos是一家,它俩基本没有什么区别,所以将rethat yum源改为centos的yum源。

一、卸载RedHat原有的Yum源

  1. 查看原有的yum源
rpm -qa |grep yum
  1. 卸载
rpm -qa|grep yum|xargs rpm -e --nodeps(不检查依赖,直接删除rpm包)

二、下载Centos Yum源

  1. 网址
    由于各个网站实际yum源版本经常更新,所以建议直接去网站下载,不要直接复制网上的命令类似于:
    wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm,这个你只会连接不上
    阿里云:https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
  2. 下载的包
    注意:包名后缀可能因为版本不同而不同
    python-urlgrabber-3.10-10.el7.noarch.rpm
    yum-3.4.3-167.el7.centos.noarch.rpm
    yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
    yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
    yum-updateonboot-1.1.31-53.el7.noarch.rpm
    yum-utils-1.1.31-53.el7.noarch.rpm
    rpm-4.11.3-43.el7.x86_64.rpm
  3. 安装
    由于这几个包互相有依赖性,所以统一直接安装
rpm -ivh --force *.rpm

出现以下结果为安装成功

警告:python-urlgrabber-3.10-10.el7.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 14%]
   2:rpm-4.11.3-43.el7                ################################# [ 29%]
   3:python-urlgrabber-3.10-10.el7    ################################# [ 43%]
   4:yum-plugin-fastestmirror-1.1.31-5################################# [ 57%]
   5:yum-3.4.3-167.el7.centos         ################################# [ 71%]
   6:yum-updateonboot-1.1.31-53.el7   ################################# [ 86%]
   7:yum-utils-1.1.31-53.el7          ################################# [100%]

三、配置repo

  1. 下载新的repo文件
    地址http://mirrors.aliyun.com/repo/
  2. 选择下载对应的repo文件
    Centos-7.repo
  3. 到对应目录下
   cd /etc/yum.repos.d/
   [root@localhost yum.repos.d]# ls
redhat.repo
  1. 将原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-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  1. 替换内容
    用密令行的方式把$releasever替换为7,具体操作是按下ESC键然后:就可以打下替换的命令%s/&releasever/7/g
:%s/$releasever/7/g

四、重构

  1. yum clean all
  2. yum makecache
  3. yum update

猜你喜欢

转载自blog.csdn.net/qq_42956179/article/details/109618774