当前位置: 首页 > news >正文

CentOS7.6 yum无法下载

报错

Loaded plugins: fastestmirror
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#52 - "Empty reply from server"


 One of the configured repositories failed (Unknown),
 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=<repoid> ...

     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 <repoid>
        or
            subscription-manager repos --disable=<repoid>

     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=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

但是对网站的访问并不受限

[root@localhost ~]# ping mirrorlist.centos.org
PING mirrorlist.centos.org (198.18.2.200) 56(84) bytes of data.
64 bytes from 198.18.2.200 (198.18.2.200): icmp_seq=1 ttl=128 time=1.34 ms
64 bytes from 198.18.2.200 (198.18.2.200): icmp_seq=2 ttl=128 time=0.728 ms
^C
--- mirrorlist.centos.org ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 0.728/1.037/1.347/0.311 ms

解决方案

这个错误表明你的 CentOS 7 系统在尝试访问 `mirrorlist.centos.org` 时遇到了问题,导致 `yum` 无法获取仓库镜像列表。以下是可能的原因和解决方案:

---

### **可能的原因**
1. **CentOS 7 已进入 EOL(End of Life)**  
   - CentOS 7 官方支持已于 **2024年6月30日** 结束,官方镜像 (`mirrorlist.centos.org`) 可能已不再维护或重定向到存档站点。
   - 你需要切换到 **CentOS Vault**(存档仓库)或升级到 CentOS Stream 8/9 或其他替代系统(如 Rocky Linux / AlmaLinux)。

2. **网络问题**  
   - 虽然 `ping` 能通,但 `curl` 无法获取数据,可能是防火墙、DNS 或代理问题。
   - 也可能是 `mirrorlist.centos.org` 的 HTTP 服务未响应。

3. **DNS 解析问题**  
   - 检查是否能正确解析 `mirrorlist.centos.org`:
     ```bash
     nslookup mirrorlist.centos.org
     ```
   - 如果解析失败,尝试更换 DNS(如 `8.8.8.8` 或 `1.1.1.1`)。

---

### **解决方案**
#### **方法 1:切换到 CentOS Vault(存档仓库)**
由于 CentOS 7 已停止支持,你需要手动修改 `yum` 配置,使用存档镜像:
```bash
sudo sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sudo sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
```
然后清理缓存并测试:
```bash
sudo yum clean all
sudo yum makecache
sudo yum update
```

#### **方法 2:检查网络连接**
1. **测试 HTTP 访问**  
   运行以下命令检查是否能获取镜像列表:
   ```bash
   curl -v http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock
   ```
   - 如果返回 `Empty reply`,说明服务器无响应(可能是 EOL 导致的关闭)。

2. **检查代理 / 防火墙**  
   - 如果你在公司网络或使用代理,确保 `http_proxy` 和 `https_proxy` 环境变量正确设置。
   - 检查防火墙是否允许 HTTP/HTTPS 访问:
     ```bash
     sudo iptables -L
     ```

3. **临时禁用仓库测试**  
   你可以尝试禁用默认仓库并使用其他镜像:
   ```bash
   sudo yum --disablerepo=base,extras,updates --enablerepo=epel test
   ```

#### **方法 3:升级系统或迁移到替代发行版**
- **升级到 CentOS Stream 8/9**(滚动发行版,替代传统 CentOS)。
- **迁移到 Rocky Linux / AlmaLinux**(RHEL 的免费替代品,兼容 CentOS)。
- 如果只是测试环境,可以考虑换成 Ubuntu / Debian。

---

### **总结**
- **如果只是临时修复** → 使用 **CentOS Vault**(方法 1)。
- **如果长期使用** → 建议 **升级或迁移到新系统**(如 Rocky Linux / AlmaLinux)。
- **如果网络问题** → 检查代理、防火墙或 DNS(方法 2)。

相关文章:

  • 《HTTP权威指南》 第14章 安全HTTP
  • 小木的算法日记——合成两个有序链表
  • 系统思考:救火先放火
  • 优化通义大模型推理性能:企业级场景下的延迟与成本削减策略
  • 桌面小屏幕实战课程:DesktopScreen 3 Git工具使用
  • 21.安卓逆向2-frida hook技术-HookOkHttp的拦截器
  • 数智管理学(二十四)
  • C++ -- AVL树的插入和旋转
  • Linux 线程调度管理函数
  • leetcode:21. 合并两个有序链表
  • 华为云Flexus+DeepSeek征文|基于Dify构建解析网页写入Notion笔记工作流
  • 【C++】C++枚举、const、static的用法
  • LLM存储优化:大量长对话解决方案
  • C++ - 标准库之 <string> npos(npos 概述、npos 的作用)
  • 开发云数据库
  • 数据库索引结构 B 树、B + 树与哈希索引在不同数据查询场景下的适用性分析
  • 深入剖析Flink内存管理:架构、调优与实战指南
  • 透视618:头部主播隐退、购物氛围变淡,新秩序正在建立
  • AAudio:Android 低延迟音频处理的核心组件
  • 基于SpringBoot的RestTemplate
  • 网站设计的逻辑/ip域名查询网站入口
  • 新郑做网站/佛山网站建设十年乐云seo
  • 商业网站设计方案/什么是优化师
  • 福州网站制作公司营销/网站老域名跳转到新域名
  • 网站制作花多少钱/最近一两天的新闻有哪些
  • 杭州做网站的公司/如何进行电子商务网站推广