必须更换为阿里云归档源,因CentOS 7官方源已于2024年6月30日彻底关闭;需手动创建CentOS-Base.repo,baseurl精确匹配系统小版本(如7.9.2009),启用gpgcheck并指定正确gpgkey,清空旧repo后执行yum clean all && yum makecache验证。

yum 源必须换,否则 Could not resolve host: mirrorlist.centos.org 会一直报错——CentOS 7 官方源已在 2024 年 6 月彻底关闭,所有默认配置都失效了。阿里云虽仍提供镜像,但不再维护实时更新的 centos-7.repo,现在只能用归档(centos-vault)地址,且必须匹配你系统的真实版本号。
确认 CentOS 7 具体小版本号
阿里云归档源要求精确到 7.x.yyyy(如 7.9.2009),不能只写 $releasever。运行以下命令查清你的系统版本:
cat /etc/centos-release
输出类似 CentOS Linux release 7.9.2009 (Core),就取 7.9.2009 这段;若显示 7.8.2003,就用那个。
- 别直接抄网上泛写的
7或$releasever,那在 vault 源下会 404 - 最小化安装可能没装
centos-release包,导致/etc/centos-release为空,此时用rpm -q centos-release查包版本
下载或手写正确的 CentOS-Base.repo
阿里云已下线 https://mirrors.aliyun.com/repo/Centos-7.repo,现在必须用 vault 地址。两种方式任选其一:
- 用
wget下载(需先确保wget已安装):wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/centos-vault/7.9.2009/os/x86_64/repodata/repomd.xml—— 不行,这不是 .repo 文件,此命令错误 - 正确做法是手动创建:
vi /etc/yum.repos.d/CentOS-Base.repo,粘贴以下内容(把7.9.2009替换成你查到的实际版本):
[base] name=CentOS-$releasever - Base - mirrors.aliyun.com baseurl=https://mirrors.aliyun.com/centos-vault/7.9.2009/os/$basearch/ gpgcheck=1 gpgkey=https://www.php.cn/link/c3e30f79a589e17ca680074aee45e3c3 enabled=1 <p>[updates] name=CentOS-$releasever - Updates - mirrors.aliyun.com baseurl=<a href="https://www.php.cn/link/eaa54bda0c143cab887c64e11803855b">https://www.php.cn/link/eaa54bda0c143cab887c64e11803855b</a> gpgcheck=1 gpgkey=<a href="https://www.php.cn/link/c3e30f79a589e17ca680074aee45e3c3">https://www.php.cn/link/c3e30f79a589e17ca680074aee45e3c3</a> enabled=1</p><p>[extras] name=CentOS-$releasever - Extras - mirrors.aliyun.com baseurl=<a href="https://www.php.cn/link/0cc57d9daaa686e94f9ab541f3026121">https://www.php.cn/link/0cc57d9daaa686e94f9ab541f3026121</a> gpgcheck=1 gpgkey=<a href="https://www.php.cn/link/c3e30f79a589e17ca680074aee45e3c3">https://www.php.cn/link/c3e30f79a589e17ca680074aee45e3c3</a> enabled=1</p>
$basearch 会自动展开为 x86_64 等,不用硬编码;gpgcheck=1 必须保留,否则 yum install 可能因签名失败中断。
CentOS Linux 7.9.2009是传统CentOS Linux 7的最后主要版本,也是很多企业历史服务器中仍可能遇到的系统版本。它以稳定、兼容RHEL 7生态、文档丰富和软件支持广泛著称,曾长期用于Web服务、数据库、虚拟化节点和企业内部业务系统。不过CentOS Linux 7已于2024年6月30日停止维护,现在继续使用会面临安全补丁缺失风险。该版本更适合旧业务迁移、历史环境恢复或离
清理缓存前先删光旧 repo 文件
别只备份 CentOS-Base.repo,yum 会加载 /etc/yum.repos.d/ 下所有 .repo 文件。如果残留 CentOS-SCLo-scl-rh.repo 这类已失效的源,yum makecache 会卡住或报 Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64。
- 执行:
rm -f /etc/yum.repos.d/*.repo(清空目录再写新文件,最稳妥) - 或者至少移走所有带
centos-sclo、centos-vault、mirrorlist字样的旧 repo 文件 -
yum clean all后必须跟yum makecache,只清不重建,yum repolist仍显示 0 个仓库
验证时重点看 repolist 和实际安装
运行 yum repolist enabled,正常输出应含三行:base、updates、extras,每行 status 列数字大于 0(比如 10036),且 repo id 不含 mirrorlist.centos.org。
- 别只信“成功”字样,要看到真实包数量
- 再试装一个基础包:
yum install -y yum-utils,若卡在Downloading packages或报Public key not found,说明gpgkey路径不对或网络不通 - 如果要用
epel,单独下载:wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm—— 错,这是 rpm 包,不是 repo 文件;正确是:wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/epel/7/x86_64/repodata/repomd.xml—— 也不对;实际应:yum install -y https://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm
归档源的包不会更新,yum update 基本无新包可装,这是预期行为,不是配置失败。










