linux更换为阿里云的yum下载镜像源

发布于:2024-08-18 ⋅ 阅读:(143) ⋅ 点赞:(0)

更换镜像源

1.备份:

sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

 2.创建一个文件:

cd  /etc/yum.repos.d/

touch CentOS-Base.repo

3.往CentOS-Base.repo添加内容

vi  CentOS-Base.repo

添加以下内容:

[base]  
name=CentOS-\$releasever - Base - mirrors.aliyun.com  
baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/  
gpgcheck=1  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7  
  
[updates]  
name=CentOS-\$releasever - Updates - mirrors.aliyun.com  
baseurl=http://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/  
gpgcheck=1  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7  
  
[extras]  
name=CentOS-\$releasever - Extras - mirrors.aliyun.com  
baseurl=http://mirrors.aliyun.com/centos/\$releasever/extras/\$basearch/  
gpgcheck=1  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7  
  
[centosplus]  
name=CentOS-\$releasever - Plus - mirrors.aliyun.com  
baseurl=http://mirrors.aliyun.com/centos/\$releasever/centosplus/\$basearch/  
gpgcheck=1  
enabled=0  
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 

清理并重建缓存

yum clean all

yum makecache

 遇到的问题

在更换完镜像源后使用yum makecache命令提示错误

解决办法:

解析DNS

vi /etc/sysconfig/network-scripts/ifcfg-ens33

新增DNS

DNS1=8.8.8.8

DNS2=8.8.4.4 

重启network

service network restart 

更新yum

yum update -y