【seafile】服务器配合 Nginx 自建 seafile pro 网盘

本文最后更新于:2022年11月4日 下午

Seafile 是国产开源的一个自建网盘,作为网盘十分优越,客户端支持多平台,支持团队协作,可以在线编辑Office文件,最重要的是支持自行部署。

背景

  • 本文假设你有基础的使用 Linux 命令行的能力
  • 本文需要配置在1c1g或更高的服务器,并假设你有root权限
  • 本文在 Ubuntu 20.04 系统上进行

Seafile 简介

Seafile 是一个可自建的网盘。社区版开源免费,pro版闭源收费。最初自建网盘的时候考虑过 NextCloud Cloudreve 但最终还是选择了 Seafile。

本文跟官方 Docker 教程不同,官方教程是使用了 seafile 镜像内置的 Nginx 来处理 ssl,很方便,但占用了 443 端口,会导致这个服务器不方便部署别的服务。因此本文在官方教程基础上进行了修改。seafile 容器暴露 8000 端口,映射容器 80 端口,宿主机和容器间不加密通信,用宿主机的 Nginx 反代到 8000 端口并处理https

seafile

下载 pro 版

先浏览器打开英文版网站,再去 customer center 注册账号并登录。

就可以免费下载pro版

官方教程:Deploy Seafile Pro Edition
但这个英文版教程没有中文全面,少了步骤

1
docker pull docker.seadrive.org/seafileltd/seafile-pro-mc:latest

启动 docker-compose

dockerdocker-compose 的安装参见本博客另一篇文章:Docker 安装

1
2
mkdir -p /opt/seafile && /opt/seafile
vim docker-compose.yml

输入:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
version: '2.0'
services:
db:
image: mariadb:10.5
container_name: seafile-mysql
environment:
- MYSQL_ROOT_PASSWORD=frae439DFREW32 # Requested, set the root's password of MySQL service.
- MYSQL_LOG_CONSOLE=true
volumes:
- /opt/seafile/mysql/db:/var/lib/mysql # Requested, specifies the path to MySQL data persistent store.
networks:
- seafile-net

memcached:
image: memcached:1.6
container_name: seafile-memcached
entrypoint: memcached -m 256
networks:
- seafile-net

elasticsearch:
image: elasticsearch:7.16.2
container_name: seafile-elasticsearch
environment:
- discovery.type=single-node
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms1g -Xmx1g"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 2g
volumes:
- /opt/seafile/elasticsearch/data:/usr/share/elasticsearch/data # Requested, specifies the path to Elasticsearch data persistent store.
networks:
- seafile-net

seafile:
image: docker.seadrive.org/seafileltd/seafile-pro-mc:latest
container_name: seafile
ports:
- "127.0.0.1:8000:80"
# - "127.0.0.1:4433:443" # If https is enabled, cancel the comment.
volumes:
- /opt/seafile/data:/shared # Requested, specifies the path to Seafile data persistent store.
environment:
- DB_HOST=db
- DB_ROOT_PASSWD=frae439DFREW32 # Requested, the value should 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=你的邮箱 # Specifies Seafile admin user, default is '[email protected]'
- SEAFILE_ADMIN_PASSWORD=asecret # Specifies Seafile admin password, default is 'asecret'
- SEAFILE_SERVER_LETSENCRYPT=false # Whether to use https or not
- SEAFILE_SERVER_HOSTNAME=example.seafile.com # Specifies your host name if https is enabled
depends_on:
- db
- memcached
- elasticsearch
networks:
- seafile-net

networks:
seafile-net:

需要修改的几个地方。
MYSQL_ROOT_PASSWORDDB_ROOT_PASSWD 需要一样。
SEAFILE_ADMIN_EMAILSEAFILE_ADMIN_PASSWORD 很重要。是你初始登录的账号密码
SEAFILE_SERVER_HOSTNAME 修改成你自己的。

运行:

1
2
3
cd /opt/seafile
mkdir -p elasticsearch/data/ && chmod 777 -R elasticsearch/data/ # seafile版本9以上需要
docker-compose up -d

配置 Nginx

安装 Nginx

1
2
sudo apt update && apt upgrade -y
sudo apt install nginx -y

安装 certbot

对于 ubuntu 20.04 上 certbot 的安装:

1
2
sudo apt update && apt upgrade -y
sudo apt install certbot python3-certbot-nginx -y

对于 ubuntu 22.04 上 certbot 的安装:

1
2
3
4
5
sudo apt update && apt upgrade -y
sudo snap install core; sudo snap refresh core
sudo apt remove certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

申请证书

certbot 申请证书(首先保证你的80端口是开的

1
certbot certonly --nginx -d 你的域名

配置 Nginx

配置nginx文件(取决于你的 Nginx 版本,请自行搜索如何配置)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
server {
listen 80;
server_name example.com default_server;

location / {
rewrite ^ https://$host$request_uri? permanent;
}
}
server {
listen 443;
ssl on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;

server_name example.com;
add_header Strict-Transport-Security max-age=15768000;
client_max_body_size 10m;

location / {
proxy_pass http://127.0.0.1:8000/;
proxy_read_timeout 310s;
# 重要
proxy_redirect http:// https://;
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/seafile.access.log;
error_log /var/log/nginx/seafile.error.log;
}
}

重启 Nginx

1
2
systemctl reload nginx
systemctl restart nginx

其他设置

Seafile 的配置文件存放在 shared/seafile/conf 目录下,您可以根据Seafile 手册的指导来修改这些配置项。

一旦修改了配置文件,您需要重启服务以使其生效:

推荐这个:

1
docker-compose restart

查找日志

1
docker-compose logs -f

Seafile 容器中 Seafile 服务本身的日志文件存放在 /shared/logs/seafile 目录下,或者您可以在宿主机上 Seafile 容器的卷目录中找到这些日志,例如:/opt/seafile/data/logs/seafile

同样 Seafile 容器的系统日志存放在 /shared/logs/var-log 目录下,或者宿主机目录 /opt/seafile/data/logs/var-log

增加一个新的管理员

【推荐】网站添加

登录网站,进入 https://你的域名/sys/users/ ,添加用户,然后把用户设置成管理员。

脚本添加

服务器运行脚本增加,确保各容器正常运行,然后执行以下命令:

1
docker exec -it seafile /opt/seafile/seafile-server-latest/reset-admin.sh

根据提示输入用户名和密码,您现在有了一个新的管理帐户。

Web 文件断点续传

在Web界面上传大文件时,如果网络不可靠,则可能会中断上传。如果上传可以从上次停止的地方恢复,将会很方便。在 Seafile 专业版 4.4.0及更新版本中,支持断点续传功能。

断点续传的工作原理如下:

  1. 用户在Web界面上传一个大文件,并且在上传过程中连接中断。
  2. 服务器将记住上传停止的位置。
  3. 当同一个文件被上传到相同资料库中的同一文件夹时,服务器会告诉浏览器从哪里开始上传。

限制:

只支持重新上传;文件更新和文件夹上传无法断点续传。

只支持 Chrome, Firefox, IE 10+ 。

要启用断点续传功能,请添加如下配置到 seahub_settings.py 中:

1
ENABLE_RESUMABLE_FILEUPLOAD = True

在 Seafile 集群中,为了使此功能如期工作,必须执行以下两个特殊配置之一:

  1. seafile-server-latest/seafile-data/httptemp 目录应该通过NFS共享给所有前端 Seafile 服务器。
  2. 或者,将负载均衡器配置为始终将来自同一IP地址的请求发送到固定的后端服务器。

【seafile】服务器配合 Nginx 自建 seafile pro 网盘
https://pawswrite.xyz/posts/5921bbff.html
作者
Rainbow
发布于
2022年10月12日
许可协议