#使用 yum下载 wget
yum -y install wget
#将 /etc/yum.repos.d/目录下的所有文件移动到 /tmp/目录下
mv /etc/yum.repos.d/* /tmp/
任选其一进行下载,命令中 -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
生成缓存前最好先执行 yum clean all 清理一下缓存
yum clean all
如下图所示(华为源),通过 yum repolist 可以查看仓库配置情况,总包个数等信息。
yum repolist
配置镜像源仓库就是将下载源的配置文件存放在 /etc/yum.repos.d/目录中,且文件名必须以 .repo 结尾,否则系统无法识别。
附:CentOS 7 仍在维护,但一些老旧版本已转移到 vault.centos.org。可以尝试切换到 vault 源。
编辑 /etc/yum.repos.d/CentOS-Base.repo 文件:
sudo vi /etc/yum.repos.d/CentOS-Base.repo
修改 [base]、[updates]、[extras] 为如下内容:
[base] name=CentOS-$releasever - Base baseurl=http://vault.centos.org/7.9.2009/os/$basearch/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [updates] name=CentOS-$releasever - Updates baseurl=http://vault.centos.org/7.9.2009/updates/$basearch/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [extras] name=CentOS-$releasever - Extras baseurl=http://vault.centos.org/7.9.2009/extras/$basearch/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
清理缓存并更新:
sudo yum clean all sudo yum makecache