在 CentOS 7 上配置中国源(镜像)来加快软件包下载速度的步骤:
更改 CentOS 7 的镜像源为中国镜像
- 备份原始的仓库配置
在修改之前,建议备份当前的仓库配置文件:
bash
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
- 编辑仓库配置
打开仓库配置文件进行编辑:
bash
sudo vi /etc/yum.repos.d/CentOS-Base.repo
- 将文件内容替换为以下中国镜像的配置:
阿里云 (Aliyun)
ini
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/repodata/repomd.xml.key
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/repodata/repomd.xml.key
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/repodata/repomd.xml.key
163 镜像 (163.com)
ini
[base]
name=CentOS-$releasever - Base - mirrors.163.com
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/$releasever/updates/$basearch/repodata/repomd.xml.key
[updates]
name=CentOS-$releasever - Updates - mirrors.163.com
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/$releasever/updates/$basearch/repodata/repomd.xml.key
[extras]
name=CentOS-$releasever - Extras - mirrors.163.com
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/$releasever/extras/$basearch/repodata/repomd.xml.key
清华大学镜像 (Tsinghua University)
ini
[base]
name=CentOS-$releasever - Base - mirrors.tuna.tsinghua.edu.cn
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/repodata/repomd.xml.key
[updates]
name=CentOS-$releasever - Updates - mirrors.tuna.tsinghua.edu.cn
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/repodata/repomd.xml.key
[extras]
name=CentOS-$releasever - Extras - mirrors.tuna.tsinghua.edu.cn
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/repodata/repomd.xml.key
保存并关闭文件。
- 清除 YUM 缓存
清除 YUM 缓存,以确保使用更新后的仓库配置:
bash
sudo yum clean all
- 更新 YUM 仓库
更新仓库元数据:
bash
sudo yum makecache
- 验证新的仓库配置
检查已启用的仓库列表,以确认更改:
bash
yum repolist
这将帮助你将 CentOS 7 配置为使用更快的中国镜像源,从而提高软件包的下载速度。