1.阿里云、清华大学、华为云、网易、腾讯云、中科大 镜像源整合在一起
注:这些镜像源的配置优先级可以自己调整,看看自己适合那个,修改顺序就可以了.
红色加粗黑色背景的文字 可以使用下面的调换顺序,当然也可以添加镜像源.
应该能够解决很多问题
1.执行下面的指令备份原来的配置文件
cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
2.修改配置文件
vi /etc/yum.repos.d/CentOS-Base.repo
3.修改配置文件中base中的内容
# 配置国内的镜像源
name=CentOS-7 - Base - All Mirrors
# 按优先级排序(数字越小优先级越高)
baseurl=https://mirrors.aliyun.com/centos/7/os/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/$basearch/
https://mirrors.163.com/centos/7/os/$basearch/
https://mirrors.huaweicloud.com/centos/7/os/$basearch/
https://mirrors.cloud.tencent.com/centos/7/os/$basearch/
https://mirrors.ustc.edu.cn/centos/7/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
priority=1
enabled=1
4.修改update中的文件
# 配置国内镜像原update
name=CentOS-7 - Updates - All Mirrors
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/$basearch/
https://mirrors.aliyun.com/centos/7/updates/$basearch/
https://mirrors.163.com/centos/7/updates/$basearch/
https://mirrors.huaweicloud.com/centos/7/updates/$basearch/
https://mirrors.cloud.tencent.com/centos/7/updates/$basearch/
https://mirrors.ustc.edu.cn/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
priority=2
enabled=1
5.修改extras 文件中的内容
# 配置国内的镜像源
name=CentOS-7 - Extras - All Mirrors
baseurl=https://mirrors.163.com/centos/7/extras/$basearch/
https://mirrors.huaweicloud.com/centos/7/extras/$basearch/
https://mirrors.aliyun.com/centos/7/extras/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/$basearch/
https://mirrors.cloud.tencent.com/centos/7/extras/$basearch/
https://mirrors.ustc.edu.cn/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
priority=3
enabled=1
6.配置文件末尾添加 [epel]
[epel]
name=EPEL 7 - All Mirrors
baseurl=https://mirrors.aliyun.com/epel/7/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/
https://mirrors.163.com/epel/7/$basearch/
https://mirrors.huaweicloud.com/epel/7/$basearch/
https://mirrors.cloud.tencent.com/epel/7/$basearch/
https://mirrors.ustc.edu.cn/epel/7/$basearch/
gpgcheck=0
enabled=1
priority=1
输入:wq 保存
6.安装优先级插件
yum install -y yum-plugin-priorities
安装信息
[root@localhost mysql]# yum install -y yum-plugin-priorities
已加载插件:fastestmirror, langpacks
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的名称或服务"
base | 3.6 kB 00:00
epel | 4.3 kB 00:00
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的名称或服务"
https://mirrors.163.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.163.com:443; 拒绝连接"
正在尝试其它镜像。
extras | 2.9 kB 00:00
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的名称或服务"
https://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
正在尝试其它镜像。
To address this issue please refer to the below knowledge base articlehttps://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/
updates | 2.9 kB 00:00
(1/7): base/7/x86_64/group_gz | 153 kB 00:00
(2/7): epel/x86_64/group | 399 kB 00:00
(3/7): extras/7/x86_64/primary_db | 253 kB 00:00
(4/7): base/7/x86_64/primary_db | 6.1 MB 00:01
(5/7): updates/7/x86_64/primary_db | 27 MB 00:01
(6/7): epel/x86_64/updateinfo | 1.0 MB 00:04
(7/7): epel/x86_64/primary_db | 8.7 MB 00:08
Determining fastest mirrors
* base: mirrors.ustc.edu.cn
* epel: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 yum-plugin-priorities.noarch.0.1.1.31-54.el7_8 将被 安装
--> 解决依赖关系完成依赖关系解决
============================================================================
Package 架构 版本 源 大小
============================================================================
正在安装:
yum-plugin-priorities noarch 1.1.31-54.el7_8 base 29 k事务概要
============================================================================
安装 1 软件包总下载量:29 k
安装大小:28 k
Downloading packages:
警告:/var/cache/yum/x86_64/7/base/packages/yum-plugin-priorities-1.1.31-54.el7_8.noarch.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
yum-plugin-priorities-1.1.31-54.el7_8.noarch.rpm 的公钥尚未安装
yum-plugin-priorities-1.1.31-54.el7_8.noarch.rpm | 29 kB 00:00
从 https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 检索密钥
导入 GPG key 0xF4A80EB5:
用户ID : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
指纹 : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
来自 : https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
从 https://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7 检索密钥
从 https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 检索密钥
获取 GPG 密钥失败:[Errno 14] curl#7 - "Failed connect to mirrors.163.com:443; 拒绝连接"
[root@localhost mysql]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base epel extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
7.清理缓存
yum clean all
[root@localhost mysql]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base epel extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
rm -rf /var/cache/yum
yum makecache fast
完整处理信息
[root@localhost mysql]# rm -rf /var/cache/yum
[root@localhost mysql]# yum makecache fast
已加载插件:fastestmirror, langpacks
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的名称或服务"
base | 3.6 kB 00:00
epel | 4.3 kB 00:00
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的名称或服务"
https://mirrors.163.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.163.com:443; 拒绝连接"
正在尝试其它镜像。
extras | 2.9 kB 00:00
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的名称或服务"
https://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found
正在尝试其它镜像。
To address this issue please refer to the below knowledge base articlehttps://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/
updates | 2.9 kB 00:00
(1/7): base/7/x86_64/group_gz | 153 kB 00:00
(2/7): epel/x86_64/updateinfo | 1.0 MB 00:00
(3/7): epel/x86_64/group | 399 kB 00:00
(4/7): base/7/x86_64/primary_db | 6.1 MB 00:00
(5/7): extras/7/x86_64/primary_db | 253 kB 00:00
(6/7): updates/7/x86_64/primary_db | 27 MB 00:00
(7/7): epel/x86_64/primary_db | 8.7 MB 00:08
Determining fastest mirrors
* base: mirrors.cloud.tencent.com
* epel: mirrors.cloud.tencent.com
* extras: mirrors.cloud.tencent.com
* updates: mirrors.cloud.tencent.com
元数据缓存已建立
8.测试一下镜像源
这里只测试阿里云的镜像源,也可测试其他的。替换下面绿色背景 的文字就可了,这里就不在演示了.
time curl -I https://mirrors.aliyun.com/centos/7/os/x86_64/repodata/repomd.xml
完整的测试信息
[root@localhost mysql]# time curl -I https://mirrors.aliyun.com/centos/7/os/x86_64/repodata/repomd.xml
HTTP/1.1 200 OK
Server: Tengine
Content-Type: text/xml; charset=utf-8
Content-Length: 3736
Connection: keep-alive
Date: Sun, 18 May 2025 13:12:06 GMT
Expires: Sun, 18 May 2025 13:13:06 GMT
Cache-Control: max-age=60
Via: osm2.et15[0.001,304], cache32.l2cn3160[0,0,304-0,H], cache39.l2cn3160[1,0], cache7.cn7551[0,0,200-0,H], cache19.cn7551[2,0]
Accept-Ranges: bytes
Last-Modified: Thu, 29 Oct 2020 20:03:00 GMT
Vary: Accept-Encoding
ETag: "5f9b1ff4-e98"
Age: 12
Ali-Swift-Global-Savetime: 1747573926
X-Cache: HIT TCP_MEM_HIT dirn:-2:-2
X-Swift-SaveTime: Sun, 18 May 2025 13:12:08 GMT
X-Swift-CacheTime: 58
Timing-Allow-Origin: *
EagleId: 74c4861817475739387855570e
real 0m0.162s
user 0m0.009s
sys 0m0.033s
9.完整的centos 镜像源配置文件
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7# 配置国内的镜像源
name=CentOS-7 - Base - All Mirrors
# 按优先级排序(数字越小优先级越高)
baseurl=https://mirrors.aliyun.com/centos/7/os/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/$basearch/
https://mirrors.163.com/centos/7/os/$basearch/
https://mirrors.huaweicloud.com/centos/7/os/$basearch/
https://mirrors.cloud.tencent.com/centos/7/os/$basearch/
https://mirrors.ustc.edu.cn/centos/7/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
priority=1
enabled=1
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7# 配置国内镜像原update
name=CentOS-7 - Updates - All Mirrors
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/$basearch/
https://mirrors.aliyun.com/centos/7/updates/$basearch/
https://mirrors.163.com/centos/7/updates/$basearch/
https://mirrors.huaweicloud.com/centos/7/updates/$basearch/
https://mirrors.cloud.tencent.com/centos/7/updates/$basearch/
https://mirrors.ustc.edu.cn/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
priority=2
enabled=1
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
# 配置国内的镜像源
name=CentOS-7 - Extras - All Mirrors
baseurl=https://mirrors.163.com/centos/7/extras/$basearch/
https://mirrors.huaweicloud.com/centos/7/extras/$basearch/
https://mirrors.aliyun.com/centos/7/extras/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/$basearch/
https://mirrors.cloud.tencent.com/centos/7/extras/$basearch/
https://mirrors.ustc.edu.cn/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=https://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.tuna.tsinghua.edu.cn/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
https://mirrors.ustc.edu.cn/centos/RPM-GPG-KEY-CentOS-7
priority=3
enabled=1
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7[epel]
name=EPEL 7 - All Mirrors
baseurl=https://mirrors.aliyun.com/epel/7/$basearch/
https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/
https://mirrors.163.com/epel/7/$basearch/
https://mirrors.huaweicloud.com/epel/7/$basearch/
https://mirrors.cloud.tencent.com/epel/7/$basearch/
https://mirrors.ustc.edu.cn/epel/7/$basearch/
gpgcheck=0
enabled=1
priority=1