RedHat7 切换yum源

由于RedHat是收费产品,如果虚拟机搭建使用了RedHat的镜像,最好是进行yum源的切换,切换后使用Centos的yum源。

1、下载所需要的rpm安装包

https://mirrors.aliyun.com/centos/7/os/x86_64/Packages

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-167.el7.centos.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-53.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm

[root@master ~]# mkdir wget
[root@master ~]# ll
总用量 8
-rw-------. 1 root root 2288 5月  26 12:47 anaconda-ks.cfg
-rw-r--r--. 1 root root 2381 5月  26 13:09 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 5月  26 17:58 wget
[root@master ~]# cd wget/
[root@master wget]# ll
总用量 0
[root@master wget]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
--2020-05-26 17:59:15--  https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 113.142.38.180, 113.142.38.187, 113.142.38.186, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|113.142.38.180|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:28348 (28K) [application/x-redhat-package-manager]
正在保存至: “yum-metadata-parser-1.1.4-10.el7.x86_64.rpm”

100%[=======================================================================================================>] 28,348      --.-K/s 用时 0.001s

2020-05-26 17:59:16 (18.2 MB/s) - 已保存 “yum-metadata-parser-1.1.4-10.el7.x86_64.rpm” [28348/28348])


[root@master wget]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-167.el7.centos.noarch.rpm
--2020-05-26 18:01:35--  https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-167.el7.centos.noarch.rpm
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 113.142.38.187, 113.142.38.180, 113.142.38.181, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|113.142.38.187|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1298672 (1.2M) [application/x-redhat-package-manager]
正在保存至: “yum-3.4.3-167.el7.centos.noarch.rpm”

100%[=======================================================================================================>] 1,298,672   1.43MB/s 用时 0.9s

2020-05-26 18:01:36 (1.43 MB/s) - 已保存 “yum-3.4.3-167.el7.centos.noarch.rpm” [1298672/1298672])

[root@master wget]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
--2020-05-26 18:02:56--  https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 113.142.38.187, 113.142.38.180, 113.142.38.181, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|113.142.38.187|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:35004 (34K) [application/x-redhat-package-manager]
正在保存至: “yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm”

100%[=======================================================================================================>] 35,004      --.-K/s 用时 0.001s

2020-05-26 18:02:56 (55.1 MB/s) - 已保存 “yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm” [35004/35004])

[root@master wget]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-53.el7.noarch.rpm
--2020-05-26 18:03:45--  https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-53.el7.noarch.rpm
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 113.142.38.187, 113.142.38.180, 113.142.38.181, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|113.142.38.187|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:124628 (122K) [application/x-redhat-package-manager]
正在保存至: “yum-utils-1.1.31-53.el7.noarch.rpm”

100%[=======================================================================================================>] 124,628     --.-K/s 用时 0.06s

2020-05-26 18:03:45 (1.94 MB/s) - 已保存 “yum-utils-1.1.31-53.el7.noarch.rpm” [124628/124628])

[root@master wget]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
--2020-05-26 18:05:22--  https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 113.142.38.180, 113.142.38.181, 113.142.38.182, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|113.142.38.180|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:111048 (108K) [application/x-redhat-package-manager]
正在保存至: “python-urlgrabber-3.10-10.el7.noarch.rpm”

100%[=======================================================================================================>] 111,048     --.-K/s 用时 0.07s

2020-05-26 18:05:22 (1.44 MB/s) - 已保存 “python-urlgrabber-3.10-10.el7.noarch.rpm” [111048/111048])

[root@master wget]# ll
总用量 1572
-rw-r--r--. 1 root root  111048 4月   4 05:21 python-urlgrabber-3.10-10.el7.noarch.rpm
-rw-r--r--. 1 root root 1298672 4月   4 05:30 yum-3.4.3-167.el7.centos.noarch.rpm
-rw-r--r--. 1 root root   28348 7月   4 2014 yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
-rw-r--r--. 1 root root   35004 4月   4 05:30 yum-plugin-fastestmirror-1.1.31-53.el7.noarch.rpm
-rw-r--r--. 1 root root  124628 4月   4 05:30 yum-utils-1.1.31-53.el7.noarch.rpm

2、安装rpm包

查询yum包和删除yum现有rpm包,删完以后再查看一下,是否删除干净,删除完成后安装刚刚下载好的rpm包,yum包安装时必须取消依赖关系和强制安装。

rpm -qa | grep yum
rpm -qa | grep yum | xargs rpm -e --nodeps

rpm -ivh python-urlgrabber-3.10-10.el7.noarch.rpm
rpm -ivh yum-* --force --nodeps

[root@master wget]# rpm -qa | grep yum
yum-3.4.3-161.el7.noarch
yum-utils-1.1.31-50.el7.noarch
PackageKit-yum-1.1.10-1.el7.x86_64
yum-rhn-plugin-2.0.1-10.el7.noarch

▽
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
yum-langpacks-0.4.2-7.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
[root@master wget]# rpm -qa | grep yum | xargs rpm -e --nodeps
警告:/etc/yum/pluginconf.d/langpacks.conf 已另存为 /etc/yum/pluginconf.d/langpacks.conf.rpmsave
[root@master wget]# rpm -ivh python-urlgrabber-3.10-10.el7.noarch.rpm
警告:python-urlgrabber-3.10-10.el7.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中...                          ################################# [100%]
        file /usr/lib/python2.7/site-packages/urlgrabber/grabber.py from install of python-urlgrabber-3.10-10.el7.noarch conflicts with file from package python-urlgrabber-3.10-9.el7.noarch
        file /usr/lib/python2.7/site-packages/urlgrabber/grabber.pyc from install of python-urlgrabber-3.10-10.el7.noarch conflicts with file from package python-urlgrabber-3.10-9.el7.noarch
        file /usr/lib/python2.7/site-packages/urlgrabber/grabber.pyo from install of python-urlgrabber-3.10-10.el7.noarch conflicts with file from package python-urlgrabber-3.10-9.el7.noarch
[root@master wget]# rpm -ivh yum-* --force --nodeps
警告:yum-3.4.3-167.el7.centos.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 25%]
   2:yum-plugin-fastestmirror-1.1.31-5################################# [ 50%]
   3:yum-3.4.3-167.el7.centos         ################################# [ 75%]
   4:yum-utils-1.1.31-53.el7          ################################# [100%]

3、准备CentOS-Base.repo

现有的redhat .repo的包重命名,再下载阿里云的.repo到/etc/yum.repos.d目录下。

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

[root@master wget]# mv /etc/yum.repos.d/redhat.repo /etc/yum.repos.d/redhat.repo.bak
[root@master wget]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2020-05-26 18:24:35--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 119.96.136.240, 118.123.252.115, 118.123.252.118, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|119.96.136.240|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[=======================================================================================================>] 2,523       --.-K/s 用时 0s

2020-05-26 18:24:35 (83.1 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

4、编辑CentOS-Base.repo

修改刚下载的.repo文件,将里面所有$releasever替换为7。

vim /etc/yum.repos.d/CentOS-Base.repo
:%s/$releasever/7/g

[root@master wget]# vim /etc/yum.repos.d/CentOS-Base.repo

:%s/$releasever/7/g

5、yum源重构及升级

yum clean all
yum makecache
yum update

[root@master wget]# yum clean all
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在清理软件源: base extras updates
[root@master wget]# yum makecache
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                      | 3.6 kB  00:00:00
extras                                                                                                                    | 2.9 kB  00:00:00
updates                                                                                                                   | 2.9 kB  00:00:00
(1/10): base/x86_64/group_gz                                                                                              | 153 kB  00:00:00
(2/10): extras/x86_64/filelists_db                                                                                        | 205 kB  00:00:00
(3/10): base/x86_64/other_db                                                                                              | 2.6 MB  00:00:00
(4/10): extras/x86_64/other_db                                                                                            | 122 kB  00:00:00
(5/10): updates/x86_64/filelists_db                                                                                       | 980 kB  00:00:00
(6/10): updates/x86_64/other_db                                                                                           | 183 kB  00:00:00
(7/10): updates/x86_64/primary_db                                                                                         | 1.3 MB  00:00:00
base/x86_64/primary_db         FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/f09552edffa70f49f553e411c2282fbccfffbeafa21e81e32622b103038b8bae-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
正在尝试其它镜像。
(8/10): base/x86_64/primary_db                                                                                            | 6.1 MB  00:00:00
base/x86_64/filelists_db       FAILED
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/6882feea31727f25dc12063b4bab119501d25dbf6cb6fa0f5b78b8e3d5401ea4-filelists.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
extras/x86_64/primary_db       FAILED                                          ====================            ] 273 kB/s |  14 MB  00:00:17 ETA
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/42c5d8fe33ef3f1ab94d1ae257bc56201267d8af60132e3d778e586693e50a8f-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(9/10): base/x86_64/filelists_db                                                                                          | 7.1 MB  00:00:01
(10/10): extras/x86_64/primary_db                                                                                         | 194 kB  00:00:00
元数据缓存已建立
[root@master wget]# yum update
.....

至此,完成 RedHat yum 更换为 Centos yum。如果安装的系统是桌面版,之后会发现桌面会变成Centos标志。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值