CentOS系统更换yum源(repomd.xml not found解决方案)

CentOS系统更换yum源

问题

当初瞎鼓捣服务器,更换yum源为aliyun的,奈何阿里的源最近全部打不开,导致yum安装不了,一直报错:

http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - “The requested URL returned error: 404 Not Found”
Trying other mirror.
http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 7 - “couldn’t connect to host”
Trying other mirror.
http://mirrors.cloud.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - “Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’”
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again

在网上查了些资料,总算弄懂应该怎么处理了,但是找不到一个对应的源,所以还原默认了;

1. 查询服务器的系统版本
[root@nys yum.repos.d]# rpm -qi centos-release 
Name        : centos-release               Relocations: (not relocatable)
Version     : 6                                 Vendor: CentOS
Release     : 10.el6.centos.12.3            Build Date: Tue 26 Jun 2018 10:52:41 PM CST
Install Date: Mon 23 Jul 2018 11:48:26 AM CST      Build Host: x86-01.bsys.centos.org
Group       : System Environment/Base       Source RPM: centos-release-6-10.el6.centos.12.3.src.rpm
Size        : 38232                            License: GPLv2
Signature   : RSA/SHA1, Tue 26 Jun 2018 11:35:30 PM CST, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Summary     : CentOS release file
Description :
CentOS release files

如上:Version,Release两项,当前服务器操作系统的版本就是:6.10

2. 更换yum源
  • 进入yum配置文件目录
cd /etc/yum.repos.d

[root@nys yum.repos.d]# ll
total 60
drwxr-xr-x 2 root root 4096 Oct 17  2017 backup
-rw-r--r-- 1 root root 1901 Jan  5 15:35 CentOS-Base.repo           #此文件为yum使用的源配置
-rw-r--r-- 1 root root 1991 Jun 26  2018 CentOS-Base.repo.rpmnew
-rw-r--r-- 1 root root  647 Jun 26  2018 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root  289 Jun 26  2018 CentOS-fasttrack.repo
-rw-r--r-- 1 root root  630 Jun 26  2018 CentOS-Media.repo
-rw-r--r-- 1 root root 8854 Jun 26  2018 CentOS-Vault.repo
-r--r--r-- 1 root root  664 May 11  2018 epel.repo
-rw-r--r-- 1 root root  957 Nov  5  2012 epel.repo.rpmnew
-rw-r--r-- 1 root root 1056 Nov  5  2012 epel-testing.repo
-rw-r--r-- 1 root root  206 Aug 20 17:58 influxdb.repo
  • 确保yum源可访问,此处用的163源

http://mirrors.163.com/centos/6.10/

  • 可以查看网易的源说明:

http://mirrors.163.com/.help/

  • 下载对应版本的163源:

wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

  • 替换源文件到Base:

sudo cp CentOS6-Base-163.repo CentOS-Base.repo

  • 更换Base文件中的路径为指定版本号:
# 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 - 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-6

#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-6

#additional packages that may be useful
--More--(51%)

* 需要将$releasever替换为当前系统版本号:6.10,对应可访问的163源路径

http://mirrors.163.com/centos/6.10/

  • 使用vim替换:

:%s/$releasever/6.10/g

  • 仅展示部分替换后的文件内容:
# 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-6.10 - Base - 163.com
baseurl=http://mirrors.163.com/centos/6.10/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6.10&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

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

--More--(51%)
3. 更新yum
#重置缓存
yum makecache

其它可参考执行的命令

#检查可以更新的软件包 
yum check-update 

#更新所有的软件包 
yum update 

#更新特定的软件包 
yum update kernel 

#大规模的升级 
yum upgrade


#清楚缓存中rpm包文件 
yum clean packages 

#清楚缓存中rpm的头文件 
yum clean  headers 

#清除缓存中旧的头文件 
yum clean old headers 

#清除缓存中旧的rpm头文件和包文件 
yum clean all

如果不成功,还原为默认源配置文件
  • CentOS-Base.repo 源文件内容,需要将版本6改为7,因为6版本repomd.xml文件已经没有了,只能从7版本开始

http://mirror.centos.org/centos/7/os/x86_64/repodata/

[root@nys yum.repos.d]# cat CentOS-Base.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-7 - Base
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates 
[updates]
name=CentOS-7 - Updates
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-7 - Extras
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-7 - Contrib
mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=contrib&infra=$infra
#baseurl=http://mirror.centos.org/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
  • 更新epel.repo文件内容,将6改为7:
[root@nys yum.repos.d]# more epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
 
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

  • 清楚缓存并重置
yum clean all

yum makecache

yum -y update
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值