Windows下部署Seafile 8.0.11[Deploy seafile pro 8.0.11 in windows docker]

Deploy seafile pro 8.0.11 in windows docker

系统环境

Windows 10 LTSB 2016/2019 X64

Docker for Windows Installer 2.3.0.46911

主机IP为192.168.1.7

安装配置

Hyper-V

#windows 10 LTSB 2016 X64
#windows 10 LTSC 2019 X64
#管理员权限命令行
DISM /Online /Enable-Feature /All /FeatureName:Microsoft-Hyper-V

-------------------------------------------------------------------
部署映像服务和管理工具
版本: 10.0.14393.0

映像版本: 10.0.14393.2457

启用一个或多个功能
[==========================100.0%==========================]
操作成功完成。
重新启动 Windows 以完成该操作。
是否立即重新启动计算机? (Y/N)Y

正在重新启动计算机...
-------------------------------------------------------------------

#重新启动计算机

Docker for Windows

Docker Desktop[右键]→Quit Docker Destop

开始菜单右键→命令提示符

robocopy "C:\Users\Public\Documents\Hyper-V\Virtual hard disks" "D:\PortableApps\Hyper-V\Docker" /mir

if exist "C:\Users\Public\Documents\Hyper-V\Virtual hard disks" rmdir /s /q "C:\Users\Public\Documents\Hyper-V\Virtual hard disks"
if not exist "C:\Users\Public\Documents\Hyper-V" mkdir "C:\Users\Public\Documents\Hyper-V"

开始菜单右键→命令提示符(管理员)

mklink /d "C:\Users\Public\Documents\Hyper-V\Virtual hard disks" "D:\PortableApps\Hyper-V\Docker"

Docker Desktop[右键]→Troubleshoot→Reset to factory defaults

Docker Desktop[右键]→Settings→General[勾选Start Docker Desktop when you log in;Send usage statistics;其他取消]

Docker Desktop[右键]→Settings→Resources→FILE SHARING[增加D:\PortableApps\Seafile]

核实docker版本:

开始菜单右键→此处打开PowerShell窗口:

docker version
#19.03.12

docker-compose --version
#docker-compose version 1.26.2, build eefe0d31

镜像加速

#cmd:
notepad.exe %USERPROFILE%\.docker\daemon.json

内容如下:

{
  "registry-mirrors": ["https://******.mirror.aliyuncs.com"],
  "insecure-registries": [],
  "debug": true,
  "experimental": false
}

重启Windows docker。

seafile

以下操作默认在Powershell中执行,进入Powershell方法:

开始菜单→Windows PowerShell→Windows PowerShell

#停止并删除所有容器
docker ps
docker stop (docker ps -a -q)
docker rm (docker ps -a -q)
docker ps

#其他方法
docker ps -a --format "{{.ID}}" | foreach {
    docker stop $_
    docker rm $_
}
 
#删除所有镜像
docker images
docker rmi --force (docker images -q)
docker images

#其他方法
docker images --format "{{.ID}}" | foreach {
   docker rmi stop $_
}

#导入已下载docker包
docker load -i D:\docseafile-pro-mc-8.0.11.tar
docker tag 34dd35104adc seafile-pro-mc:8.0.11

docker load -i D:\mariadb-10.5.tar
docker tag 9a2e250ac491 mariadb:10.5

docker load -i D:\memcached-1.5.6.tar
docker tag 855fdf342eda memcached:1.5.6

docker load -i D:\elasticsearch-with-ik-5.6.16.tar
docker tag cc24b852b4e4 elasticsearch-with-ik:5.6.16

docker load -i D:\documentserver-6.3.2.tar
docker tag a29e61244e3c documentserver:6.3.2

docker images

设置

网络

#查看docker默认网络情况
docker network inspect bridge

#查看docker网络
docker network ls
docker network ls -f 'name=conf_seafile-net'
docker network inspect conf_seafile-net

#删除重复IP段且无用的网络(避免冲突,一般为以前运行过docker遗留的网络配置)
docker network rm conf_seafile-net

docker启动

.env中按照主机IP,端口,各docker image ID,email,password根据需要配置;然后根据yml文件版本,选择对应启动命令。

#启动容器组
#docker-compose V2
docker-compose up -d

#查看容器日志
docker-compose logs
docker logs seafile-8.0.11

#停止容器
#docker-compose V2
docker-compose stop

#打开已存在容器
#docker-compose V2
docker-compose start

onlyoffice

关闭验证

排除错误(unable to verify the first certificate),若不启用https,本项可不设置。

#进入onlyoffice容器
docker exec -it onlyoffice /bin/bash
/var/www/onlyoffice/documentserver/npm/json -f /etc/onlyoffice/documentserver/default.json -I -e 'this.services.CoAuthoring.requestDefaults.rejectUnauthorized=false'
cat /etc/onlyoffice/documentserver/default.json
#重启onlyoffice
supervisorctl restart all
#退出onlyoffice容器
exit
添加字体

字体存放D:\PortableApps\winfonts\文件夹。

#拷贝字体至onlyoffice容器内部
docker cp D:\PortableApps\winfonts\ onlyoffice:/usr/share/fonts/
#进入onlyoffice容器
docker exec -it onlyoffice /bin/bash
ls /usr/share/fonts/winfonts/
mkfontscale
mkfontdir
fc-cache -fv
/usr/bin/documentserver-generate-allfonts.sh
#重启onlyoffice
supervisorctl restart all
#退出onlyoffice容器
exit

在D:\PortableApps\Seafile\seafile-data\seafile\conf\seahub_settings.py最后增加(或者修改):

# Enable Only Office
ENABLE_ONLYOFFICE = True
VERIFY_ONLYOFFICE_CERTIFICATE = False
ONLYOFFICE_APIJS_URL = 'http://192.168.1.7/onlyofficeds/web-apps/apps/api/documents/api.js'
ONLYOFFICE_FILE_EXTENSION = ('doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'odt', 'fodt', 'odp', 'fodp', 'ods', 'fods')
ONLYOFFICE_EDIT_FILE_EXTENSION = ('docx', 'pptx', 'xlsx')

删除pycache,修改nginx配置文件:

$seafile_data_path="D:\PortableApps\Seafile"
ls $seafile_data_path\seafile-data\seafile\conf
rm -r "$seafile_data_path\seafile-data\seafile\conf\__pycache__"
ls $seafile_data_path\seafile-data\seafile\conf
#替换nginx配置文件
copy seafile.nginx.conf D:\PortableApps\Seafile\seafile-data\nginx\conf
#重启nginx
docker exec seafile-8.0.11 nginx -s reload
#重启seafile服务
docker exec seafile-8.0.11 /opt/seafile/seafile-pro-server-8.0.11/seafile.sh restart
docker exec seafile-8.0.11 /opt/seafile/seafile-pro-server-8.0.11/seahub.sh restart

license

许可文件存放到D:\PortableApps\Seafile\seafile-data\seafile

主页

进入http://192.168.1.7/主页在系统管理中设置[SERVICE_URL:http://192.168.1.7/]|[FILE_SERVER_ROOT:http://192.168.1.7/seafhttp]

故障处理

无。

附件

.env

# Hosts
# ${host_ip} ${http_port} ${https_port}
host_ip=192.168.1.7
http_port=80
https_port=443

# 超时定值设置
DOCKER_CLIENT_TIMEOUT=1200
COMPOSE_HTTP_TIMEOUT=1200

# images ID
# ${seafile_id} ${mysql_id} ${memcached_id} ${elasticsearch_id} ${onlyoffice_id}
seafile_id=34dd35104adc
mysql_id=9a2e250ac491
memcached_id=855fdf342eda
elasticsearch_id=cc24b852b4e4
onlyoffice_id=a29e61244e3c

# seafile version
# ${seafile_version}
seafile_version=8.0.11

# seafile path
# ${seafile_data_path}
seafile_data_path=D:\PortableApps\Seafile

# email information
# ${my_email} ${my_email_pass}
my_email=******@qq.com
my_email_pass=******

# mysql password
# ${mysql_password}
mysql_password=******

# sql外部单口
# ${mysql_port}
mysql_port=63306

docker-compose.yml

version: '2.0'
services:

  db:
    image: ${mysql_id}
    container_name: seafile-mysql
    privileged: true
    restart: always
    ports:
      - "${mysql_port}:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=${mysql_password}  # Requested, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
    volumes:
      - ${seafile_data_path}/seafile-mysql/db:/var/lib/mysql  # Requested, specifies the path to MySQL data persistent store.
    networks:
      seafile-net:
        ipv4_address: 172.19.0.3

  memcached:
    image: ${memcached_id}
    container_name: seafile-memcached
    entrypoint: memcached -m 512
    restart: always
    networks:
      seafile-net:
        ipv4_address: 172.19.0.5

  elasticsearch:
    image: ${elasticsearch_id}
    container_name: seafile-elasticsearch
    privileged: true
    restart: always
    environment:
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    mem_limit: 2g
    volumes:
      - ${seafile_data_path}/seafile-elasticsearch/data:/usr/share/elasticsearch/data  # Requested, specifies the path to Elasticsearch data persistent store.
    networks:
      seafile-net:
        ipv4_address: 172.19.0.6
          
  seafile:
    image: ${seafile_id}
    container_name: seafile-${seafile_version}
    privileged: true
    restart: always
    ports:
      - "${host_ip}:${http_port}:80"
      #- "${host_ip}:${https_port}:443"  # If https is enabled, cancel the comment.
    volumes:
      - ${seafile_data_path}/seafile-data:/shared   # Requested, specifies the path to Seafile data persistent store.
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=${mysql_password}  # Requested, the value shuold be root's password of MySQL service.
      - TIME_ZONE=Asia/Shanghai # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=${my_email} # Specifies Seafile admin user, default is 'me@example.com'
      - SEAFILE_ADMIN_PASSWORD=${my_email_pass}     # Specifies Seafile admin password, default is 'asecret'
      #- SEAFILE_SERVER_LETSENCRYPT=true   # Whether to use https or not
      #- SEAFILE_SERVER_HOSTNAME=${host_ip}   # Specifies your host name if https is enabled
    depends_on:
      - db
      - memcached
      - elasticsearch
    networks:
      seafile-net:
        ipv4_address: 172.19.0.2

  onlyoffice:
    image: ${onlyoffice_id}
    container_name: onlyoffice
    privileged: true
    restart: always
    ports:
      - "${host_ip}:8008:80"
      #- "${host_ip}:8443:443"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    mem_limit: 8g
    volumes:
      - ${seafile_data_path}/onlyoffice/DocumentServer/data:/var/www/onlyoffice/Data
    networks:
      seafile-net:
        ipv4_address: 172.19.0.7

networks:
    seafile-net:
       ipam:
         driver: default
         config:
         - subnet: 172.19.0.0/16
           gateway: 172.19.0.1

seafile.nginx.conf

# -*- mode: nginx -*-
# Auto generated at 11/21/2020 22:08:56

# Required for only office document server
map $http_x_forwarded_proto $the_scheme {
        default $http_x_forwarded_proto;
        "" $scheme;
    }
map $http_x_forwarded_host $the_host {
        default $http_x_forwarded_host;
        "" $host;
    }
map $http_upgrade $proxy_connection {
        default upgrade;
        "" close;
    }

server {
listen 80;
server_name seafile.example.com;

    client_max_body_size 10m;

    location / {
        proxy_pass http://127.0.0.1:8000/;
        proxy_read_timeout 310s;
        proxy_set_header Host $host;
        proxy_set_header Forwarded "for=$remote_addr;proto=$scheme";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Connection "";
        proxy_http_version 1.1;

        client_max_body_size 0;
        access_log      /var/log/nginx/seahub.access.log seafileformat;
        error_log       /var/log/nginx/seahub.error.log;
    }

    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size 0;
        proxy_connect_timeout  36000s;
        proxy_read_timeout  36000s;
        proxy_request_buffering off;

        access_log      /var/log/nginx/seafhttp.access.log seafileformat;
        error_log       /var/log/nginx/seafhttp.error.log;
    }

    location /seafdav {
        client_max_body_size 0;
        fastcgi_pass    127.0.0.1:8080;
        fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
        fastcgi_param   PATH_INFO           $fastcgi_script_name;

        fastcgi_param   SERVER_PROTOCOL     $server_protocol;
        fastcgi_param   QUERY_STRING        $query_string;
        fastcgi_param   REQUEST_METHOD      $request_method;
        fastcgi_param   CONTENT_TYPE        $content_type;
        fastcgi_param   CONTENT_LENGTH      $content_length;
        fastcgi_param   SERVER_ADDR         $server_addr;
        fastcgi_param   SERVER_PORT         $server_port;
        fastcgi_param   SERVER_NAME         $server_name;

        access_log      /var/log/nginx/seafdav.access.log seafileformat;
        error_log       /var/log/nginx/seafdav.error.log;
    }

    location /media {
        root /opt/seafile/seafile-server-latest/seahub;
    }

location /onlyofficeds/ {
        # THIS ONE IS IMPORTANT ! - Trailing slash !
        proxy_pass http://172.19.0.7/;
        # onlyoffice docker IP !
        proxy_http_version 1.1;
        client_max_body_size 100M; # Limit Document size to 100MB
        proxy_read_timeout 3600s;
        proxy_connect_timeout 3600s;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $proxy_connection;
        # THIS ONE IS IMPORTANT ! - Subfolder and NO trailing slash !
        proxy_set_header X-Forwarded-Host $the_host/onlyofficeds;
        proxy_set_header X-Forwarded-Proto $the_scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
        proxy_cookie_path / "/; httponly; secure; SameSite=Lax";
    }

    # For letsencrypt
    location /.well-known/acme-challenge/ {
        alias /var/www/challenges/;
        try_files $uri =404;
    }
}