centos默认的yum使用的是国外源,安装软件非常慢。国内提供了一些yum源镜像,可以提速。
原理
yum的源配置文件都在/etc/yum.repo.d目录中,只需要将此目录下的文件替换成国内源,并重新生成缓存即可。
备份原有源
cd /etc/yum.repo.d
mkdir bak
mv Cent* ./bak # 将原有的所有文件均移动到bak目录中
下载新的源
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo #此处使用的是163的源,也可以用阿里云等
mv CentOS7-Base-163.repo CentOS-Base.repo #将下载下来的文件替换成CentOs的默认repo
生成缓存
yum clean all #清除缓存
yum list #更新列表
yum makecache #生成缓存
#下列两条用来测效果的,可以不需要
yum update
yum upgrade
附
CentOS7-Base-163.repo的内容如下,对于部分不具备wget的系统可以直接将以下内容复制进去
# 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 - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7