centos换成国内镜像
为了将CentOS的镜像源更换为国内源,你需要编辑/etc/yum.repos.d/CentOS-Base.repo文件,将其中的官方镜像地址替换为国内的镜像地址。
以下是一个基本的步骤指南,以及一个示例配置,用于将CentOS的默认镜像源更换为阿里云的镜像源:
备份当前的CentOS-Base.repo文件:
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
编辑CentOS-Base.repo文件:
sudo vi /etc/yum.repos.d/CentOS-Base.repo
将文件中的所有mirrorlist和baseurl行替换为阿里云镜像源地址。例如,对于CentOS 7,你可以使用以下内容:
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-
r
e
l
e
a
s
e
v
e
r
−
B
a
s
e
−
A
l
i
y
u
n
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Base - Aliyun baseurl=http://mirrors.aliyun.com/centos/
releasever−Base−Aliyunbaseurl=http://mirrors.aliyun.com/centos/releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
U
p
d
a
t
e
s
−
A
l
i
y
u
n
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Updates - Aliyun baseurl=http://mirrors.aliyun.com/centos/
releasever−Updates−Aliyunbaseurl=http://mirrors.aliyun.com/centos/releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
E
x
t
r
a
s
−
A
l
i
y
u
n
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Extras - Aliyun baseurl=http://mirrors.aliyun.com/centos/
releasever−Extras−Aliyunbaseurl=http://mirrors.aliyun.com/centos/releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
P
l
u
s
−
A
l
i
y
u
n
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Plus - Aliyun baseurl=http://mirrors.aliyun.com/centos/
releasever−Plus−Aliyunbaseurl=http://mirrors.aliyun.com/centos/releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
对于CentOS 8,替换为:
[base]
name=CentOS-
r
e
l
e
a
s
e
v
e
r
−
B
a
s
e
−
A
l
i
y
u
n
b
a
s
e
u
r
l
=
h
t
t
p
:
/
/
m
i
r
r
o
r
s
.
a
l
i
y
u
n
.
c
o
m
/
c
e
n
t
o
s
/
releasever - Base - Aliyun baseurl=http://mirrors.aliyun.com/centos/
releasever−Base−Aliyunbaseurl=http://mirrors.aliyun.com/centos/releasever/BaseOS/
b
a
s
e
a
r
c
h
/
o
s
/
.
.
.
[
a
p
p
s
t
r
e
a
m
]
n
a
m
e
=
C
e
n
t
O
S
−
basearch/os/ ... [appstream] name=CentOS-
basearch/os/...[appstream]name=CentOS−releasever - AppStream - Aliyun
baseurl=http://mirrors.aliyun.com/centos/
r
e
l
e
a
s
e
v
e
r
/
A
p
p
S
t
r
e
a
m
/
releasever/AppStream/
releasever/AppStream/basearch/os/
…
清除缓存并生成新的缓存:
sudo yum clean all
sudo yum makecache
测试新的镜像源是否可用:
sudo yum update
请根据你的CentOS版本(7或8)选择相应的配置
本文地址:https://www.vps345.com/6663.html