前言

在linux中默认 yum仓库是国外地址,因此使用 yum命令下载服务速度较慢,所以配置国内仓库镜像源,可以大大加快服务下载速度。国内大型 yum仓库镜像源有阿里源、清华源、华为源等。以下操作步骤等,均在Centos7版本中测试。

1. 国内镜像源地址

阿里源:https://developer.aliyun.com/mirror
阿里巴巴开源镜像站,免费提供Linux镜像下载服务,拥有Ubuntu、CentOS、Deepin、MongoDB、Apache、Maven、Composer等多种开源软件镜像源,此外还提供域名解析DNS、网络授时NTP等服务,致力于为互联网用户提供全面,高效和稳定的基础服务。icon-default.png?t=N7T8https://developer.aliyun.com/mirror/

清华源:centos | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirrorcentos 使用帮助 | 镜像站使用帮助 | 清华大学开源软件镜像站,致力于为国内和校内用户提供高质量的开源软件镜像、Linux 镜像源服务,帮助用户更方便地获取开源软件。本镜像站由清华大学 TUNA 协会负责运行维护。icon-default.png?t=N7T8https://mirror.tuna.tsinghua.edu.cn/help/centos/

华为源:华为开源镜像站软件开发服务华为云华为云DevCloud团队提供的全类型镜像站服务,提供主流开发语言组件、操作系统、常用工具和库等镜像,极速下载,全站CDN,官方合作。icon-default.png?t=N7T8https://mirrors.huaweicloud.com/home

2. 在 Centos 中操作

2.1 下载 wget
#使用 yum下载 wget
yum -y install wget
2.2 备份原文件
#将 /etc/yum.repos.d/目录下的所有文件移动到 /tmp/目录下
mv /etc/yum.repos.d/* /tmp/
2.3 下载镜像源仓库配置文件

任选其一进行下载,命令中 -O 后边跟的路径表示下载路径

# 阿里源
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

# 清华源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos/?action=download&filename=centos7
或
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos/?action=download&filename=centos7

# 华为源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-8-reg.repo
或
curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-8-reg.repo

阿里云

https://developer.aliyun.com/mirror/alinux?spm=a2c6h.13651102.0.0.6d641b11Cy41Tx
sed -i 's/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g' /etc/yum.repos.d/*.repo
2.4 运行 yum makecache 生成缓存

生成缓存前最好先执行 yum clean all 清理一下缓存

yum clean all && yum makecache
2.5 执行 yum repolist 查看是否配置成功

如下图所示(华为源),通过yum repolist 可以查看仓库配置情况,总包个数等信息。

总结

配置镜像源仓库就是将下载源的配置文件存放在 /etc/yum.repos.d/目录中,且文件名必须以 .repo 结尾,否则系统无法识别。

作者:Jeebiz  创建时间:2022-06-01 16:27
最后编辑:Jeebiz  更新时间:2024-08-20 17:39