Centos 修改 yum 源为阿里云

参考

https://serverfault.com/questions/1161816/mirrorlist-centos-org-no-longer-resolve

修改 Centos 的 yum 源为阿里云

去阿里云 yum 镜像源官网:

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

选择自己对应的操作系统,这里以 centos7 演示:

先备份原 yum 配置文件:

shell 复制代码
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载了阿里云提供的 CentOS 7 的 Yum 源配置文件,并将其覆盖到系统中的 /etc/yum.repos.d/CentOS-Base.repo 文件:

shell 复制代码
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

# 或使用 curl 下载文件
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

清除旧缓存:

shell 复制代码
sudo yum clean all

生成新缓存:

shell 复制代码
sudo yum makecache

检验新配置是否生效:

shell 复制代码
yum repolist

提示不能解析 mirrorlist.centos.org

shell 复制代码
Could not retrieve mirrorlist http://mirrorlist.centos.org?arch=x86_64&release=7&repo=sclo-rh error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"


 One of the configured repositories failed (未知),
 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=<repoid> ...

     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 <repoid>
        or
            subscription-manager repos --disable=<repoid>

     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=<repoid>.skip_if_unavailable=true

执行如下命令:

shell 复制代码
sudo sed -i s/mirror.centos.org/vault.centos.org/g /etc/yum.repos.d/CentOS-*.repo
sudo sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/CentOS-*.repo
sudo sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/CentOS-*.repo
相关推荐
yuanzhengme6 分钟前
Shell【脚本 02】离线安装配置Zookeeper及Kafka并添加service服务和开机启动(脚本分析)
linux·zookeeper·kafka·自动化·安装脚本
Johny_Zhao1 小时前
阿里云平台健康检查巡检清单-运维篇
linux·网络安全·阿里云·信息安全·云计算·shell·系统运维
来自于狂人1 小时前
CentOS 镜像源配置与 EOL 后的应对策略
linux·运维·centos
博语小屋2 小时前
进程初识之进程状态
linux
吉凶以情迁2 小时前
window服务相关问题探索 go语言服务开发探索调试
linux·服务器·开发语言·网络·golang
数智前线3 小时前
谁在托举Agent?阿里云抢滩Agent Infra新赛道
阿里云·云计算
潮湿的心情3 小时前
中宇联:以“智云融合+AI”赋能全栈云MSP服务,深化阿里云生态合作
人工智能·阿里云·云计算
云布道师3 小时前
【云故事探索】NO.16:阿里云弹性计算加速精准学 AI 教育普惠落地
人工智能·阿里云·云计算
阿里云云原生3 小时前
阿里云微服务引擎 MSE 及 API 网关 2025 年 7 月产品动态
阿里云·微服务·云计算
柏木乃一4 小时前
Linux初步认识与指令与权限
linux·运维·服务器·shell·权限