将CentOS的yum源更换为国内镜像源

使用yum的官方源进行yum install xxxx 的时候,速度非常慢,只有几kB/s,有时候还不到1kB/s。这就会造成安装包的速度的速度要么特变慢,要么就根本安装不了。如下图所示。

解决方案:

替换CentOS的yum 源 为 国内的镜像源。

更换 yum 源的原因:
国外网站连接响应太慢
国内 yum 源响应速度快

解决方案1:替换CentOS的yum 源 为 国内的yum源--阿里yum源。

具体步骤如下:

1.备份

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

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

CentOS6

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

CentOS7

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

如下图所示:

wget 命令 -O 参数含义:

-O  --output-document=文件,将数据写入此文件中。

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

的含义即为
将 http://mirrors.aliyun.com/repo/Centos-7.repo 文件中的数据写入到/etc/yum.repos.d/CentOS-Base.repo文件中,CentOS-Base.repo文件不需要事先创建。

参考链接:wget命令详解 https://www.jianshu.com/p/2e2ba8ecc22a

3.之后运行yum makecache生成缓存

yum makecache

这一步还是比较耗时的,而且速度不快几k到几十k每秒之间,可以不执行。

 

最终效果

最终效果如图,yum源更换为国内阿里镜像源后,yum 安装或更新包的速度非常快,保持在 几MB/s

-----------------------------------------------

有时候用阿里的yum源,会出现问题,“Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error”

此时,阿里云 yum 源域名无法解析,那么我们就要考虑将阿里yum源换成别的源,比如清华yum源。

-----------------------------------------------

解决方案2:替换CentOS的yum 源 为 国内的yum源--清华yum源。

具体步骤如下:

1.备份

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

2.创建 /etc/yum.repos.d/

touch /etc/yum.repos.d/CentOS-Base.repo

3.向 /etc/yum.repos.d/CentOS-Base.repo 写入 清华大学yum源配置:

# 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.
# 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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

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

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

4.结束。接下来可以直接使用yum 安装 所需工具包。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

wudinaniya

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

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

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

打赏作者

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

抵扣说明:

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

余额充值