阿里云Centos8 yum报错Failed to synchronize cache for repo ‘BaseOS‘解决方案,通过换文件的方式来解决。

起因:

在阿里云上买了个centos服务器,但是yum的时候报错,查了下是连不上微软的源。

报这个错误:Error: Failed to synchronize cache for repo 'BaseOS'

报错如下:

[root@iZbp1j62zviuaiizue37Z yum.repos.d]# yum install -y lrzsz
CentOS-8 - AppStream                              103 kB/s | 4.4 kB     00:00    
CentOS-8 - Base                                    56 kB/s | 2.3 kB     00:00    
Error: Failed to synchronize cache for repo 'BaseOS'

解决办法,有让换BaseOS的链接的,还有换源文件的。

下面我们采取换文件的方式

1、先删除文件

rm -rf /etc/yum.repos.d/CentOS-Base.repo

2、再下载文件

curl -o /etc/yum.repos.d/CentOS-Base.repo https://repo.huaweicloud.com/repository/conf/CentOS-8-reg.repo

3、清理老的缓存

dnf clean all

4、生成新的缓存

dnf repolist

5、执行完,出现下面的这个就可以了。

[root@iZbp1j62zviuaiizue37Z yum.repos.d]# dnf repolist
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
CentOS-8 - AppStream                              6.1 MB/s |  21 MB     00:03    
CentOS-8 - Base - repo.huaweicloud.com            2.9 MB/s | 4.6 MB     00:01    
CentOS-8 - PowerTools - repo.huaweicloud.com      3.8 MB/s | 2.3 MB     00:00    
CentOS-8 - Extras - repo.huaweicloud.com           34 kB/s |  10 kB     00:00    
repo id              repo name                                              status
AppStream            CentOS-8 - AppStream                                   15,665
BaseOS               CentOS-8 - Base - repo.huaweicloud.com                  1,896
PowerTools           CentOS-8 - PowerTools - repo.huaweicloud.com            1,693
extras               CentOS-8 - Extras - repo.huaweicloud.com                   38

### CentOS 7 中 YUM 报错 'cannot find a valid baseurl for repo:base/7/x86_64' 的解决方案 当遇到 `cannot find a valid baseurl for repo:base/7/x86_64` 错误时,通常是因为系统的 YUM 配置文件中的基础仓库地址不可访问或者配置错误。以下是具体的解决方法: #### 方法一:更阿里云镜像源 可以通过替默认的 YUM 源为阿里云镜像源来解决问题。具体操作如下: ```bash curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo ``` 执行该命令后,YUM 配置文件会被替阿里云的镜像源[^2]。 #### 方法二:手动编辑 YUM 配置文件 如果系统中未安装 `curl` 或其他工具,则可以手动编辑 `/etc/yum.repos.d/CentOS-Base.repo` 文件并将其内容替为以下内容: ```ini [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 ``` 完成上述更改后保存文件[^3]。 #### 方法三:清理并重新生成 YUM 缓存 无论采用哪种方式更新 YUM 源,在完成后都需要清除旧的缓存并生成新的缓存数据: ```bash yum clean all yum makecache ``` 以上步骤能够有效解决YUM 基础库 URL 不可用而导致的问题[^1]。 ---
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值