CentOS7/8在线yum源自动设置

1. 前提说明

CentOS7/8版本官方已经归档,默认的安装源无法使用,而且网上大多数提供的国内yum地址也大部分失效。故为了快速有效的使用在线yum,结合国内清华源,来生成有效的repo文件,帮助实施人员解决手动配置慢等问题。

2. 使用方法

核心命令:

csharp 复制代码
[root@localhost soft]# wget  https://raw.githubusercontent.com/FlowerBirds/centosv7v8-china-repo/refs/heads/main/install-repo.py
[root@localhost soft]# python install-repo.py

默认使用Linux自带的Python2环境执行脚本,会自动检测当前系统版本,并生成repo文件。例如:

bash 复制代码
[root@localhost soft]# wget https://raw.githubusercontent.com/FlowerBirds/centosv7v8-china-repo/refs/heads/main/install-repo.py
--2025-12-10 16:46:52-- https://www.falvce.com/ https://raw.githubusercontent.com/FlowerBirds/centosv7v8-china-repo/refs/heads/main/install-repo.py
正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.109.133, 185.199.110.133, 185.199.111.133, ...
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|185.199.109.133|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:9144 (8.9K) [text/plain]
正在保存至: "install-repo.py"

100%[========================================================================================================================================================>] 9,144       --.-K/s 用时 0.003s

2025-12-10 16:46:52 (2.69 MB/s) - 已保存 "install-repo.py" [9144/9144])

[root@localhost soft]# python install-repo.py
⚠️  警告:当前为Python2环境,建议使用Python3运行(Python2已停止维护)

===== 开始备份YUM源配置 =====
已备份:/etc/yum.repos.d/CentOS-Base.repo -> /etc/yum.repos.d/repo_bak_20251210_160331/CentOS-Base.repo
已备份:/etc/yum.repos.d/test.repo -> /etc/yum.repos.d/repo_bak_20251210_160331/test.repo
所有.repo文件已备份至:/etc/yum.repos.d/repo_bak_20251210_160331

===== 开始识别系统版本 =====
已识别系统版本:CentOS 7.9.2009

===== 开始生成清华Vault源 =====
✅ 成功生成CentOS 7.9.2009的清华源配置:/etc/yum.repos.d/CentOS-Base.repo

===== 操作完成 =====
📁 原有配置备份目录:https://www.falvce.com/ /etc/yum.repos.d/repo_bak_20251210_160331
🔧 建议执行以下命令刷新缓存:
   yum clean all && yum makecache
   yum repolist enabled
[root@localhost soft]#
[root@localhost soft]# yum clean all && yum makecache
已加载插件:fastestmirror, langpacks
正在清理软件源: base extras updates
Cleaning up list of fastest mirrors
Other repos take up 169 M of disk space (use --verbose for details)
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
base                                                                                                                                                                       | 3.6 kB  00:00:00
extras                                                                                                                                                                     | 2.9 kB  00:00:00
updates                                                                                                                                                                    | 2.9 kB  00:00:00
(1/10): base/x86_64/group_gz                                                                                                                                               | 153 kB  00:00:00
(2/10): base/x86_64/primary_db                                                                                                                                             | 6.1 MB  00:00:02
(3/10): extras/x86_64/primary_db                                                                                                                                           | 253 kB  00:00:00
(4/10): base/x86_64/other_db                                                                                                                                               | 2.6 MB  00:00:01
(5/10): extras/x86_64/filelists_db                                                                                                                                         | 305 kB  00:00:01
(6/10): extras/x86_64/other_db                                                                                                                                             | 154 kB  00:00:00
(7/10): base/x86_64/filelists_db                                                                                                                                           | 7.2 MB  00:00:04
(8/10): updates/x86_64/primary_db                                                                                                                                          |  27 MB  00:00:09
(9/10): updates/x86_64/filelists_db                                                                                                                                        |  15 MB  00:00:10
(10/10): updates/x86_64/other_db                                                                                                                                           | 1.6 MB  00:00:00
元数据缓存已建立
[root@localhost soft]#  yum repolist enabled
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识                                                                          源名称                                                                                                      状态
base/x86_64                                                                     CentOS-7.9.2009 - Base - Tsinghua Vault                                                                     10,072
extras/x86_64                                                                   CentOS-7.9.2009 - Extras - Tsinghua Vault                                                                      526
updates/x86_64                                                                  CentOS-7.9.2009 - Updates - Tsinghua Vault                                                                   6,173
repolist: 16,771

执行成功后,提示执行命令即可。脚本会将之前的repo文件进行备份,不影响后续还原。

脚本仓库地址:github.com/FlowerBirds...

相关推荐
陈年老古董16 小时前
CentOS编译安装Python3.11完整教程
linux·笔记·学习·centos·python3.11
笨笨饿16 小时前
#111_关于FreeRTOS面试的一些题目
linux·ubuntu·面试·职场和发展·centos·rtos
一路向北finish4 天前
《CentOS 7 搭建 Hadoop 3.3.6 分布式集群:NFS 共享方案完整实操》
linux·运维·hadoop·分布式·centos
量子炒饭大师9 天前
MySQL 5.7 在 CentOS 7 环境安装:从清理 MariaDB 到初始化与完善配置
数据库·mysql·centos·mariadb
a未来永远是个未知数10 天前
centos离线安装ntpcent
linux·运维·centos
☆凡尘清心☆11 天前
CentOS Stream 9 源码编译搭建 Zabbix7.0.29 完整部署方案(部署成功)
linux·运维·centos
wsad053211 天前
CentOS 10 上使用 Docker Compose 部署 Discuz X5.0 论坛完整教程
linux·docker·centos·discuz
檀越剑指大厂14 天前
CentOS部署Landlord斗地主项目:源码编译并实现远程访问
linux·运维·centos
测试运维日常笔记15 天前
RHEL/CentOS 离线部署指南:配置本地 ISO 镜像作为 YUM 仓库
linux·运维·centos
梓沂15 天前
CentOS 7.9 静默安装 Oracle 11gR2 企业版全记录
linux·oracle·centos