CentOS 7 执行yum命令报错

CentOS 7 执行yum命令报错

引言

CentOS 7 系统无法连接到 CentOS 的官方镜像站点。这通常是由于网络问题或 CentOS 7 已停止维护导致的(2024年6月30日后 CentOS 7 已进入 EOL)

报错明细:

已加载插件:fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - “Could not resolve host: mirrorlist.centos.org; 未知的错误”
One of the configured repositories failed (未知),
and yum doesn’t have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work “fix” this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=4. Disable the repository permanently, so yum won’t use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable
or
subscription-manager repos --disable=
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=.skip_if_unavailable=true
Cannot find a valid baseurl for repo: base/7/x86_64

解决办法 更新yum源

备份原有源

mkdir -p /etc/yum.repos.d/backup
mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/backup/

创建新的源文件

cat > /etc/yum.repos.d/CentOS-Base.repo <<'EOF'
[base]
name=CentOS-7 - Base
baseurl=https://vault.centos.org/7.9.2009/os/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1

[updates]
name=CentOS-7 - Updates
baseurl=https://vault.centos.org/7.9.2009/updates/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1

[extras]
name=CentOS-7 - Extras
baseurl=https://vault.centos.org/7.9.2009/extras/x86_64/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
EOF

清理并重建缓存

yum clean all
yum makecache
### 解决 CentOS 中 `yum` 命令报错的方法 对于 CentOS 8 和 CentOS 7 用户,在执行 `yum` 命令时可能会遇到不同的错误消息。以下是针对这些错误的具体解决方案。 #### 错误一:Failed to set locale 和 Failed to download metadata for repo 'appstream' 当运行 `yum` 命令报错 “Failed to set locale” 或者 “Failed to download metadata for repo ‘appstream’”,这通常发生在 CentOS 8 上。这类问题可以通过更新系统的区域设置或者更换镜像源来解决[^1]。 为了更改镜像源,可以按照如下操作: ```bash sudo mv /etc/yum.repos.d/CentOS-Linux-AppStream.repo /etc/yum.repos.d/CentOS-Linux-AppStream.repo.bak sudo curl -o /etc/yum.repos.d/CentOS-Linux-AppStream.repo http://mirror.centos.org/centos/$releasever/AppStream/x86_64/os/ ``` #### 错误二:Another app is currently holding the yum lock; waiting for it to exit 如果收到此提示,则意味着有另一个进程正在占用 YUM 数据库锁文件 `/var/run/yum.pid` 或者 `/var/lib/rpm/__db.*` 文件被锁定。此时应该等待其他程序完成其任务后再尝试,也可以手动删除上述提到的 PID 文件或 RPM 数据库中的临时文件以解锁[^2]。 #### 错误三:Could not resolve host: mirrorlist.centos.org;Name or service not known 该问题是由于 CentOS 7 的官方支持已终止,并且默认仓库已被迁移至归档位置所致。这意味着即使使用最新版的 CentOS 7,默认情况下也无法正常访问官方提供的软件包资源。建议采取以下措施之一来修复这个问题[^3]: - 更改本地主机上的 DNS 设置; - 使用第三方提供的活跃镜像站点作为新的下载源; - 将现有的基础配置替换为来自阿里云或其他可靠提供商的新版本。 具体做法是在终端里输入下面几条指令来进行修改: ```bash cd /etc/yum.repos.d/ sudo cp CentOS-Base.repo CentOS-Base.repo.backup sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo ``` 通过以上步骤能够有效地解决问题并恢复正常的包管理功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

FBI HackerHarry浩

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值