替换完成之后,重新生成 cache

sudo yum clean all
sudo yum makecache

阿里源

国内源很多,但是感觉阿里官方文档清晰,操作也最简单

全部阿里源

阿里CentOS 镜像

这里只抄录一下 CentOS 7

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

epel(RHEL 7)

wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

清华源 (tuna)

CentOS 镜像使用帮助

如果是直接替换CentOS官方源 (http://mirror.centos.org/),操作还是比较方便
但是,如果已经替换过国内其他源,就需要手动修改下面的操作脚本

抄录 Centos 7 部分

  1. 建议先备份 /etc/yum.repos.d/ 内的文件。

  2. 然后编辑 /etc/yum.repos.d/ 中的相应文件,在 mirrorlist= 开头行前面加 # 注释掉;并将 baseurl= 开头行取消注释(如果被注释的话)。 对于 CentOS 7 ,请把该行内的域名(例如mirror.centos.org)替换为 mirrors.tuna.tsinghua.edu.cn。 对于 CentOS 8 ,请把 mirror.centos.org/$contentdir 替换为 mirrors.tuna.tsinghua.edu.cn/centos。

  3. 以上步骤可以被下方的命令一步完成

     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
    

腾讯源

之前没有使用过,这里有个比较清晰的文档,操作很方便

centos更换国内源——腾讯云源

源清单在这里

抄录Centos7 部分

  1. 备份系统旧配置文件

     mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    
  2. CentOS 7

     wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
    

中科大源 (ustc)

CentOS 源使用帮助
和清华源操作方式基本上一样

抄录Centos7 部分

  1. 对于 CentOS 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
    

以上命令只替换了默认启用的仓库。替换之后请运行 yum makecache 更新缓存。

2。 以下是替换之后的文件样本

CentOS 7:
/etc/yum.repos.d/CentOS-Base.repo 文件:

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=https://mirrors.ustc.edu.cn/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐