centos更改国内镜像源

1.下载 wget

#使用 yum下载 wget

yum -y install wget


2备份原文件

#将 /etc/yum.repos.d/目录下的所有文件移动到 /tmp/目录下

mv /etc/yum.repos.d/* /tmp/


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


4运行 yum makecache 生成缓存

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

yum clean all


5执行 yum repolist 查看是否配置成功

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

 yum repolist

repolist


总结

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