最近,发现 Docker 已经支持 Ubuntu Server 20.04,并且腾讯云也有了官方的 Ubuntu Server 20.04 的镜像,准备将自己的服务器升级到最新版本。

因为我使用的是腾讯官方的镜像,而且服务器上也没什么东西。就想着直接重装成新系统,然后将文件复制回去。

备份文件

按量计费购买一个 10G 的云硬盘,挂载到服务器上。按照 教程 挂载到一个文件夹。复制所有用户文件到新硬盘里。

# 查看硬盘名称
fdisk -l
# 格式化
mkfs -t ext4 /dev/vdb
# 挂载硬盘
mount /dev/vdb data

并且给当前使用的 50G 硬盘做快照。

配置 SSH

直接让腾讯云在重装系统的时候配置好 ssh_key,检查了一下配置,没有问题。

还原文件

先将网站相关的文件还原,要注意权限,postgres 的数据库文件需要 root 权限。

安装 Docker

参考:

Docker

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# 使用腾讯云的内网镜像源
sudo add-apt-repository \
   "deb [arch=amd64] http://mirrors.tencentyun.com/docker-ce/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get update
sudo apt-get install docker-ce

Docker Compose

# 使用 FastGit 加速器
sudo curl -L "https://hub.fastgit.org/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

设置镜像加速器

sudo vim /etc/default/docker
# 添加如下配置
DOCKER_OPTS="--registry-mirror=https://mirror.ccs.tencentyun.com"
# 或者
sudo vim /etc/docker/daemon.json
# 添加如下配置
{
    "registry-mirrors": [
        "https://mirror.ccs.tencentyun.com"
    ]
}

标签: 升级, Ubuntu, 服务器