优化yum下载安装慢,不断换mirror

https://zhuanlan.zhihu.com/p/78471090

不停地换mirror,为了解决这个问题,在网上搜了好多资料,总结出一个基于aliyun的mirror源

先检查:是否能正常上网,DNS是否正常,网关gw是否正常,若通过ping 不正常,则解决好网络,再进行下面操作.

 

1. 清除缓存

[root@centos7 ~]#  yum clean all
已加载插件:fastestmirror
正在清理软件源: base extras updates
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors

2.元数据建立

[root@centos7 ~]#  yum makecache
已加载插件:fastestmirror
Determining fastest mirrors
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                          | 3.6 kB  00:00:00     
extras                                                                        | 3.4 kB  00:00:00     
updates                                                                       | 3.4 kB  00:00:00     
(1/12): base/7/x86_64/group_gz                                                | 166 kB  00:00:01     
(2/12): extras/7/x86_64/prestodelta                                           | 100 kB  00:00:00     
(3/12): extras/7/x86_64/filelists_db                                          | 603 kB  00:00:02     
(4/12): extras/7/x86_64/other_db                                              | 126 kB  00:00:00     
(5/12): extras/7/x86_64/primary_db                                            | 205 kB  00:00:01     
(6/12): base/7/x86_64/filelists_db                                            | 6.9 MB  00:00:02     
(7/12): base/7/x86_64/primary_db                                              | 5.9 MB  00:00:03     
(8/12): updates/7/x86_64/prestodelta                                          | 679 kB  00:00:01     
(9/12): updates/7/x86_64/other_db                                             | 578 kB  00:00:01     
(10/12): updates/7/x86_64/filelists_db                                        | 3.4 MB  00:00:02     
(11/12): updates/7/x86_64/primary_db                                          | 6.0 MB  00:00:02     
(12/12): base/7/x86_64/other_db                                               | 2.5 MB  00:00:06     
元数据缓存已建立

3. 更新

[root@centos7 ~]#  yum update
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No packages marked for update

4.备份yum源 

[root@centos7 ~]#  cd /etc/yum.repos.d/
[root@centos7 yum.repos.d]#  ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@centos7 yum.repos.d]#  mv CentOS-Base.repo CentOS-Base.repo.backup
[root@centos7 yum.repos.d]#  ls
CentOS-Base.repo.backup  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo           CentOS-fasttrack.repo  CentOS-Sources.repo

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

  再创建缓存

[root@centos7 yum.repos.d]#  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2018-12-02 17:55:13--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 183.61.14.235, 183.61.14.231, 183.61.14.236, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|183.61.14.235|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

100%[===========================================================>] 2,523       --.-K/s 用时 0s      

2018-12-02 17:55:18 (107 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

[root@centos7 yum.repos.d]# yum makecache 已加载插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; 拒绝连接" 正在尝试其它镜像。 http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; 未知的错误" 正在尝试其它镜像。 base | 3.6 kB 00:00:00 extras | 3.4 kB 00:00:00 updates | 3.4 kB 00:00:00 元数据缓存已建立

  

posted @ 2018-12-02 18:09  找工作好爽啊哈哈哈呜  阅读(5442)  评论(0编辑  收藏  举报