zoukankan      html  css  js  c++  java
  • 更改Ubuntu和Centos系统中的镜像源

    由于系统的镜像源都是在国外,所以一般下载相关软件包时的下载速度很慢,可以把镜像文件替换成国内的镜像源,本文以阿里云镜像仓库为主:

    一:Centos7系统为例:

      1:备份系统原有的镜像源,如下

    [root@molson ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    [root@molson ~]# ll /etc/yum.repos.d/
    总用量 32
    -rw-r--r--. 1 root root 2523 9月   9 20:52 CentOS-Base.repo.backup
    -rw-r--r--. 1 root root 1664 11月 30 2016 CentOS-Base.repo.backup.bak
    -rw-r--r--. 1 root root 1309 11月 30 2016 CentOS-CR.repo
    -rw-r--r--. 1 root root  649 11月 30 2016 CentOS-Debuginfo.repo
    -rw-r--r--. 1 root root  314 11月 30 2016 CentOS-fasttrack.repo
    -rw-r--r--. 1 root root  630 11月 30 2016 CentOS-Media.repo
    -rw-r--r--. 1 root root 1331 11月 30 2016 CentOS-Sources.repo
    -rw-r--r--. 1 root root 2893 11月 30 2016 CentOS-Vault.repo
    [root@molson ~]# 
    

      2:把阿里云镜像源下载到镜像源中,如下

       

    [root@molson ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
    --2020-09-09 21:05:37--  https://mirrors.aliyun.com/repo/Centos-7.repo
    正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 122.228.65.229, 115.238.192.242, 115.238.192.244, ...
    正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|122.228.65.229|:443... 已连接。
    已发出 HTTP 请求,正在等待回应... 200 OK
    长度:2523 (2.5K) [application/octet-stream]
    正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”
    
    100%[=======================================================================================================>] 2,523       --.-K/s 用时 0s      
    
    2020-09-09 21:05:37 (779 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])
    
    [root@molson ~]# ll /etc/yum.repos.d
    总用量 36
    -rw-r--r--. 1 root root 2523 6月  16 2018 CentOS-Base.repo
    -rw-r--r--. 1 root root 2523 9月   9 20:52 CentOS-Base.repo.backup
    -rw-r--r--. 1 root root 1664 11月 30 2016 CentOS-Base.repo.backup.bak
    -rw-r--r--. 1 root root 1309 11月 30 2016 CentOS-CR.repo
    -rw-r--r--. 1 root root  649 11月 30 2016 CentOS-Debuginfo.repo
    -rw-r--r--. 1 root root  314 11月 30 2016 CentOS-fasttrack.repo
    -rw-r--r--. 1 root root  630 11月 30 2016 CentOS-Media.repo
    -rw-r--r--. 1 root root 1331 11月 30 2016 CentOS-Sources.repo
    -rw-r--r--. 1 root root 2893 11月 30 2016 CentOS-Vault.repo
    [root@molson ~]#
    

      3:运行 yum makecache 生成缓存

       

    [root@molson ~]#  yum makecache
    已加载插件:fastestmirror
    base                                                                                                                      | 3.6 kB  00:00:00     
    extras                                                                                                                    | 2.9 kB  00:00:00     
    updates                                                                                                                   | 2.9 kB  00:00:00     
    (1/6): updates/7/x86_64/filelists_db                                                                                      | 2.4 MB  00:00:01     
    (2/6): extras/7/x86_64/other_db                                                                                           | 124 kB  00:00:01     
    (3/6): extras/7/x86_64/filelists_db                                                                                       | 217 kB  00:00:01     
    (4/6): updates/7/x86_64/other_db                                                                                          | 316 kB  00:00:00     
    (5/6): base/7/x86_64/other_db                                                                                             | 2.6 MB  00:00:02     
    (6/6): base/7/x86_64/filelists_db                                                                                         | 7.1 MB  00:00:03     
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    元数据缓存已建立
    

      由上图可知,阿里云镜像源已经更新成功

    二:ubuntu1804系统为例

      1:先把原来的镜像镜像备份,如下

      

    root@template-ubuntu-20200606:~# cp /etc/apt/sources.list    /etc/apt/sources.list.backup.bak
    

      

      2:打开文件,删除文件里的内容,把阿里云镜像源复制进去,具体如下

      

    root@template-ubuntu-20200606:~# vim /etc/apt/sources.list
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    

      添加成功后,阿里云镜像源仓库就更新成功

      

  • 相关阅读:
    微信支付接口之心酸
    分页之辛酸史
    谈谈面试经历
    Linux(Ubuntu 14.0)
    Android(Xamarin)之旅(五)
    css:befor :after 伪元素的妙用
    js设计模式-代理模式
    html页面元素命名参考
    html5-meta标签和搜索引擎
    iframe框架加载完成后执行函数
  • 原文地址:https://www.cnblogs.com/molson/p/13642037.html
Copyright © 2011-2022 走看看