445 字
2 分钟
CentOS7 YUM源配置
CentOS 7 在 2024 年 6 月 30 日已正式 EOL,官方 mirror.centos.org 上的 7 系列源全部下线。装好的 CentOS 7.9 (2009) 跑 yum makecache 会直接 404。处理方式是整体替换为阿里云或华为云保留的镜像。
1. 关闭防火墙和 SELinux
$ systemctl stop firewalld && systemctl disable firewalld$ setenforce 0$ sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config2. 配置 repo 仓库(阿里 / 华为二选一)
2.1 阿里云源
$ mv /etc/yum.repos.d/* /media/$ curl -o /etc/yum.repos.d/aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo$ yum clean all && yum makecache2.2 华为云源
$ mv /etc/yum.repos.d/* /media/$ curl -o /etc/yum.repos.d/huaweicloud.repo \ https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo$ yum clean all && yum makecache两个源选其一即可,不要同时启用——可能因为同名仓库 ID(
base、updates、extras)冲突而互相覆盖。
3. 安装 EPEL
CentOS 7 实际用起来还需要 EPEL 提供常用扩展包(如 nginx):
$ yum install -y epel-release# 把 EPEL 也切到国内$ sed -i 's|^#baseurl=https://download.example/pub|baseurl=https://mirrors.aliyun.com|' \ /etc/yum.repos.d/epel.repo$ sed -i 's|^metalink|#metalink|' /etc/yum.repos.d/epel.repo$ yum makecache4. 验证
$ yum repolist$ yum install -y vim wget tree5. 常见问题
| 现象 | 处理 |
|---|---|
makecache 报 Could not retrieve mirrorlist | 还有官方 repo 没挪走,再 mv /etc/yum.repos.d/CentOS-* /media/ 一次 |
| 个别包 404 | EOL 后阿里云会迁到 vault,需手动改为 https://mirrors.aliyun.com/centos-vault/7.9.2009/ |
| 安装新软件版本太老 | CentOS 7 已 EOL,新软件不再进库,生产环境建议尽快迁移到 Rocky 9 / AlmaLinux 9 |
| GPG 校验失败 | 在 repo 文件里设置 gpgcheck=0,或导入对应公钥 |
6. EOL 之后该怎么办
CentOS 7 进入 EOL 意味着:
- 没有官方安全补丁
- 第三方仓库(如 Docker 官方源)也会逐步停止 7 的支持
- 新版本应用越来越难装
推荐迁移方向:
- Rocky Linux 9 / AlmaLinux 9:CentOS 的精神续作,兼容 RHEL
- openEuler:国产,dnf 体验更现代
- 短期续命:用 vault 归档源凑合
7. 同系列文章
- AlmaLinux 9:[[posts/almalinux9-yum-repo/index.md]]
- Rocky Linux 9:[[posts/rockylinux9-yum-repo/index.md]]
- CentOS Stream 8:[[posts/centosstream8-yum-repo/index.md]]
- RHEL 7/8:[[posts/rhel7-yum-repo/index.md]]
- Debian 12:[[posts/debian12-apt-repo/index.md]]
- 离线场景制作本地仓库:[[posts/centos-local-yum-repo/index.md]]
CentOS7 YUM源配置
https://blog.xeu.asia/posts/centos7-yum-repo/