1、备份自带的yum源
[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.ba
2、下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2022-11-22 05:30:47-- https://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 125.64.132.20, 125.64.132.18, 125.64. 132.62, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|125.64.132.20|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”
100%[===================================================>] 2,523 --.-K/s 用时 0.02s
2022-11-22 05:30:47 (133 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])
3、运行 yum makecache 生成缓存
[root@localhost ~]# yum makecache
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Fail ed connect to mirrors.aliyuncs.com:80; 拒绝连接"
正在尝试其它镜像。
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; 未知的错误"
正在尝试其它镜像。
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00:03
(2/10): base/7/x86_64/primary_db | 6.1 MB 00:01:48
(3/10): extras/7/x86_64/primary_db | 249 kB 00:00:04
(4/10): extras/7/x86_64/filelists_db | 276 kB 00:00:05
(5/10): extras/7/x86_64/other_db | 149 kB 00:00:02
(6/10): base/7/x86_64/filelists_db | 7.2 MB 00:02:13
(7/10): base/7/x86_64/other_db | 2.6 MB 00:00:46
(8/10): updates/7/x86_64/filelists_db | 10 MB 00:02:59
(9/10): updates/7/x86_64/other_db | 1.2 MB 00:00:21
(10/10): updates/7/x86_64/primary_db | 18 MB 00:05:23
元数据缓存已建立
4、查看更换的阿里云镜像的仓库是否生效
[root@localhost ~]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base extras updates
Cleaning up list of fastest mirrors
[root@localhost ~]# yum repolist
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): extras/7/x86_64/primary_db | 249 kB 00:00:04
(2/4): base/7/x86_64/group_gz | 153 kB 00:00:08
(3/4): base/7/x86_64/primary_db | 6.1 MB 00:01:49
(4/4): updates/7/x86_64/primary_db | 18 MB 00:05:32
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 515
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 4,385
repolist: 14,972