yum -y install wget 报错已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile 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: mirrorlis
时间: 2025-03-13 18:12:05 浏览: 354
### CentOS7 Yum 安装 Wget 报错 `Could not resolve host: mirrorlist.centos.org` 的解决方案
当执行 `yum install wget` 或其他基于 Yum 的操作时,如果遇到报错 `Could not resolve host: mirrorlist.centos.org`,这通常是因为系统的 DNS 配置不正确或 Yum 源配置存在问题。以下是具体的解决方法:
#### 修改 Yum 源配置
1. **备份原始的 Yum 源文件**
将现有的 `/etc/yum.repos.d/CentOS-Base.repo` 文件重命名为 `.bak` 后缀以便备份:
```bash
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
```
2. **下载新的 Yum 源文件**
使用阿里云或其他稳定镜像站点替换默认的 Yum 源文件。例如,通过以下命令获取阿里云的 Yum 源文件:
```bash
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
```
如果希望使用华为云镜像,则可以运行如下命令:
```bash
sudo wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-7-anon.repo
```
3. **清理并重建缓存**
替换完成后,清除旧的缓存数据并重新生成新缓存:
```bash
sudo yum clean all
sudo yum makecache
```
4. **验证网络连接**
确认主机能够正常访问外部互联网资源。可以通过测试 DNS 和 Ping 命令来完成此步骤:
```bash
nslookup mirrors.aliyun.com
ping mirrors.aliyun.com
```
若发现无法解析域名或超时现象,需进一步排查本地网络设置。
5. **尝试再次安装软件包**
执行初始失败的操作以确认问题已修复:
```bash
sudo yum install -y wget
```
以上过程解决了由于官方镜像不可达而导致的问题[^3]。
---
### 注意事项
- 更改后的 Yum 源应始终指向可靠的第三方镜像地址(如阿里云、腾讯云等),这些服务提供更稳定的国内访问支持。
- 对于某些特殊环境下的机器可能还需要调整防火墙规则允许必要的端口通信以及禁用 SELinux 来减少冲突可能性。
```python
print("成功解决问题后即可正常使用YUM工具进行各种应用部署工作啦!")
```
阅读全文
相关推荐














