通常来说,默认的yum镜像地址是你在安装系统时,你所配置的国家和地区的附近。因为我装系统的时候,是一路按默认设置来装的,所以yum镜像地址在美国。
[user@hadoop02 yum.repos.d]$ pwd
/etc/yum.repos.d
[user@hadoop02 yum.repos.d]$ ls
CentOS-AppStream.repo CentOS-centosplus.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo
CentOS-Base.repo CentOS-CR.repo CentOS-Extras.repo CentOS-HA.repo CentOS-PowerTools.repo CentOS-Vault.repo
[user@hadoop02 yum.repos.d]$ cat CentOS-Base.repo
# 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.
#
#
[BaseOS]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[user@hadoop02 yum.repos.d]$
重点在mirrorlist那一行
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
http://mirrorlist.centos.org,它是centos在美国的官方镜像地址。
现在我要把它改成国内的镜像地址,通常有有两个选择:
1、网易
2、阿里云
我选择了阿里云。
需要注意的是,所谓的修改yum镜像地址,其实不需要真的修改/etc/yum.repos.d/CentOS-Base.repo配置文件,只需要去网易和阿里云下载与你系统版本对应的配置文件即可,强调一下,所下载的配置文件必须与你的系统版本相对应,否则无法使用,这也正是我选择阿里云的原因,因为网易暂时还没有Centos-8的配置文件。
以下是我的具体操作:
1、进入目录
[user@hadoop02 yum.repos.d]$ ls
CentOS-AppStream.repo CentOS-centosplus.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo
CentOS-Base.repo CentOS-CR.repo CentOS-Extras.repo CentOS-HA.repo CentOS-PowerTools.repo CentOS-Vault.repo
2、备份CentOS-Base.repo文件
user@hadoop02 yum.repos.d]$ sudo cp CentOS-Base.repo CentOS-Base.repo.bakup
[sudo] password for user:
[user@hadoop02 yum.repos.d]$ ls
CentOS-AppStream.repo CentOS-Base.repo.bakup CentOS-CR.repo CentOS-Extras.repo CentOS-HA.repo CentOS-PowerTools.repo CentOS-Vault.repo
CentOS-Base.repo CentOS-centosplus.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo
3、下载配置文件
[user@hadoop02 yum.repos.d]$ pwd
/etc/yum.repos.d
[user@hadoop02 yum.repos.d]$ sudo wget http://mirrors.aliyun.com/repo/Centos-8.repo
--2020-03-12 08:08:22-- http://mirrors.aliyun.com/repo/Centos-8.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 116.31.73.83, 113.105.168.161, 119.147.111.227, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|116.31.73.83|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2595 (2.5K) [application/octet-stream]
Saving to: ‘Centos-8.repo’
Centos-8.repo 100%[===========================================================================================================================>] 2.53K --.-KB/s in 0s
2020-03-12 08:08:27 (359 MB/s) - ‘Centos-8.repo’ saved [2595/2595]
[user@hadoop02 yum.repos.d]$ ls
Centos-8.repo CentOS-Base.repo CentOS-centosplus.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo
CentOS-AppStream.repo CentOS-Base.repo.bakup CentOS-CR.repo CentOS-Extras.repo CentOS-HA.repo CentOS-PowerTools.repo CentOS-Vault.repo
可以看到,/etc/yum.repos.d/目录下多了一个Centos-8.repo文件,这个就是从阿里云下载下来的配置文件。
发现了一个错误:前面备份Centos-Base.repo文件时应该用mv命令,而不是cp,所以这里还需要把文件/etc/yum.repos.d/CentOS-Base.repo删除掉。
[user@hadoop02 yum.repos.d]$ sudo rm CentOS-Base.repo.bakup
[user@hadoop02 yum.repos.d]$ ls
Centos-8.repo CentOS-Base.repo.backup CentOS-CR.repo CentOS-Extras.repo CentOS-HA.repo CentOS-PowerTools.repo CentOS-Vault.repo
CentOS-AppStream.repo CentOS-centosplus.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo
4、清理yum缓存,让新的配置文件生效
[user@hadoop02 yum.repos.d]$ yum clean all
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
0 files removed
[user@hadoop02 yum.repos.d]$ yum makecache
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
CentOS-8 - AppStream 661 kB/s | 6.5 MB 00:10
CentOS-8 - Extras 368 B/s | 2.1 kB 00:05
CentOS-8 - Base - mirrors.aliyun.com 265 kB/s | 5.0 MB 00:19
Metadata cache created.
到这,yum镜像地址就改好了。
网友评论