Centos 修改镜像地址

通常在国内使用 Linux 都需要修改镜像地址 ,因为默认的 http://mirrorlist.centos.org 被禁了,根本访问不了,也就无法下载各种包了,所以需要修改。

1. 国内常用的 CentOS 镜像站点地址

阿里云:centos安装包下载_开源镜像站-阿里云   http://mirrors.aliyun.com/centos/

网易:Index of /centos/   http://mirrors.163.com/centos/

清华大学:Index of /centos/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror  https://mirrors.tuna.tsinghua.edu.cn/centos/

2. 修改 Centos 镜像地址

文件位于 /etc/yum.repos.d/CentOS-Base.repo

修改前:里面的 http://mirrorlist.centos.org 域名国内完全不能访问,所以需要修改。

修改后:原来URL注释,改成阿里云的。

注意:原本URL里面是有 $releasever、$basearch 两个变量的,可以改成和自己的系统一直的版本号,如: 7.9.2009 和 x86_64 了,

我们可以通过下面地址 http://mirrors.aliyun.com/centos/ 来确认URL。

使用说明页:https://developer.aliyun.com/mirror/centos

主要流程如下:

1. 备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2. 下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

3. 运行 yum makecache 生成缓存

https://mirrors.aliyun.com/repo/Centos-7.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.
#
#
 
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.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-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.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-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

验证:输入下面命令来验证。

yum repolist
yum clean all
yum makecache

如果能正常更新代表正常。

微信截图_20250226211020.png

执行 yum repolist 命令报错,提示无法通过https 访问,则是错误。


打赏

本篇文章链接 地址:https://www.wmzos.com/?id=143

相关阅读

添加新评论