0

0

Redhad 7改用CentOS7 yum源【亲测】

蓮花仙者

蓮花仙者

发布时间:2025-07-11 09:40:22

|

318人浏览过

|

来源于php中文网

原创

1、遇到问题

在RedHat系统中,默认的yum源需要注册到RedHat Subscription Management才能更新。为了避免花费,我们需要替换为国内的yum源。

2、解决办法

由于CentOS和RedHat系统非常相似,替换为CentOS的yum源是可行的,但过程中可能遇到一些挑战。以下是解决方案的详细步骤,参考了博文:https://www.php.cn/link/95d8f6ff68222377d570a652eb96f082

(1)删除RedHat自带的yum包

[root@node1 ~]# rpm -qa|grep yum|xargs rpm -e --nodeps
warning: /etc/yum/pluginconf.d/langpacks.conf saved as /etc/yum/pluginconf.d/langpacks.conf.rpmsave
[root@node1 ~]# rpm -qa |grep yum
[root@node1 ~]# 
[root@node1 ~]# rpm -qa|grep python-urlgrabber|xargs rpm -e --nodeps

(2)下载yum软件包

Redhad 7改用CentOS7 yum源【亲测】

从阿里镜像中查找所需的yum包:

光子AI
光子AI

AI电商服饰商拍平台

下载
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm 
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-42.el7.noarch.rpm 
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-42.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-langpacks-0.4.2-7.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-rhn-plugin-2.0.1-9.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-4.11.3-25.el7.x86_64.rpm

(3)安装依赖

[root@node1 ~]# rpm -ivh python-urlgrabber-3.10-8.el7.noarch.rpm
warning: python-urlgrabber-3.10-8.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:python-urlgrabber-3.10-8.el7     ################################# [100%]
[root@node1 ~]#
[root@node1 ~]# rpm -Uvh rpm-4.11.3-25.el7.x86_64.rpm --nodeps
warning: rpm-4.11.3-25.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:rpm-4.11.3-25.el7                ################################# [ 50%]
Cleaning up / removing...
   2:rpm-4.11.3-21.el7                ################################# [100%]
[root@node1 ~]#

(4)安装yum包

[root@node1 ~]# rpm -ivh yum-*
warning: yum-3.4.3-154.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 17%]
   2:yum-plugin-fastestmirror-1.1.31-4################################# [ 33%]
   3:yum-3.4.3-154.el7.centos         ################################# [ 50%]
   4:yum-langpacks-0.4.2-7.el7        ################################# [ 67%]
   5:yum-rhn-plugin-2.0.1-9.el7       ################################# [ 83%]
   6:yum-utils-1.1.31-42.el7          ################################# [100%]
[root@node1 ~]#

3、更新源

完成上述步骤后,可以使用CentOS的yum源进行更新。

[root@node1 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

更新缓存时可能遇到错误:

[root@node1 ~]# yum makecache
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-              : manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
http://mirrors.aliyun.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article https://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/
http://mirrors.aliyuncs.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; No route to host"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; No route to host"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; No route to host"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; No route to host"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; No route to host"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; No route to host"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; No route to host"
Trying other mirror.

尝试将CentOS-Base.repo内容更改为163的源:

#CentOS-Base.repo
<h2>The mirror system uses the connecting IP address of the client and the</h2><h2>update status of each mirror to pick mirrors that are updated to and</h2><h2>geographically close to the client.  You should use this for CentOS updates</h2><h2>unless you are manually picking other mirrors.</h2><h2>If the mirrorlist= does not work for you, as a fall back you can try the</h2><h2>remarked out baseurl= line instead.</h2><h2></h2><p>[base]
name=CentOS-$7 - Base - 163.com</p><h1>mirrorlist=<a href="https://www.php.cn/link/588fad4e41a1544c03e7d5625c37cbf0">https://www.php.cn/link/588fad4e41a1544c03e7d5625c37cbf0</a></h1><p>baseurl=<a href="https://www.php.cn/link/8f5f383cc40b32666bf48521713980f4">https://www.php.cn/link/8f5f383cc40b32666bf48521713980f4</a>
gpgcheck=1
gpgkey=<a href="https://www.php.cn/link/aa799ad70bea3029d4141c7b773c1a46">https://www.php.cn/link/aa799ad70bea3029d4141c7b773c1a46</a></p><h1>released updates</h1><p>[updates]
name=CentOS-$7 - Updates - 163.com</p><h1>mirrorlist=<a href="https://www.php.cn/link/1a795f72604e4e1d35075019929d5b95">https://www.php.cn/link/1a795f72604e4e1d35075019929d5b95</a></h1><p>baseurl=<a href="https://www.php.cn/link/e8d2fc41fb98705874a309ed648806a0">https://www.php.cn/link/e8d2fc41fb98705874a309ed648806a0</a>
gpgcheck=1
gpgkey=<a href="https://www.php.cn/link/aa799ad70bea3029d4141c7b773c1a46">https://www.php.cn/link/aa799ad70bea3029d4141c7b773c1a46</a></p><h1>additional packages that may be useful</h1><p>[extras]
name=CentOS-$7 - Extras - 163.com</p><h1>mirrorlist=<a href="https://www.php.cn/link/edb636f69bf78b885117a47ec1a455d4">https://www.php.cn/link/edb636f69bf78b885117a47ec1a455d4</a></h1><p>baseurl=<a href="https://www.php.cn/link/bf6423635e56a99e9df17852c6bfadca">https://www.php.cn/link/bf6423635e56a99e9df17852c6bfadca</a>
gpgcheck=1
gpgkey=<a href="https://www.php.cn/link/aa799ad70bea3029d4141c7b773c1a46">https://www.php.cn/link/aa799ad70bea3029d4141c7b773c1a46</a></p><h1>additional packages that extend functionality of existing packages</h1><p>[centosplus]
name=CentOS-$7 - Plus - 163.com
baseurl=<a href="https://www.php.cn/link/ea14b04d59d604daf500d9a35bdd01be">https://www.php.cn/link/ea14b04d59d604daf500d9a35bdd01be</a>
gpgcheck=1
enabled=0
gpgkey=<a href="https://www.php.cn/link/aa799ad70bea3029d4141c7b773c1a46">https://www.php.cn/link/aa799ad70bea3029d4141c7b773c1a46</a>
[root@node1 yum.repos.d]# vi CentOS-Base.repo
[root@node1 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
base                                                                                                                      | 3.6 kB  00:00:00<br />
extras                                                                                                                    | 3.4 kB  00:00:00<br />
updates                                                                                                                   | 3.4 kB  00:00:00<br />
(1/12): base/x86_64/group_gz                                                                                              | 156 kB  00:00:05<br />
(2/12): base/x86_64/filelists_db                                                                                          | 6.7 MB  00:00:06<br />
(3/12): base/x86_64/other_db                                                                                              | 2.5 MB  00:00:00<br />
(4/12): base/x86_64/primary_db                                                                                            | 5.7 MB  00:00:03<br />
(5/12): extras/x86_64/prestodelta                                                                                         | 129 kB  00:00:05<br />
(6/12): extras/x86_64/primary_db                                                                                          | 185 kB  00:00:00<br />
(7/12): extras/x86_64/other_db                                                                                            | 121 kB  00:00:00<br />
(8/12): extras/x86_64/filelists_db                                                                                        | 709 kB  00:00:10<br />
(9/12): updates/x86_64/filelists_db                                                                                       | 4.2 MB  00:00:06<br />
(10/12): updates/x86_64/prestodelta                                                                                       | 960 kB  00:00:06<br />
(11/12): updates/x86_64/primary_db                                                                                        | 6.9 MB  00:00:01<br />
(12/12): updates/x86_64/other_db                                                                                          | 734 kB  00:00:01<br />
Determining fastest mirrors
Metadata Cache Created
[root@node1 yum.repos.d]# 

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
http与https有哪些区别
http与https有哪些区别

http与https的区别:1、协议安全性;2、连接方式;3、证书管理;4、连接状态;5、端口号;6、资源消耗;7、兼容性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

2860

2024.08.16

centos
centos

PHP中文网为大家提供centos相关信息,CentOS(Community Enterprise Operating System,中文意思是社区企业操作系统)是Linux发行版之一,是免费的、开源的、可以重新分发的开源操作系统,PHP中文网提供centos相关文章,以及安装教程。

449

2023.06.16

常见的linux系统有哪些
常见的linux系统有哪些

linux系统有Ubuntu、Fedora、CentOS、Debian、openSUSE、Arch Linux、Gentoo、Slackware、Linux Mint、Kali Linux。更多关于linux系统的文章详情请阅读本专题下面的文章。php中文网欢迎大家前来学习。

852

2023.10.27

JavaScript浏览器渲染机制与前端性能优化实践
JavaScript浏览器渲染机制与前端性能优化实践

本专题围绕 JavaScript 在浏览器中的执行与渲染机制展开,系统讲解 DOM 构建、CSSOM 解析、重排与重绘原理,以及关键渲染路径优化方法。内容涵盖事件循环机制、异步任务调度、资源加载优化、代码拆分与懒加载等性能优化策略。通过真实前端项目案例,帮助开发者理解浏览器底层工作原理,并掌握提升网页加载速度与交互体验的实用技巧。

23

2026.03.06

Rust内存安全机制与所有权模型深度实践
Rust内存安全机制与所有权模型深度实践

本专题围绕 Rust 语言核心特性展开,深入讲解所有权机制、借用规则、生命周期管理以及智能指针等关键概念。通过系统级开发案例,分析内存安全保障原理与零成本抽象优势,并结合并发场景讲解 Send 与 Sync 特性实现机制。帮助开发者真正理解 Rust 的设计哲学,掌握在高性能与安全性并重场景中的工程实践能力。

68

2026.03.05

PHP高性能API设计与Laravel服务架构实践
PHP高性能API设计与Laravel服务架构实践

本专题围绕 PHP 在现代 Web 后端开发中的高性能实践展开,重点讲解基于 Laravel 框架构建可扩展 API 服务的核心方法。内容涵盖路由与中间件机制、服务容器与依赖注入、接口版本管理、缓存策略设计以及队列异步处理方案。同时结合高并发场景,深入分析性能瓶颈定位与优化思路,帮助开发者构建稳定、高效、易维护的 PHP 后端服务体系。

162

2026.03.04

AI安装教程大全
AI安装教程大全

2026最全AI工具安装教程专题:包含各版本AI绘图、AI视频、智能办公软件的本地化部署手册。全篇零基础友好,附带最新模型下载地址、一键安装脚本及常见报错修复方案。每日更新,收藏这一篇就够了,让AI安装不再报错!

84

2026.03.04

Swift iOS架构设计与MVVM模式实战
Swift iOS架构设计与MVVM模式实战

本专题聚焦 Swift 在 iOS 应用架构设计中的实践,系统讲解 MVVM 模式的核心思想、数据绑定机制、模块拆分策略以及组件化开发方法。内容涵盖网络层封装、状态管理、依赖注入与性能优化技巧。通过完整项目案例,帮助开发者构建结构清晰、可维护性强的 iOS 应用架构体系。

113

2026.03.03

C++高性能网络编程与Reactor模型实践
C++高性能网络编程与Reactor模型实践

本专题围绕 C++ 在高性能网络服务开发中的应用展开,深入讲解 Socket 编程、多路复用机制、Reactor 模型设计原理以及线程池协作策略。内容涵盖 epoll 实现机制、内存管理优化、连接管理策略与高并发场景下的性能调优方法。通过构建高并发网络服务器实战案例,帮助开发者掌握 C++ 在底层系统与网络通信领域的核心技术。

29

2026.03.03

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
最新Python教程 从入门到精通
最新Python教程 从入门到精通

共4课时 | 22.5万人学习

Django 教程
Django 教程

共28课时 | 4.8万人学习

SciPy 教程
SciPy 教程

共10课时 | 1.8万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号