CentOS换源,加速软件安装速度

139 次查看 0 条评论

有时候yum下载时速度很慢,会不停的换mirrors,可能到了最后还会安装失败。这时候我们可以考虑清楚缓存并更新yum源。

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/ 目录

这里使用阿里云源:

# CentOS 5.x
curl -o /etc/yum.repos.d/CentOS-Base.repo "http://mirrors.aliyun.com/repo/Centos-5.repo"
# CentOS 6.X
curl -o /etc/yum.repos.d/CentOS-Base.repo "http://mirrors.aliyun.com/repo/Centos-6.repo"
# CentOS 7.x
curl -o /etc/yum.repos.d/CentOS-Base.repo "http://mirrors.aliyun.com/repo/Centos-7.repo"

文章末尾有附清华源。

3、清理并重新生成源缓存

## 清理并生成缓存
yum clean all && yum makecache
## 查看源信息
yum repolist
yum list

97230-c4twxkme548.png

4、禁用fastestmirror插件

每次使用yum安装软件都会出现一个fastestmirror的插件,都要等半天。所以禁用掉插件后再手动配置镜像源会加快安装速度。

vi /etc/yum/pluginconf.d/fastestmirror.conf
## 修改内容
enabled=1//由1改为0,禁用该插件
## 快速修改
sed -i "s/enabled=1/enabled=0/g" /etc/yum/pluginconf.d/fastestmirror.conf

或者直接禁用所有插件:

vi /etc/yum.conf
## 修改内容
plugins=1 //改为0,不使用插件
## 快速修改
sed -i "s/plugins=1/plugins=0" /etc/yum.conf

5、清华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.
#
#

[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

CentOS-Base.repo


参考资料:

  1. CentOS 7 禁用fastestmirror插件并配置清华镜像源
CentOS YUM

暂无评论