概览

由于需要安装较新的组件,系统默认使用的是 webtatic.repo,基本上链接到的镜像都是国外,导致下载速率很慢,随之想着替换,不料还搞出大问题,但也在解决这个问题的过程中,也对 CentOS 软件包镜像源有了更深的理解。

过程

本来是在百度上随便搜索一个方法操作,因为之前有弄过,但是详细流程比较模糊,所以找个文档参考一下,但是在过程中始终无法正常完成替换,后面我想到我用的是系统是比较新的,可能方法有些不一样,所以我在我自己的博客上通过记录的各个开源软件镜像站,使用阿里云、腾讯云、华为云的替换方法均报错,报错内容如下(以华为云镜像为例):

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
https://repo.huaweicloud.com/centos/2.xxxx/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.


 One of the configured repositories failed (CentOS-2.xxxx - AppStream - repo.huaweicloud.com),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=AppStream ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable AppStream
        or
            subscription-manager repos --disable=AppStream

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=AppStream.skip_if_unavailable=true

failure: repodata/repomd.xml from AppStream: [Errno 256] No more mirrors to try.
https://repo.huaweicloud.com/centos/2.xxxx/AppStream/x86_64/os/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found

在以上问题出现后,再经过多种方法后,依然无果,遂找到阿里云售后,但是对方也是找文档办事,一个一个文档的发过来,后面通过一个 shell 的方法来尝试,但是又报另外一个错误,但就在我准备放弃的时候,我再看了一眼上面的报错内容,我发现上面报错内容中 URL 对应的 centos/2.xxxx/AppStream 看起来好像不是很正常,我想到这个就是版本号呀,但是 CentOS 现在基本是 6/7/8 的版本号,怎么会获取到 2 起始的版本号,这时我恍然大悟,原来系统是通过变量来获取当前最新的版本,而我的系统又是 Alinux(即 Aliyun Linux),通过查看系统发行版本已知系统内置版本为 2.xxxx:

cat /etc/os-release
NAME="Alibaba Cloud Linux (Aliyun Linux)"
VERSION="2.xxxx LTS (Hunting Beagle)"
ID="alinux"
ID_LIKE="rhel fedora centos anolis"
VERSION_ID="2.xxxx"
PRETTY_NAME="Alibaba Cloud Linux (Aliyun Linux) 2.xxxx LTS (Hunting Beagle)"
ANSI_COLOR="0;31"
HOME_URL="https://www.aliyun.com/"

由此,我即在替换华为云的软件包镜像源后,将下载并重命名的 CentOS-Base.repo 修改内容里 $releasever 替换为 8,再次尝试,果然成功~!

附:华为云 CentOS 软件包镜像源配置说明

https://mirrors.huaweicloud.com/home

1、备份配置文件:
cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2、下载新的 CentOS-Base.repo 文件到/etc/yum.repos.d/目录下,选择 CentOS 版本:
执行如下命令:
CentOS 8
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-8-reg.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo

3、执行 yum clean all 清除原有 yum 缓存。

4、执行 yum makecache(刷新缓存)或者 yum repolist all(查看所有配置可以使用的文件,会自动刷新缓存)。

yum 测试仓库镜像列表成功

yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                  repo name                                                                status
AppStream/x86_64                         CentOS-x.xxxx - AppStream - repo.huaweicloud.com                         6,397
BaseOS/x86_64                            CentOS-x.xxxx - Base - repo.huaweicloud.com                              1,786
PowerTools/x86_64                        CentOS-x.xxxx - PowerTools - repo.huaweicloud.com                        2,260
extras/x86_64                            CentOS-x.xxxx - Extras - repo.huaweicloud.com                               38
repolist: 10,481

附:阿里云添加软件源官方文档

https://developer.aliyun.com/mirror/centos

https://help.aliyun.com/document_detail/120851.html


友情提示:本站所有文章,如无特殊说明或标注,均为何星星原创发布。与此同时,趋于近年来本站的文章内容频繁被他站盗用与机器采集,现已全局禁用网站文字内容操作,了解详情或转载文章请 点此 继续!

0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用 * 标注