在 CentOS 7 上配置中国源

在 CentOS 7 上配置中国源(镜像)来加快软件包下载速度的步骤:

更改 CentOS 7 的镜像源为中国镜像

  1. 备份原始的仓库配置

在修改之前,建议备份当前的仓库配置文件:

bash 复制代码
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
  1. 编辑仓库配置

打开仓库配置文件进行编辑:

bash 复制代码
sudo vi /etc/yum.repos.d/CentOS-Base.repo
  1. 将文件内容替换为以下中国镜像的配置:

阿里云 (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

保存并关闭文件。

  1. 清除 YUM 缓存

清除 YUM 缓存,以确保使用更新后的仓库配置:

bash 复制代码
sudo yum clean all
  1. 更新 YUM 仓库

更新仓库元数据:

bash 复制代码
sudo yum makecache
  1. 验证新的仓库配置

检查已启用的仓库列表,以确认更改:

bash 复制代码
yum repolist

这将帮助你将 CentOS 7 配置为使用更快的中国镜像源,从而提高软件包的下载速度。

相关推荐
远游客07131 小时前
centos stream 8下载安装遇到的坑
linux·服务器·centos
jingyu飞鸟1 小时前
centos-stream9系统安装docker
linux·docker·centos
cominglately4 小时前
centos单机部署seata
linux·运维·centos
魏 无羡4 小时前
linux CentOS系统上卸载docker
linux·kubernetes·centos
CircleMouse4 小时前
Centos7, 使用yum工具,出现 Could not resolve host: mirrorlist.centos.org
linux·运维·服务器·centos
木子Linux5 小时前
【Linux打怪升级记 | 问题01】安装Linux系统忘记设置时区怎么办?3个方法教你回到东八区
linux·运维·服务器·centos·云计算
mixboot11 小时前
CentOS 7.9 ISO 镜像下载
centos·iso·centos 7.9
阿里嘎多学长1 天前
centos怎么安装haproxy
linux·运维·服务器·centos
helloasimo1 天前
CentOS下,离线安装vscode的步骤;
linux·运维·centos
Web项目开发2 天前
GoCD 持续集成和部署工具配置指南(CentOS 7)
linux·ci/cd·centos