备份
操作前请做好相应备份!
1 2
| # 备份 cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
|
阿里源
centos镜像_centos下载地址_centos安装教程-阿里巴巴开源镜像站 (aliyun.com)
注意
非阿里云ECS用户会出现 Couldn’t resolve host ‘mirrors.cloud.aliyuncs.com’ 信息,不影响使用。用户也可自行修改相关配置: eg:
1
| sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
|
CentOS 8
1 2 3 4 5 6 7 8
| # 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/ wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 或者使用curl curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 更新软件包缓存 sudo yum makecache
|
CentOS 7
1 2 3 4 5 6 7 8
| # 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/ 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
# 更新软件包缓存 sudo yum makecache
|
CentOS 6
centos-vault镜像_centos-vault下载地址_centos-vault安装教程-阿里巴巴开源镜像站 (aliyun.com)
centos-vault镜像
简介
其中CentOS-Vault.repo对应的是发行该镜像时的yum源版本,使用该镜像源可以下载发行镜像时的yum源。
下载地址:https://mirrors.aliyun.com/centos-vault/
配置方法
建议先备份 /etc/yum.repos.d/
内的文件。
需要确定您所需要的小版本,如无特殊需要则使用该大版本的最后一个小版本,比如 6.10,5.11,我们将其标记为 $minorver
,需要您在之后的命令中替换。
然后编辑 /etc/yum.repos.d/
中的相应文件,在 mirrorlist=
开头行前面加 #
注释掉;并将 baseurl=
开头行取消注释(如果被注释的话)。 对于 CentOS 8 之前的版本,请把该行内的域名及路径(例如mirror.centos.org/centos/$releasever
)替换为 mirrors.aliyun.com/centos-vault/$minorver
。 对于 CentOS 8 ,请注意域名及路径发生了更换,此时需要替换的字段为 http://mirror.centos.org/$contentdir/$releasever
。
以上步骤可以被下方的命令完成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| # 注意替换 minorver 变量 # Centos 6 minorver=6.10 sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \ -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo
# CentOS 8 minorver=8.5.2111 sudo sed -e "s|^mirrorlist=|#mirrorlist=|g" \ -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=https://mirrors.aliyun.com/centos-vault/$minorver|g" \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo # 更新软件包缓存 sudo yum makecache
|
注意
注意,如果需要启用其中一些 repo,需要将其中的 enabled=0
改为 enabled=1
。
清华源
centos | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror
CentOS 8
1 2 3 4 5 6 7 8
| # 对于 CentOS 8 sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos|g' \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo # 更新软件包缓存 sudo yum makecache
|
CentOS 7
1 2 3 4 5 6 7 8
| # 对于 CentOS 7 sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \ -i.bak \ /etc/yum.repos.d/CentOS-*.repo
# 更新软件包缓存 sudo yum makecache
|
中科大源
CentOS 源使用帮助 — USTC Mirror Help 文档
CentOS 8
1 2 3 4 5 6 7 8 9 10
| sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org/$contentdir|baseurl=https://mirrors.ustc.edu.cn/centos|g' \ -i.bak \ /etc/yum.repos.d/CentOS-Stream-AppStream.repo \ /etc/yum.repos.d/CentOS-Stream-BaseOS.repo \ /etc/yum.repos.d/CentOS-Stream-Extras.repo \ /etc/yum.repos.d/CentOS-Stream-PowerTools.repo # 更新软件包缓存 sudo yum makecache
|
CentOS 7
1 2 3 4 5 6 7
| sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://mirrors.ustc.edu.cn/centos|g' \ -i.bak \ /etc/yum.repos.d/CentOS-Base.repo # 更新软件包缓存 sudo yum makecache
|
以上命令只替换了默认启用的仓库。替换之后请运行 yum makecache
更新缓存。