Centos7国内常用源

11 篇文章 0 订阅
6 篇文章 0 订阅

这里我整理一下国内较知名的镜像站点,供大家在生产测试环境中使用。
你可能还需要看:Debian10常用国内源

一、基础知识

红帽系的源一般都是由

/etc/yum.repos.d/

目录下的repo文件进行配置,默认文件结构为:


[root@localhost yum.repos.d]# ll
总用量 32
-rw-r--r--. 1 root root 1664 9月   5 2019 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 9月   5 2019 CentOS-CR.repo
-rw-r--r--. 1 root root  649 9月   5 2019 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 9月   5 2019 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 9月   5 2019 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 9月   5 2019 CentOS-Sources.repo
-rw-r--r--. 1 root root 6639 9月   5 2019 CentOS-Vault.repo
[root@localhost yum.repos.d]#

然后查看一下CentOS-Base.repo文件的内容

[root@localhost 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.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


可以看到,此时的镜像地址是

http://mirrorlist.centos.org

此类源一般来说都是比较慢的,下面开始说明如何快速的修改源

二、如何修改

2.1、备份

在Linux中,配置任何文件之前都建议先进行备份,下面是备份命令

mkdir -p /yum_bak&&mv /etc/yum.repos.d/* /yum_bak/

2.2、添加

备份完成之后,开始添加/编辑源文件,添加源文件主要有三种方法

  • 直接编辑内容
  • 下载rpeo源文件
  • yum安装相关源

首先讲解第一个

2.2.1、直接编辑

使用下面的命令写入配置内容

cat <<EOF > /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/os/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-\$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/\$releasever/updates/\$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

EOF

执行效果如下:
在这里插入图片描述
在这里插入图片描述

2.2.2、下载源文件

这个就比较省事了,下载下来就能用,命令如下:

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

在这里插入图片描述
由于阿里云的源默认接入内网域名,所以如果不是阿里云服务器的话,需要执行下面的语句进行相关修改

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

2.2.3、这个就不讲了

三、快速替换源站

在使用前面的方式下载好了源配置文件之后,我们就可以针对这些模板进行快速的替换了,下面先附上一个模板,然后附上各大国内源站

3.1、源模板

直接执行下面的指令即可

echo '[base]
name=CentOS-$releasever - Base
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras 
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7' > /etc/yum.repos.d/CentOS-Base.repo

3.2、国内常用源站列表

**

PS:下面的指令仅限执行了3.1的指令之后的模板有效,如果需要切换不同的源,请重新执行3.1步骤的指令下执行替换

**

网易源

http://tel.mirrors.163.com

sed -i 's#http://mirrors.aliyun.com/#http://tel.mirrors.163.com/#g' /etc/yum.repos.d/CentOS-Base.repo

腾讯源

https://mirrors.cloud.tencent.com/

sed -i 's#http://mirrors.aliyun.com/#https://mirrors.cloud.tencent.com/#g' /etc/yum.repos.d/CentOS-Base.repo

清华大学

https://mirrors.tuna.tsinghua.edu.cn/

sed -i 's#http://mirrors.aliyun.com/#https://mirrors.tuna.tsinghua.edu.cn/#g' /etc/yum.repos.d/CentOS-Base.repo

中国科技技术大学

https://mirrors.ustc.edu.cn/

sed -i 's#http://mirrors.aliyun.com/#https://mirrors.ustc.edu.cn/#g' /etc/yum.repos.d/CentOS-Base.repo

华为镜像站

https://mirrors.huaweicloud.com/

sed -i 's#http://mirrors.aliyun.com/#https://mirrors.huaweicloud.com/#g' /etc/yum.repos.d/CentOS-Base.repo
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

坐公交也用券

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值