ubuntu/centos替换软件源,安装docker或其他软件

2018-07-14  本文已影响0人  旋转马达

ubuntu和centos系统国内快速安装docker

容器化是当前软件开发最流行的趋势,docker则是容器领域的领导者,无论是微服务,还是区块链中的(hyperledger)都要使用docker,学会使用docker是每一个互联网行业开发人员的基本技能。本文讲解国内环境在ubuntu系统上安装docker时候遇到的困难已经解决方案,如何才能快速的安装完毕docker。

一:难处

       不管是apt还是yum,一般安装软件都是通过网络来访问存储在互联网上软件包来安装,那么提供存储软件包的服务器就是仓库(repository)。但问题就出在这些仓库上,这些仓库都是在国外的,因为国内的网络环境不是怎么好,所以通常访问这些仓库都会很慢,也就直接导致我们安装软件很慢,浪费大把的时间。

二:解决方案

镜像网站

       镜像,原意是光学里指的物体在镜面中所成之像。引用到电脑网络上,一个网站的镜像是指对一个网站内容的拷贝。镜像通常用于为相同信息内容提供不同的源,特别是在下载量大的时候提供了一种可靠的网络连接。制作镜像是一种文件同步的过程。“镜像网站”(英文:Mirror sites [1] ),又译作““镜像站点” [1] ,亦即把一个互联网上的网站数据“拷贝”到本地服务器,并保持本地服务器数据的同步更新,因此也称为“复制网络站点” 。
       因此,解决国外仓库访问慢的问题就是使用镜像,将获取软件的源修改为国内的镜像网站,我就用清华清华大学开源软件镜像站了,别的还有很多,你们可以自己选。这种方式不仅仅适用于docker,也适用于任何linux上的软件安装,这样你的人生又多了一点时间陪家人,陪妹子。

Ubuntu18.04LTS替换软件源安装docker

Ubuntu 的软件源配置文件是/etc/apt/sources.list。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用 TUNA 的软件源镜像。

    # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
    deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse

    # 预发布软件源,不建议启用
    # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
    # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

安装docker

sudo add-apt-repository \
   "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

Centos7替换软件源安装docker

同样的方式,换汤不换药,我们去替换yum的软件源就可以使用国内的镜像站点安装软件了,速度杠杠的。
首先备份 CentOS-Base.repo
sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak 将以下内容写入 /etc/yum.repos.d/CentOS-Base.repo后更新软件包缓存 sudo yum makecache以启用 TUNA 软件仓库。

    # 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

安装docker

    sudo yum makecache fast
    sudo yum install docker-ce
上一篇下一篇

猜你喜欢

热点阅读