Bootstrap

【微知】如何将Centos8的yum镜像更换为阿里云的镜像?(/etc/yum.repos.d/CentOS-Base.repo, yum clean all, yum makecache)

背景

Centos官方镜像使用yum安装软件经常网络不可达,比如报错:

[root@localhost egypt-1.10]# yum install cpan
CentOS Stream 8 - AppStream 0.0 B/s | 0 B 00:00
Errors during downloading metadata for repository ‘appstream’:
- Curl error (6): Couldn’t resolve host name for http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]
Error: Failed to download metadata for repo ‘appstream’: Cannot prepare internal mirrorlist: Curl error (6): Couldn’t resolve host name for http://mirrorlist.centos.org/?release=8-stream&arch=x86_64&repo=AppStream&infra=stock [Could not resolve host: mirrorlist.centos.org]

将yum镜像源换成阿里云比较方便,本文简单记录更换方式。具体可参考:https://developer.aliyun.com/mirror/centos

实操

备份原有以及下载新的

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

在这里插入图片描述

清除原来的以及生成cache

yum clean all && yum makecache

如果还有访问centos官网的,可以直接到yum repos配置目录先移动或者删掉其他的repos

  • 报错
    在这里插入图片描述

  • 查看:
    在这里插入图片描述

  • 移动然后执行makecache
    在这里插入图片描述

然后执行原来报错的安装包

在这里插入图片描述
在这里插入图片描述

综述

  • 删除原有的/etc/yum.repos.d/CentOS-Base.repo
  • yum clean all清除原有数据
  • yum makecache重新生成缓存
  • 安装需要的命令
;