/ 下载阿里云源文件
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
// 替换 阿里云镜像地址
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
// 建立缓存
yum makecache
但是很多时候,执行makecache特别慢,是因为CentOS-AppStream.repo的镜像还没改:
直接暴力修改:
vim /etc/yum.repos.d/CentOS-AppStream.repo
修改这个为:
baseurl=https://mirrors.aliyun.com/centos/basearch/os/
完成的内容如下:
[AppStream]
name=CentOS-$releasever - AppStream
加上这一条就行了
baseurl=https://mirrors.aliyun.com/centos/basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
之后执行
yum clean all
yum makecache
Centos7更新阿里源:
- 备份原镜像文件,便于后期恢复
$sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2.下载新的CentOS-Base.repo 到/etc/yum.repos.d/
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
- 清除缓存
yum clean all
- 生成缓存
yum makecache