原文地址:https://lala.im/8062.html,請支持原作者!該處僅作轉載。
昨天把自己维护的一台peertube实例从contabo迁移到littlecreekhosting了,这里记录下迁移过程。
因为是docker部署的,所以整个迁移过程也很简单,基本就是打包,传到新机器解压,up就行了。
这里先贴一下我的各项配置,compose的配置:
version: '3.5'
services:
peertube:
image: chocobozzz/peertube:production-buster
restart: unless-stopped
env_file:
- .env
depends_on:
- postgres
- redis
networks:
default:
ipv4_address: 172.18.0.233
ports:
- "1935:1935"
- "127.0.0.1:9000:9000"
volumes:
- assets:/app/client/dist
- ./docker-volume/data:/data
- ./docker-volume/config:/config
postgres:
image: postgres:13-alpine
restart: unless-stopped
env_file:
- .env
volumes:
- ./docker-volume/db:/var/lib/postgresql/data
redis:
image: redis:6-alpine
restart: unless-stopped
volumes:
- ./docker-volume/redis:/data
volumes:
assets:
networks:
default:
ipam:
driver: default
config:
- subnet: 172.18.0.0/16
.env的配置:
POSTGRES_USER=imlala
POSTGRES_PASSWORD=password
POSTGRES_DB=peertube
PEERTUBE_DB_USERNAME=imlala
PEERTUBE_DB_PASSWORD=password
PEERTUBE_DB_SSL=false
PEERTUBE_DB_HOSTNAME=postgres
PEERTUBE_WEBSERVER_HOSTNAME=example.com
PEERTUBE_WEBSERVER_PORT=443
PEERTUBE_WEBSERVER_HTTPS=true
PEERTUBE_TRUST_PROXY=["127.0.0.1", "loopback", "172.18.0.0/16"]
[email protected]
所有的配置文件和数据都在/opt/peertube目录下,所以我直接备份这个目录就行了。
细心的人可能已经看到compose内还有一个assets的命名卷,这个卷里面的数据实际上不需要备份。
因为assets卷里面存储的是peertube的前端资源文件,每次拉peertube镜像的时候都会生成,所以直接忽略掉这个卷即可。
下面是迁移过程,首先进到peertube目录:
cd /opt/peertube
停止并删除所有容器:
docker-compose down
回到上级目录打包:
cd ..
tar -zcvf peertube.tar.gz peertube/
将打包好的压缩包传到新机器内:
scp peertube.tar.gz [email protected]:/opt
nginx的反向代理配置文件也可以传过去:
scp /etc/nginx/conf.d/peertube.conf [email protected]:/etc/nginx/conf.d
新机器内先安装好运行环境,需要nginx/certbot/docker:
apt -y update
apt -y install curl nginx python3-certbot-nginx
curl -sSL https://get.docker.com/ | sh
systemctl enable --now nginx docker
docker-compose也得装一下:
curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
解压传过来的压缩包:
cd /opt
tar -xzvf peertube.tar.gz
进入peertube目录up即可:
cd peertube
docker-compose up -d
按需要编辑nginx反向代理的配置,主要就是把之前certbot接管的ssl配置给删掉,还有把listen80加回来:
nano /etc/nginx/conf.d/peertube.conf
改成这样就行了:
upstream backend {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name example.com;
client_max_body_size 0;
location / {
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://backend;
}
reset_timedout_connection on;
proxy_ignore_client_abort on;
tcp_nopush on;
tcp_nodelay on;
sendfile on;
sendfile_max_chunk 1M;
aio threads;
gzip on;
gzip_vary on;
gzip_types # text/html is always compressed by HttpGzipModule
text/css
application/javascript
font/truetype
font/opentype
application/vnd.ms-fontobject
image/svg+xml;
gzip_min_length 1000; # default is 20 bytes
gzip_buffers 16 8k;
gzip_comp_level 2; # default is 1
}
用certbot重新申请ssl证书:
certbot --nginx
至此迁移就全部完成了,可以打开站点测试看看是否各项功能都正常。
尤其要看一下调试界面的这个IP地址是否是你当前的公网IP: