RedHat7 切换yum源或者重新安装yum源

故事的开始是本人不小心手贱把yum源给卸载了,卸载完以后就开始找百度的各类大神的博客,看别人怎么搞的然后辛辛苦苦整了一个小时还是报错,最终找到了一个博客成功的帮我把问题解决了,下面写的是在解决问题的一些心得体会。
一般有以下5个步骤
当然在下载之前先ping下外网地址,目的是看你的网络有没有连通
1下载相应的rmp包
2安装rmp包
3准备CentOS-Base.repo
4.编辑CentOS-Base.repo
5.yum源重构及升级

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

1.下载阿里yum源的地址
下载地址:https://mirrors.aliyun.com/centos/7/os/x86_64/Packages
找到1.yum-metadata-parser-.rpm
2.yum-
.el7.centos.noarch.rpm
3.yum-plugin-fastestmirror-.el7.noarch.rpm
4.yum-utils-
.el7.noarch.rpm
5python-urlgrabber-*.el7.noarch.rpm
这五个rpm包,其中 “ * ” 代表的是相对应的版本,因为随时间的变化这些rmp包的版本也会更换,查找到版本后再下载是最稳妥的
不过今天是2020年6月我换的rmp包是

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包安装时必须取消依赖关系和强制安装。

1查找安装过的yum相关的rpm包

rpm -qa | grep yum

2检查yum是否已经安装

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

3安装python-urlgrabber-*.el7.noarch.rpm这个包

rpm -ivh python-urlgrabber-3.10-10.el7.noarch.rpm

4把剩下4个yum-*的rpm包强制安装

rpm -ivh yum-* --force --nodeps

注意:我们在安装的时候那个yum-*的包必须一起安装,具体原因是因为包之间有相互依赖的关系

[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。
这个命令是进入刚下载好的CentOS-Base.repo文件夹里面

vim /etc/yum.repos.d/CentOS-Base.repo

用密令行的方式把$releasever替换为7,具体操作是按下ESC键然后:就可以打下替换的命令%s/&releasever/7/g

:%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标志。
心得:其实yum源的下载啊是很简单的事情,无非就是先下载rpm包,安装,再安装相应的镜像文件,修改文件重构和升级,其中最为麻烦的事情就是下载那个版本的rpm包的事情,需要得知版本我们需要去看官方网站去找相应的版本,剩下的都不是什么大问题。对于yum源来说有163yum源【网易】和阿里yum源【阿里巴巴】以及本地yum源【本地】。博主是因为在挂载本地yum源的时候看了某篇博客,具体那一篇就不列出来了,然后把本地的yum源给删除了,后面经过了坎坷的按照别人的博客一步一步操作发现越来越挫,起初我是找那些163yum源的下载的,要么就是有的rpm包找不到,要么就是安装的时候没有那个包,留下了辛酸的泪水,errr。所以我们要做第一步的时候要确保官网上面有我们要的那个包且版本的要对应的上。不过建议能不要删除yum源就尽量别那么手贱吧,一般对于本地yum源就已经够用了吧,这里插一张本地yum源文件的图片
本文95%是来自于这篇博客https://blog.csdn.net/weixin_45883933/article/details/106837010#comments_12617477
应该说是百分之九十九

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值