上一篇
最新消息(2025年8月):近期国内主流镜像站(如阿里云、腾讯云、华为云)已全面支持CentOS 7/8/Stream的稳定同步,部分高校镜像站因带宽调整可能暂时访问较慢,建议优先选择大厂镜像源以保证下载速度。
默认情况下,CentOS使用官方源(mirror.centos.org),但由于服务器在国外,国内用户直接访问可能速度慢、不稳定,甚至频繁超时,换成国内镜像源可以显著提升软件包下载速度,让yum/dnf
操作更流畅。
确认系统版本
执行以下命令查看当前CentOS版本:
cat /etc/redhat-release
输出类似:
CentOS Linux release 7.9.2009 (Core)
或
CentOS Stream release 8
备份原有源
为避免配置错误导致无法恢复,先备份默认源文件:
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
下载阿里云镜像源配置文件:
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
更新缓存:
sudo yum clean all && sudo yum makecache
下载对应版本的repo文件(注意区分CentOS 8和Stream):
# CentOS 8(非Stream) sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo # CentOS Stream 8 sudo curl -o /etc/yum.repos.d/CentOS-Stream.repo http://mirrors.aliyun.com/repo/CentOS-Stream-8.repo
更新元数据:
sudo dnf clean all && sudo dnf makecache
如果阿里云不适合你的网络环境,可替换为以下镜像站(操作步骤类似):
腾讯云
# CentOS 7 sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.tencentyun.com/help/CentOS7-Base.repo
华为云
# CentOS 7 sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-7-reg.repo
清华大学镜像站
# CentOS 7 sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos7.repo
ping mirrors.aliyun.com
114.114.114
: echo "nameserver 114.114.114.114" | sudo tee /etc/resolv.conf
/etc/yum.repos.d/
下其他冲突的repo文件。 Stream版本更新策略激进,换源后建议定期执行:
sudo dnf update --refresh
运行以下命令查看当前使用的镜像URL:
sudo yum repolist all # CentOS 7 sudo dnf repolist all # CentOS 8/Stream
输出中应显示mirrors.aliyun.com
等国内域名。
:换源是CentOS运维的基础操作,能极大提升效率,建议根据实际网络环境选择镜像站,遇到问题优先检查repo文件格式和网络连通性。
本文由 驹玛丽 于2025-08-01发表在【云服务器提供商】,文中图片由(驹玛丽)上传,本平台仅提供信息存储服务;作者观点、意见不代表本站立场,如有侵权,请联系我们删除;若有图片侵权,请您准备原始证明材料和公证书后联系我方删除!
本文链接:https://vps.7tqx.com/wenda/508675.html
发表评论