CentOS系统速度慢怎么解决

云服务器使用帮助

CentOS系统速度慢怎么解决

2023-01-07 13:56


                                            




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

 

 

解决方案:

替换CentOS的yum 源 为 国内的镜像源。以下方法适用余centos6.*和centos7.*

 

更换 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

如下图所示:

 

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 安装 所需工具包。