一、准备工作
保证本地包含wget
工具,执行如下指令表示已经安装 wget
工具。
$ wget --version
GNU Wget 1.14 在 linux-gnu 上编译。
+digest +https +ipv6 +iri +large-file +nls +ntlm +opie +ssl/openssl
Wgetrc:
/etc/wgetrc (系统)
没有则通过 yum
安装。
yum -y install wget
二、备份历史配置
找到本地 yum
源仓库配置,/etc/yum.repos.d
。
ll /etc/yum.repos.d
-rw-r--r--. 1 root root 2523 12月 26 19:31 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 11月 23 23:08 CentOS-CR.repo
-rw-r--r--. 1 root root 649 11月 23 23:08 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 11月 23 23:08 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 11月 23 23:08 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 11月 23 23:08 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 11月 23 23:08 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 11月 23 23:08 CentOS-x86_64-kernel.repo
保留原始配置CentOS-Base.repo
。
mv CentOS-Base.repo CentOS-Base.repo.bak
三、配置国内源
下载阿里云镜像源配置,需要注意的是,目前,阿里云镜像中,只能够支持https
。
$ wget -O CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
--2021-04-07 11:00:18-- http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 111.160.44.224, 111.160.44.229, 111.160.44.230, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|111.160.44.224|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “CentOS-Base.repo”
四、清空缓存
配置文件后,需要先清空本地的 yum
缓存。
$ yum clean all
重新添加缓存。
$ yum makecache
已加载插件:fastestmirror
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 | ...........
元数据缓存已建立
表示配置成功。