美文网首页
ubuntu/centos替换软件源,安装docker或其他软件

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

作者: 旋转马达 | 来源:发表于2018-07-14 16:41 被阅读0次

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

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

    一:难处

    • 1: debian系的操作系统(ubuntu/linux mint)使用包管理系统(PMS)都是基于dpkg的,例如ubuntu上最常用的apt,apt-get。
    • 2:redhat系的操作系统(centos/fedora/openSUSE)使用的包管理系统(PMS)都是基于rpm的,例如centos上的yum。
    • 3:本文就讲解这两种最常用的包管理工具apt(推荐使用apt而不是apt-get),yum安装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

    • 1:如果你过去安装过 docker,先删掉:
      sudo apt-get remove docker docker-engine docker.io

    • 2:然后安装依赖
      sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common

    • 3:信任 Docker 的 GPG 公钥:
      curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

    • 4:对于 amd64 架构的计算机,添加软件仓库:

    sudo add-apt-repository \
       "deb [arch=amd64] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
       $(lsb_release -cs) \
       stable"
    
    • 5:更新apt的索引
      sudo apt-get update

    • 6:安装docker-ce
      sudo apt-get install docker-ce

    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

    • 1:如果你之前安装过 docker,请先删掉
      sudo yum remove docker docker-common docker-selinux docker-engine

    • 2:安装依赖
      sudo yum install -y yum-utils device-mapper-persistent-data lvm2

    • 3:下载docker-ce的repo
      wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo

    • 4:用sed把软件仓库地址替换为 TUNA:(如果不理解复制粘贴执行就好)
      sudo sed -i 's+download.docker.com+mirrors.tuna.tsinghua.edu.cn/docker-ce+' /etc/yum.repos.d/docker-ce.repo

    • 5:执行安装

        sudo yum makecache fast
        sudo yum install docker-ce
    

    相关文章

      网友评论

          本文标题:ubuntu/centos替换软件源,安装docker或其他软件

          本文链接:https://www.haomeiwen.com/subject/mulypftx.html