阿毛
It's me !
想你所想
解决低版本CentOS中使用yum异常问题

在CentOS 6.10中使用yum时遇到了一些错误,原因是在于yum版本支持问题,这里总结下。

问题描述

公司使用阿里binlog同步组件canal进行binlog数据处理,构建镜像启动canal server,其中镜像基础基于“centos:centos6.10”,然后yum一些基础工具。原先(2021年前)一直可以正常构建,但这两天突然构建不了了。报错如下:

[91mError: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
[0mYumRepo Error: All mirror URLs are not using ftp, http[s] or file.
 Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
The command '/bin/sh -c yum install -y ca-certificates curl' returned a non-zero code: 1

原因分析

在找解决办法时,偶然间看到这样一个回答(https://stackoverflow.com/questions/21396508/yumrepo-error-all-mirror-urls-are-not-using-ftp-https-or-file

https://file.blog.humh.cn/2021/02/d2b5ca33bd970f64a6301fa75ae2eb22.png

于是有了启示,是不是yum在CentOS不同版本支持上有差异,顺着这个方向验证,发现确实自2020年12月起,yum对CentOS 6.0 – 6.10的所有版本将不再提供更新和安全支持,国内的镜像源和官方镜像源都不可用。

国内yum镜像源如:阿里云 http://mirrors.aliyun.com/centos , 进入“6”目录下,可以发现只有一个readme文件,而文件内容如下

This directory (and version of CentOS) is deprecated. Please see this FAQ
concerning the CentOS release scheme:
 
https://wiki.centos.org/FAQ/General
 
Please keep in mind that 6.0, 6.1, 6.2, 6.3, 6.4 , 6.5, 6.6, 6.7, 6.8 , 6.9 and 6.10 no longer get any updates, nor
any security fix's.
 
The whole CentOS 6 is *dead* and *shouldn't* be used anywhere at *all*

大致就是说,yum已不再为CentOS 6相关版本提供支持,更低版本也是如此。

官方镜像源:
http://mirror.centos.org/centos/6/,也是同上,只有readme。
http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os,也会提示“Invalid release/repo/arch combination”不可用的错误信息,正常应该是这样的

https://file.blog.humh.cn/2021/02/d2b5ca33bd970f64a6301fa75ae2eb22-1.png

而对于yum来说,它的大致逻辑就是,会根据本地配置文件中指定url去找对应库下的repodata目录,里面包含了多个软件库之间依赖关系,每个rpm包中header也都记录该包存在的依赖关系,当yum install的时候,是需要先找打依赖关系,你可能也注意到了,在安装某个包时,下载了很多其他的东西。在repodata目录下存在一个repomd.xml,其中指定了相应rpm包的下载地址

https://file.blog.humh.cn/2021/02/d2b5ca33bd970f64a6301fa75ae2eb22-2.png

到了这里,你就不难理解异常的原因。就是因为yum对旧版CentOS不再支持,对应版本yum源中不再存在任何包,在install时也就找不到repomd.xml。导致了上面的报错,也就为啥原先可以,现在突然不行了。

解决方式

替换本地yum配置文件中的源地址

yum虽然不再对旧版CentOS提供更新和支持,但保留了截止支持时的快照,过时的源,也就说要想安装新包可能不行,但旧包还是可以的。地址:https://vault.centos.org/

https://file.blog.humh.cn/2021/02/d2b5ca33bd970f64a6301fa75ae2eb22-3.png

1、修改配置文件

CentOS中,yum配置文件位于“/etc/yum.repos.d/”,只需要修改CentOS-Base.repo即可。

打开CentOS-Base.repo,替换其中每一项的baseurl,具体来说替换“enable=1”的项(“enable=0”代表未生效启用)。

替换成的url规则:https://vault.centos.org/系统版本/[os][updates][extras][centosplus][contrib]/$basearch

说明:yum支持一些变量值,如上面的$basearch实际上是系统硬件架构(CPU指令集),就是我们常说的i386i486i586i686x86_64。。等

如这里使用的是CentOS 6.10,则替换后的结果应为

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/6.10/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

注意:默认可能启用的是mirrorlist配置,而注释掉了baseurl,修改后,应注释mirrorlist,取消baseurl的注释,启用baseurl

其他项以此类推。

最终修改后的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-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://vault.centos.org/6.10/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

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

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://vault.centos.org/6.10/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-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://vault.centos.org/6.10/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-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=https://vault.centos.org/6.10/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

或者可以使用系统基础版本号,如CentOS 6.10 对应基本版本号6,在yum中$releasever代表了基础版本号,拿base节点举例的话,baseurl可为:https://vault.centos.org/centos/$releasever/os/$basearch/。其他节点以此类推。

注意,baseurl支持多镜像源配置,然后会取可用url使用,如果使用了yum-fastestmirror,则会自动判断baseurl中多个url源哪个最快,用哪个。如果没有使用fastestmirror插件的话,而配置文件未指定(默认)或指定了failovermethod=priority则按配置的url列表顺序,自上而下使用,如果第二不行,则使用第二个,以此类推。

如果都是用yum变量配置的话,且多镜像源,最终配置可参考如下:

# 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
failovermethod=priority
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/os/$basearch/
        https://mirrors.cloud.tencent.com/centos/$releasever/os/$basearch/
        https://vault.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
failovermethod=priority
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/updates/$basearch/
        https://mirrors.cloud.tencent.com/centos/$releasever/updates/$basearch/
        https://vault.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
failovermethod=priority
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/extras/$basearch/
        https://mirrors.cloud.tencent.com/centos/$releasever/extras/$basearch/
        https://vault.centos.org/centos/$releasever/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-$releasever - Plus
failovermethod=priority
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/centosplus/$basearch/
        https://mirrors.cloud.tencent.com/centos/6.0/centosplus/$basearch/
        https://vault.centos.org/centos/$releasever/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-$releasever - Contrib
failovermethod=priority
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib&infra=$infra
baseurl=https://mirrors.aliyun.com/centos-vault/centos/$releasever/contrib/$basearch/
        https://mirrors.cloud.tencent.com/centos/$releasever/contrib/$basearch/
        https://vault.centos.org/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

注意
阿里云镜像源,目录结构为:具体系统版本号如6.0-6.10在https://mirrors.aliyun.com/centos-vault/下,而基础版本号如6,在https://mirrors.aliyun.com/centos-vault/centos下!!
vault镜像源,目录结构为:具体版本号如6.0-6.10在https://vault.centos.org/下,而基础版本号如6,在https://vault.centos.org/centos/
配置时需要注意!!

2、重新加载配置

配置完成后,卸载旧yum配置,重新加载新配置,运行如下命令

yum clean all && yum makecache

至此,yum在旧版CentOS中的使用问题,已解决。


参考

发表评论

textsms
account_circle
email

想你所想

解决低版本CentOS中使用yum异常问题
在CentOS 6.10中使用yum时遇到了一些错误,原因是在于yum版本支持问题,这里总结下。 问题描述 公司使用阿里binlog同步组件canal进行binlog数据处理,构建镜像启动canal server,其…
扫描二维码继续阅读
2021-02-02