静看光阴荏苒
不管不顾不问不说也不念

PeerTube迁移(Docker)

昨天把自己维护的一台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"]
PEERTUBE_ADMIN_EMAIL=imlala@example.com

所有的配置文件和数据都在/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 root@1.1.1.1:/opt

nginx的反向代理配置文件也可以传过去:

scp /etc/nginx/conf.d/peertube.conf root@1.1.1.1:/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:

赞(2)
未经允许不得转载:荒岛 » PeerTube迁移(Docker)
分享到: 更多 (0)

评论 7

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #1

    littlecreekhosting的vps怎么样?网上资料稀缺 :???:

    yntzes2年前 (2022-05-19) QQbrowser QQbrowser Android 4.3 Android 4.3回复
    • 一般般吧,主要便宜,应该是oneman。。

      LALA2年前 (2022-05-22) Google Chrome 86.0.4240.198 Google Chrome 86.0.4240.198 Windows 10 x64 Edition Windows 10 x64 Edition回复
  2. #2

    我用本地nginx反代以后,视频上传什么的没问题,但是播放无法播放,可以付费解决. :smile:

    caibao2年前 (2022-09-27) Firefox 105.0 Firefox 105.0 Windows 10 x64 Edition Windows 10 x64 Edition回复
    • 本地nginx是什么意思,你是说你用电脑本地的nginx反代服务器上的peertube?

      LALA2年前 (2022-09-27) Google Chrome 104.0.0.0 Google Chrome 104.0.0.0 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • :cool: 你这儿没开邮件提醒,我问了之后自己去百度搜索相关知识了,最后换了个反向代理工具解决的,现在需要解决的问题是peertube对接oss.另外我说的本地nginx是指的服务器上原本在运行的nginx服务,代理docker中的peertube.不能播放的原因是因为nginx要把整个流媒体缓存完才播放,最后换了其他web反向代理工具解决的.

        caibao1年前 (2022-10-28) Firefox 106.0 Firefox 106.0 Windows 10 x64 Edition Windows 10 x64 Edition回复
      • :grin: 恨不得去WH上门请教就好.反正离的近..

        caibao1年前 (2022-10-28) Firefox 106.0 Firefox 106.0 Windows 10 x64 Edition Windows 10 x64 Edition回复

分享创造快乐

广告合作资源投稿