centos8.5本地yum源报错

在下载文件出现以下错误

[root@server ~]# yum install gcc
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

RHEL8.5-BaseOS                                                                                        0.0  B/s |   0  B     00:00    
Errors during downloading metadata for repository 'BaseOS':
  - Curl error (37): Couldn't read a file:// file for file:///mnt/BaseOS/repodata/repomd.xml [Couldn't open file /mnt/BaseOS/repodata/repomd.xml]
Error: Failed to download metadata for repo 'BaseOS': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried

原因:CentOS 8操作系统版本结束了生命周期

解决方案:

1、删除或者备份 /etc/yum.repos.d 路径下的本地yum文件,我这里的是base.repo

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

2、访问阿里云官网centos镜像_centos下载地址_centos安装教程-阿里巴巴开源镜像站,根据官方步骤,将yum源切换成阿里云的。

1)下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/

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

2)运行 yum makecache 生成缓存

yum makecache

3)CentOS 8 结束生命周期切换源

公网用户:

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

yum clean all && yum makecache

阿里云ecs用户:

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 http://mirrors.cloud.aliyuncs.com/repo/Centos-vault-8.5.2111.repo

sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/CentOS-Base.repo && sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/CentOS-Base.repo && 
sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo

yum clean all && yum makecache

3、非阿里云ECS用户会出现 Couldn't resolve host 'mirrors.cloud.aliyuncs.com' 信息,不影响使用。用户也可自行修改相关配置: eg:

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

 至此安装成功

如果下载速度过慢,访问阿里云容器镜像服务->镜像工具->镜像加速器,进行里面的配置(阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台

如果出现报错Failed to restart docker.service: Unit docker.service not found. 这是因为输入docker命令会自动将docker变成podman,所以需要用systemctl restart podman命令

### 解决CentOS 8YUM命令错误的方法 对于CentOS 8中的YUM命令出现问题的情况,可以采取一系列措施来解决问题并恢复系统的正常功能。官方支持结束后的系统可能会遇到软件仓库不可用的问题,因此需要调整配置以继续获得必要的更新和支持。 #### 备份和清理配置文件 为了防止意外丢失重要数据,在执行任何更改之前先备份`/etc/yum.repos.d/`目录下的所有文件是一个明智的选择。这可以通过简单的复制操作完成: ```bash cp -r /etc/yum.repos.d ~/yum_repos_backup/ ``` 接着清除该目录内的旧有配置文件,以便重新设置新的资库链接[^1]。 #### 清理YUM缓存 通过运行以下命令清空本地存储的元数据和其他临时文件,有助于消除由于过期或损坏的数据引起的潜在冲突: ```bash yum clean all ``` 此过程会移除所有已下载的头文件、RPM 文件以及数据库记录,从而确保后续的操作基于最新的在线信息进行处理。 #### 配置使用Vault Repository 鉴于官方已经停止了对某些版本的支持,转向社区维护或者更稳定的替代方案成为必要选项之一。针对这种情况,建议切换至CentOS Vault repository作为主要依赖。具体做法是在`/etc/yum.repos.d/CentOS-Linux-Vault.repo`创建一个新的repo定义文件,并指定目标版本号(例如8.5.2111),如下所示: ```ini [baseos] name=CentOS-$releasever - BaseOS mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra #baseurl=http://vault.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial [appstream] name=CentOS-$releasever - AppStream mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra #baseurl=http://vault.centos.org/$contentdir/$releasever/AppStream/$basearch/os/ gpgcheck=1 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial ``` 请注意上述模板适用于大多数场景;如果特定需求存在差异,则需相应调整参数值。 #### 安装兼容性包 考虑到部分应用程序可能依赖于较早版本的OpenSSL或其他组件,安装像`compat-openssl10`这样的向后兼容性的软件包可以帮助解决因API变更引发的应用层面上的问题[^3]。 ```bash dnf install compat-openssl10 ``` 以上步骤综合起来能够有效应对CentOS 8上可能出现的各种YUM相关问题,保障系统的稳定性和安全性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值