初始化信宜仓库服务器的准备工作

配置国内源

首先需要配置国内的源,不配置的话默认会从国外下载,速度非常慢,大大降低效率

参考:

https://blog.csdn.net/weixin_39394526/article/details/87935449

https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/

 cp /etc/apt/sources.list  /etc/apt/sources.list.bak  #备份
 vi /etc/apt/sources.list  #编辑源
 
 # 默认注释了源码镜像以提高 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
 
 apt-get update #更新源

安装docker

 #1.卸载之前的版本
 sudo apt-get remove docker docker-engine docker.io containerd runc
 
 #2.设置docker镜像
 #更新apt软件包索引并安装软件包以允许apt通过HTTPS使用存储库:
 sudo apt-get update
 #添加Docker的官方GPG密钥:
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
 #验证您现在是否拥有带有指纹的密钥:
 sudo apt-key fingerprint 0EBFCD88
 #设置镜像仓库:(使用阿里云镜像地址)
 sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
 
 #我执行到最后一步时,提示add-apt-repository 和 lsb_release 找不到 解决方法如下
 apt-get install software-properties-common
 sudo apt-get install lsb-core -y #较大非必要不安装
 
 
 #3.正式安装docker
 #更新apt软件包索引
 sudo apt-get update
 #安装最新版的docker
 sudo apt-get install docker-ce docker-ce-cli containerd.io
 
 #4启动
 service docker start
 #查看docker是否安装成功(利用查看版本来验证)
 docker version
 
 #q
 
 #最小化安装的ubuntu systemd找不到(题外话)
 apt-get install --reinstall systemd

安装docker-compose

 #镜像下载
 curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
 
 #授权
 chmod +x /usr/local/bin/docker-compose
 
 docker-compose --version

新建用户、用户组

这一步是为了以后维护docker的时候不需要每次用root(最高权限)登录,提高安全性

 root@master-yzjgxh2565653321-1637222778287-1118825:/# groupadd docker
 groupadd: group 'docker' already exists
 root@master-yzjgxh2565653321-1637222778287-1118825:/# groupadd docker-compose
 root@master-yzjgxh2565653321-1637222778287-1118825:/# useradd -m -s /bin/bash bigfoot01
 root@master-yzjgxh2565653321-1637222778287-1118825:/# passwd bigfoot01
 Enter new UNIX password:
 Retype new UNIX password:
 passwd: password updated successfully
 root@master-yzjgxh2565653321-1637222778287-1118825:/# visudo
 root@master-yzjgxh2565653321-1637222778287-1118825:/# gpasswd -a bigfoot01 docker
 root@master-yzjgxh2565653321-1637222778287-1118825:/# newgrp docker
 root@master-yzjgxh2565653321-1637222778287-1118825:/# gpasswd -a bigfoot01 docker-compose
 root@master-yzjgxh2565653321-1637222778287-1118825:/# newgrp docker-compose
 
 #useradd 的时候 -s /bin/bash 非常关键,决定了子用户输入命令有没有shell格式
 #gpasswd -a bigfoot01 docker 将bigfoot01加入到docker组
 #newgrp docker 更新用户组
 

后续还需要修改ssh远程端口和完善用户和用户组的权限分配,上面的用户只能用于docker开头的命令,只有docker权限还不足以达到维护服务器地步。