linux 重装 yum 及更换yum源 -- 解决国内各版本 yum 源失效的问题

公司的服务器 yum 源有问题  卸载之后想重新安装一个,结果发现国内好多镜像网站一些老版本 都失效了  找了两天终于找到了  特贴出来做个记录 

http://vault.centos.org

然后我在 centos 使用yum安装git 的时候 爆出了

Loaded plugins: fastestmirror, security
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/
removing mirrorlist with no valid mirrors: /var/cache/yum/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base

的错误  ,之后找了好多解决方法 , 修改DNS之类的 都尝试过了 ,还是没有解决问题 , 没办法只好卸载 yum 重新安装,发现问题依旧,就是在此时发现了好多  yum 源失效的问题 , 转念一想 ,是不是服务器的 yum 源失效了 , 抱着试试的心态更换了 yum 源 ,终于解决了问题

一: 重新安装 yum

先查看 yum 的依赖包:#rpm –qa | grep yum     ps:重要 一定要先对依赖包做个记录 不然你直接删了 都不知道该安装些什么东西 最好截张图

卸载相关依赖包:#rpm –e –nodeps yum

这两句可合并为一句执行 : #rpm -qa | grep yum |xargs rpm -e --nodeps

去 http://vault.centos.org 下载相应的 centos 版本 的 python  和 python-iniparse 依赖包  , #cat  /etc/issue 可以 查看当前centos版本

我的是centos 5.11 版本 ,对应文件在 http://vault.centos.org/5.11/os/x86_64/ 目录下

安装 , #rpm –ivh  python-***(对应版本)   python-iniparse-***

在这儿我还报了个错 

[root@localhost my_temp]# rpm -ivh python-2.4.3-46.el5.x86_64.rpm  python-iniparse-0.2.3-4.el5.noarch.rpm 
error: Failed dependencies:
    python-libs-x86_64 = 2.4.3-46.el5 is needed by python-2.4.3-46.el5.x86_64

很明显是还缺东西  没事 找到对应 版本 一起安装就可以了

若安装失败可重新输入此命令并加参数--nodeps –force

然后在把之前 列出的 yum 依赖包 下载下来并安装 最好一起安装 可解决报的依赖问题

我这儿只是例子  以自己的版本为准

[root@localhost my_temp]# rpm -ivh yum-fastestmirror-1.1.16-21.el5.centos.noarch.rpm  yum-security-1.1.16-21.el5.centos.noarch.rpm  yum-3.2.22-40.el5.centos.noarch.rpm  yum-metadata-parser-1.1.2-4.el5.x86_64.rpm  yum-updatesd-0.9-6.el5_10.noarch.rpm 
Preparing...                ########################################### [100%]
   1:yum-metadata-parser    ########################################### [ 20%]
   2:yum                    ########################################### [ 40%]
   3:yum-fastestmirror      ########################################### [ 60%]
   4:yum-security           ########################################### [ 80%]
   5:yum-updatesd           ########################################### [100%]

OK  大功告成,之后 清理yum缓存

#yum clean all

在将服务器软件包信息缓存至本地

#yum makecache

到此如果  yum 可以使用的话 无视下面的就好

二 : 更换 yum 源

进入 yum 配置文件目录    #cd  /etc/yum.repos.d/   

备份配置文件    #mv  CentOS-Base.repo   CentOS-Base.repo.bak

下载 163 的配置文件  #wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

更名  #mv CentOS6-Base-163.repo   CentOS-Base.repo

到重点了  由于 163源 迁移的问题 所以 这个下载下来的源是同样无法使用的 只能自己手动修改

未改动过的 163 源是这样子的 

[base]
name=CentOS-$releasever - Base - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#released updates 
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

自己把他的路径根据源网站作了修改

改动之后是这样的 

[base]
name=CentOS-$releasever - Base - 163.com
baseurl=http://vault.centos.org/5.11/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5

#released updates 
[updates]
name=CentOS-$releasever - Updates - 163.com
baseurl=http://vault.centos.org/5.11/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons - 163.com
baseurl=http://vault.centos.org/5.11/addons/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
baseurl=http://vault.centos.org/5.11/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://vault.centos.org/5.11/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - 163.com
baseurl=http://vault.centos.org/5.11/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-5
                                         

说一说几个主要修改的点

首先是网址 改为了 http://vault.centos.org   然后删除了 centos  把  $releasever  这个变量自己手动改为了 5.11(对应的版本号)  这一步自己琢磨 我是改完之后 他还报错 发现是版本号的问题 给我显示的 5 而我是 5.11 的版本,改完之后最好自己先去访问一下有没有对应的文件 以防出错  

#yum clean all

#yum makecache

测试安装了 git  完美   ,一点错都没报  爽!

既不回头,何必不忘; 既然无缘,何须誓言; 今日种种,逝水无痕; 明夕何夕,君已陌路;
原文地址:https://www.cnblogs.com/zyjfire/p/7279487.html