背景:作者打算在Redhat 做kvm虚拟化的时候在安装 virt-manager发现 提示要注册红帽的yum源,简单说要钱呗。要钱那是不可能给你的,所以有以下有centos的yum源替换redhat7的yum源。

前景概括(步骤总结)

  1. 卸载原有的yum的rpm包
  2. 去阿里镜像站下载centos必要的yum包
  3. rpm -ivh yum- 安装相对应的rpm
  4. 去阿里镜像站下载 centos-base.repo,并修改
  5. 清楚yum缓存,再重新生成缓存
  6. 测试 使用 yum -y install xxx

详细步骤:
查看 原有的yum
[root@localhost yum.repos.d]# rpm -qa |grep yum
yum-3.4.3-158.el7.centos.noarch
yum-plugin-fastestmirror-1.1.31-45.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-utils-1.1.31-45.el7.noarch
yum-updateonboot-1.1.31-45.el7.noarch
[root@localhost yum.repos.d]#

卸载以上安装包
rpm -qa | grep yum | xargs rpm -e --nodeps

再次查看是否删除完成
[root@localhost yum.repos.d]# rpm -qa |grep yum

保证主机可以上网(为了去阿里镜像站里下载对应的rpm包:https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
[root@localhost yum.repos.d]# ping www.hao123.com
PING hao123.n.shifen.com (112.34.111.167) 56(84) bytes of data.
64 bytes from 112.34.111.167: icmp_seq=1 ttl=128 time=55.8 ms
64 bytes from 112.34.111.167: icmp_seq=2 ttl=128 time=54.2 ms
64 bytes from 112.34.111.167: icmp_seq=3 ttl=128 time=48.1 ms
^C
--- hao123.n.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 48.114/52.736/55.804/3.326 ms

下载在本地:如下图:
Redhat 7 yum源换成centos的YUM 源

安装下载的软件包
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-45.el7.noarch.rpm

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-45.el7.noarch.rpm

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

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
之后就是直接安装 rpm -ivh yum-*

之后发现提示有问题
Redhat 7 yum源换成centos的YUM 源
后来发现是python-urlgrabber和rpm版本过低;所以可以去下载的版本的,或者直接更新
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-4.11.3-32.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
然后更新
rpm -Uvh rpm-4.11.3-32.el7.x86_64.rpm --nodeps
rpm -Uvh python-urlgrabber-3.10-8.el7.noarch.rpm --nodeps

然后再次执行 yum -y install yum-*
Redhat 7 yum源换成centos的YUM 源

查看是否安装好以上rpm包


去阿里镜像站下载centos-7.repo
CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

vim /etc/yum.repos.d/CentOS-Base.repo
把releasever替换成现有系统的版本号(7)
vim替换命令
:%s/$releasever/7/g

最后执行 yum clean all 清除缓存
yum makecahe 再生成缓存