配置阿里云yum镜像源报错: One of the configured repositories failed (CentOS-$releasever - Base - mirrors.aliyun
本文记录了在CentOS 7系统上配置阿里云yum镜像源和安装Docker时遇到的典型问题及解决方案。主要问题包括:1)$releasever变量未解析导致404错误,通过手动替换为版本号7解决;2)Docker社区版安装时出现软件包下载失败,通过改用清华镜像源最终成功安装。关键解决步骤包括:修改repo文件中的$releasever为具体版本号、清理缓存重建元数据、更换镜像源等。整个过程展示了L
1、配置阿里云yum镜像源报错
原因是$releasever找不到相关的变量值,需要改一下配置文件,手动指定一下相关的发行版本,报错如下:
One of the configured repositories failed (CentOS-$releasever - Base - mirrors.aliyun.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=base ...
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 base
or
subscription-manager repos --disable=base
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=base.skip_if_unavailable=true
failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
2、解决方法:
直接编辑 /etc/yum.repos.d/CentOS-Base.repo文件,将所有 $releasever替换为具体的版本号(例如 7)
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
3. 验证修复结果
完成修复后,执行以下命令测试:
# 清理旧缓存
yum clean all
# 重新建立元数据缓存
yum makecache
# 测试列出可用更新
yum list available
需要用yum下载docker,但yum源加了docker社区版后,发现,还是有报错,执行逻辑:
4、安装 yum-utils包(它提供了 yum-config-manager工具)
yum install -y yum-utils
5、执行命令加载docker yum 源,添加阿里云 Docker CE 镜像仓库:
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
6、更新 Yum 缓存
yum makecache
然后发现报错:
https://mirrors.aliyun.com/docker-ce/linux/centos/%24releasever/x86_64/stable/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
正在尝试其它镜像。
To address this issue please refer to the below wiki article
https://wiki.centos.org/yum-errors
If above article doesn't help to resolve this issue please use https://bugs.centos.org/.
One of the configured repositories failed (Docker CE Stable - x86_64),
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=docker-ce-stable ...
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 docker-ce-stable
or
subscription-manager repos --disable=docker-ce-stable
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=docker-ce-stable.skip_if_unavailable=true
failure: repodata/repomd.xml from docker-ce-stable: [Errno 256] No more mirrors to try.
https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/x86_64/stable/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
原因:
错误的核心是Docker CE 的 repo 文件配置中的 %24releasever 找不到导致,导致 URL 拼写错误。
-
错误信息显示:
链接1%24releasever/x86_64/stable/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found -
%24是$的 URL 编码,说明$releasever没有被替换成实际的版本号 -
直接访问了不存在的 URL:
https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/x86_64/stable/
解决方法:
批量修改 $releasever为实际版本号命令,如7
sed -i 's/\$releasever/7/g' /etc/yum.repos.d/docker-ce.repo
重建缓存
yum makecache
重新安装 Docker
yum install -y docker-ce
结果遇到如下错误,这是阿里云镜像的docker-compose-plugin包的问题,换成其他镜像如清华镜像源即可
安装 5 软件包 (+5 依赖软件包)
总下载量:114 M
安装大小:401 M
Downloading packages:
(1/10): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm | 40 kB 00:00:00
warning: /var/cache/yum/x86_64/$releasever/docker-ce-stable/packages/containerd.io-1.6.33-3.1.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY ] 4.2 MB/s | 45 MB 00:00:16 ETA
containerd.io-1.6.33-3.1.el7.x86_64.rpm 的公钥尚未安装
(2/10): containerd.io-1.6.33-3.1.el7.x86_64.rpm | 35 MB 00:00:10
(3/10): docker-buildx-plugin-0.14.1-1.el7.x86_64.rpm | 14 MB 00:00:11
(4/10): docker-ce-26.1.4-1.el7.x86_64.rpm | 27 MB 00:00:07
(5/10): docker-ce-rootless-extras-26.1.4-1.el7.x86_64.rpm | 9.4 MB 00:00:02
docker-compose-plugin-2.27.1-1 FAILED
https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-compose-plugin-2.27.1-1.el7.x86_64.rpm: [Errno -1] 软件包与预期下载的不符。建议:运行 yum --enablerepo=docker-ce-stable clean metadata| 97 MB 00:00:03 ETA
正在尝试其它镜像。
(6/10): fuse3-libs-3.6.1-4.el7.x86_64.rpm | 82 kB 00:00:00
(7/10): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm | 54 kB 00:00:00
(8/10): slirp4netns-0.4.3-4.el7_8.x86_64.rpm | 81 kB 00:00:00
(9/10): docker-ce-cli-26.1.4-1.el7.x86_64.rpm | 15 MB 00:00:11
Error downloading packages:
docker-compose-plugin-2.27.1-1.el7.x86_64: [Errno 256] No more mirrors to try.
如何换清华镜像源:
rm -f /etc/yum.repos.d/docker-ce.repo
yum --enablerepo=docker-ce-stable clean metadata
yum clean all
sed -i 's|https://download.docker.com|https://mirrors.tuna.tsinghua.edu.cn/docker-ce|g' /etc/yum.repos.d/docker-ce.repo
yum-config-manager \
--add-repo \
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo
参考文章:
配置 Docker 镜像源,添加清华镜像源的 repo 配置文件后记得重新执行:
sed -i 's/\$releasever/7/g' /etc/yum.repos.d/docker-ce.repo
然后重新执行:
yum install -y docker-ce
发现安装成功,问题解决!

更多推荐



所有评论(0)