前言
在linux中默认 yum仓库是国外地址,因此使用 yum命令下载服务速度较慢,所以配置国内仓库镜像源,可以大大加快服务下载速度。国内大型 yum仓库镜像源有阿里源、清华源、华为源等。以下操作步骤等,均在Centos7版本中测试。
1.国内镜像源地址
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
2.4运行 yum makecache 生成缓存
生成缓存前最好先执行 yum clean all 清理一下缓存
2.5执行 yum repolist 查看是否配置成功
如下图所示(华为源),通过 yum repolist 可以查看仓库配置情况,总包个数等信息。
总结
配置镜像源仓库就是将下载源的配置文件存放在 /etc/yum.repos.d/目录中,且文件名必须以 .repo 结尾,否则系统无法识别。