部署 Seafile 专业版本服务器

本文档用来说明通过预编译好的安装包来安装并运行基于 MySQL/MariaDB 的 Seafile 服务器。

提示:如果您是初次部署 Seafile 服务,我们建议您使用自动安装脚本来快速部署一个 Seafile 服务。

下载安装包和申请试用许可证书

需要您添加 Seafile 售前人员,询要专业版安装包和试用许可证书

部署和目录设计

假设你已经下载 seafile-pro-server_*/opt/seafile目录下。 我们建议这样的目录结构:

mkdir  -p /opt/seafile/installed 
mv seafile-pro-server_* /opt/seafile/installed 
cd /opt/seafile/installed 
#将 seafile-pro-server_* 解压到 /opt/seafile 目录下
tar -xzf seafile-pro-server_* -C /opt/seafile

现在,你的目录看起来应该像这样:

#tree seafile -L 2
seafile
├── installed
│   └── seafile-pro-server_8.0.0_x86-64.tar.gz
└── seafile-pro-server-8.0.0
    ├── reset-admin.sh
    ├── runtime
    ├── seafile
    ├── seafile.sh
    ├── seahub
    ├── seahub.sh
    ├── setup-seafile-mysql.sh
    └── upgrade

这样设计目录的好处在于

安装 Seafile 专业版本服务器

安装前的准备工作

安装 Seafile 服务器之前,请确认已安装以下软件:

Seafile Pro 8.0.x 版本

# on Debian 10/Ubuntu 18.04/Ubuntu 20.04
apt-get update
apt-get install python3 python3-setuptools python3-pip python3-ldap  libmysqlclient-dev  -y
pip3 install --timeout=3600 django==2.2.* future mysqlclient pymysql Pillow pylibmc \ 
captcha jinja2 sqlalchemy==1.4.3 psd-tools django-pylibmc django-simple-captcha
# on CentOS 8
yum install python3 python3-setuptools python3-pip python3-ldap python3-devel mysql-devel gcc gcc-c++ -y
pip3 install --timeout=3600 django==2.2.* future mysqlclient pymysql Pillow pylibmc \ 
captcha jinja2 sqlalchemy==1.4.3 psd-tools django-pylibmc django-simple-captcha 

Seafile Pro 9.0.x 版本

# on Debian 10/Ubuntu 18.04/Ubuntu 20.04
apt-get update
apt-get install python3 python3-setuptools python3-pip python3-ldap libmysqlclient-dev -y
pip3 install --timeout=3600 django==3.2.* future mysqlclient pymysql Pillow pylibmc \ 
captcha jinja2 sqlalchemy==1.4.3 psd-tools django-pylibmc django-simple-captcha \
pycryptodome==3.12.0 cffi==1.14.0 lxml
注意:Seafile Pro 9.0.x 版本不支持在 Centos 系统 tar 包部署,支持 Docker 方式部署 

Seafile Pro 10.0.x 版本

# Ubuntu 22.04 (almost the same for Ubuntu 20.04 and Debian 11, Debian 10)
sudo apt-get update
sudo apt-get install -y python3 python3-setuptools python3-pip libmysqlclient-dev
sudo apt-get install -y memcached libmemcached-dev
sudo pip3 install --timeout=3600 django==3.2.* future==0.18.* mysqlclient==2.1.* \
    pymysql pillow==9.3.* pylibmc captcha==0.4 markupsafe==2.0.1 jinja2 sqlalchemy==1.4.3 \
    psd-tools django-pylibmc django_simple_captcha==0.5.* djangosaml2==1.5.* pysaml2==7.2.* pycryptodome==3.16.* cffi==1.15.1 lxml

Seafile Pro 11.0.x 版本

# Ubuntu 22.04 (almost the same for Ubuntu 20.04 and Debian 11, Debian 10)
sudo apt-get update
sudo apt-get install -y python3 python3-setuptools python3-pip libmysqlclient-dev   ldap-utils libldap2-dev
sudo apt-get install -y memcached libmemcached-dev
sudo pip3 install --timeout=3600 django==3.2.* future==0.18.* mysqlclient==2.1.* pymysql pillow==10.0.* pylibmc captcha==0.4 markupsafe==2.0.1 jinja2 sqlalchemy==2.0.18 psd-tools django-pylibmc django_simple_captcha==0.5.* djangosaml2==1.5.* pysaml2==7.2.* pycryptodome==3.16.* cffi==1.15.1 python-ldap==3.4.3 lxml

安装

cd seafile-pro-server-*
./setup-seafile-mysql.sh  #运行安装脚本并回答预设问题

如果你的系统中没有安装上面的某个软件,那么 Seafile初始化脚本会提醒你安装相应的软件包.

该脚本会依次询问你一些问题,从而一步步引导你配置 Seafile 的各项参数:

在这里, 你会被要求选择一种创建 Seafile 数据库的方式:

-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------
[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases

如果安装正确完成,你会看到成功的消息。这个时候你的目录结构如下:

#tree seafile -L 2
seafile
├── conf
│   └── ccnet.conf
│   └── seafile.conf
│   └── seahub_settings.py
│   └── gunicorn.conf
├── installed
│   └── seafile-pro-server_8.0.0_x86-64.tar.gz
├── seafile-data
├── seafile-pro-server-8.0.0  # active version
│   ├── reset-admin.sh
│   ├── runtime
│   ├── seafile
│   ├── seafile.sh
│   ├── seahub
│   ├── seahub.sh
│   ├── setup-seafile-mysql.sh
│   └── upgrade
├── seafile-server-latest  # symbolic link to seafile-server-8.0.0
├── seahub-data
│   └── avatars

seafile-server-latest文件夹为指向当前 Seafile 服务器文件夹的符号链接。 将来你升级到新版本后, 升级脚本会自动更新使其始终指向最新的 Seafile 服务器文件夹。

配置 Memcached

安装 Memcached 软件

# on Debian/Ubuntu 18.04/Ubuntu 20.04
apt-get install memcached libmemcached-dev -y
pip3 install --timeout=3600 pylibmc django-pylibmc
systemctl enable --now memcached

将以下配置添加到 seahub_settings.py 中:

CACHES = {
    'default': {
        'BACKEND': 'django_pylibmc.memcached.PyLibMCCache',
        'LOCATION': '127.0.0.1:11211',
    },
}

配置 seaf-server 的 memcached (专业版的额外步骤)

在 seafile.conf 文件中增加以下配置

[memcached]
memcached_options = --SERVER=<the IP of Memcached Server> --POOL-MIN=10 --POOL-MAX=100

配置 Nginx

请先确保你的系统中安装了 Nginx。在 Ubuntu 下,你可以通过以下命令来安装

# Debian/Ubuntu
$ sudo apt install nginx -y

然后我们添加 Nginx 的配置文件。Ubuntu 下请按照以下步骤添加

  1. 创建文件 /etc/nginx/site-available/seafile.conf,并拷贝以下内容

  2. 删除/etc/nginx/site-enabled/default: rm /etc/nginx/site-enabled/default

  3. 创建符号链接: ln -s /etc/nginx/sites-available/seafile.conf /etc/nginx/sites-enabled/seafile.conf

server {
    listen 80;
    server_name seafile.example.com;
    proxy_set_header X-Forwarded-For $remote_addr;
    location / {
         proxy_pass         http://127.0.0.1:8000;
         proxy_set_header   Host $http_host;
         proxy_set_header   X-Real-IP $remote_addr;
         proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header   X-Forwarded-Host $server_name;
         proxy_read_timeout  1200s;
         # used for view/edit office file via Office Online Server
         client_max_body_size 0;
         access_log      /var/log/nginx/seahub.access.log;
         error_log       /var/log/nginx/seahub.error.log;
    }
    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        client_max_body_size 0;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_connect_timeout  36000s;
        proxy_read_timeout  36000s;
        proxy_send_timeout  36000s;
        send_timeout  36000s;
    }
    location /media {
        root /opt/seafile/seafile-server-latest/seahub;
    }
}

Nginx 默认设置 "client_max_body_size" 为 1M。如果上传文件大于这个值的话,会报错,相关 HTTP 状态码为 423 ("Request Entity Too Large"). 你可以将值设为 0 以禁用此功能.

如果要上传大于 4GB 的文件,默认情况下 Nginx 会把整个文件存在一个临时文件中,然后发给上游服务器 (seaf-server),这样容易出错。使用 1.8.0 以上版本同时在 Nginx 配置文件中设置以下内容能解决这个问题:

    location /seafhttp {
        ... ...
        proxy_request_buffering off;
    }

修改 Seafile 配置文件

下面还需要更新 SERVICE_URL 和 FILE_SERVER_ROOT 这两个配置项。否则无法通过 Web 正常的上传和下载文件。

您可以直接通过管理员 Web 界面来设置这两个值 (注意,如果同时在 Web 界面和配置文件中设置了这个值,以 Web 界面的配置为准。):

SERVICE_URL: http://www.myseafile.com
FILE_SERVER_ROOT: http://www.myseafile.com/seafhttp

或者修改seahub_settings.py 文件

修改 seahub_settings.py

(这是一个 python 文件,注意引号)

SERVICE_URL = 'http://www.myseafile.com'
FILE_SERVER_ROOT = 'http://www.myseafile.com/seafhttp'

启动 Seafile 服务

在 seafile-server-latest 目录下,运行如下命令

 ./seafile.sh start # 启动 Seafile 服务  
 ./seahub.sh start  # 启动 Seahub 网站 (默认运行在127.0.0.1:8000端口上)

你第一次启动 seahub 时,seahub.sh 脚本会提示你创建一个 seafile 管理员帐号。

恭喜!​ 现在你已经成功的安装了 Seafile 服务器。你可以通过 80 端口来访问 Seafile 服务了。

启用 HTTPS

请参考文档 Nginx 下启用 Https

添加许可证书

您申请到证书后,有两种方式添加许可证书

  1. 在浏览器上,用管理员账号登录, 点击系统管理->信息->许可证上传

  2. 把证书拷贝到 Seafile 服务器指定的目录,命令如下

mv seafile-license.txt  /opt/seafile  
##重启 Seafile 使许可证书生效
./seafile.sh start     # 启动 Seafile 服务 
./seahub.sh start      # 启动 Seahub 网站

对接索引服务

ElasticSearch 程序部署

本案例是用 Docker 部署 ElasticSearch 程序为例,所以需要您提前在服务器上提前部署好 Docker,并且启动(Docker 安装这里不介绍)

## 拉取 ElasticSearch 镜像
docker pull elasticsearch:7.16.2
## 创建 ElasticSearch 数据映射本目录,并给目录权限
mkdir -p /opt/seafile-elasticsearch/data  && chmod -R 777 /opt/seafile-elasticsearch/data/
## 启动 Elasticsearch 容器
sudo docker run -d \
--name es \
-p 9200:9200 \
-e "discovery.type=single-node" -e "bootstrap.memory_lock=true" \
-e "ES_JAVA_OPTS=-Xms1g -Xmx1g" -e "xpack.security.enabled=false" \
--restart=always \
-v /opt/seafile-elasticsearch/data:/usr/share/elasticsearch/data \
-d elasticsearch:7.16.2

注意:seafile Pro 9.0.x 只支持 ElasticSearch 7.x 版本,最好使用 7.16.2 及以上版本,7.16.2 之前版本有漏洞。

ElasticSearch 对接 Seafile 配置

在 seafile 程序的 seafevents.conf 配置文件里 [INDEX FILES] 字段下添加

[INDEX FILES]
external_es_server = true
es_host = your elasticsearch server's IP     ## ElasticSearch 服务器ip或者域名
es_port = 9200                               ## ElasticSearch 容器映射端口

重启 Seafile 程序,使配置文件生效

./seafile.sh restart  && ./seahub.sh restart 

关闭/重启 Seafile 和 Seahub

关闭

./seahub.sh stop      # 停止 Seahub
./seafile.sh stop     # 停止 Seafile 进程

重启

./seafile.sh restart # 停止当前的 Seafile 进程,然后重启 Seafile
./seahub.sh restart  # 停止当前的 Seahub 进程,并在 8000 端口重新启动 Seahub

Last modified by Daniel Pan, 2024-03-20

下载安装包和申请试用许可证书
部署和目录设计
安装 Seafile 专业版本服务器
安装前的准备工作
安装
配置 Memcached
配置 Nginx
修改 Seafile 配置文件
修改 seahub_settings.py
启动 Seafile 服务
启用 HTTPS
添加许可证书
对接索引服务
关闭/重启 Seafile 和 Seahub
关闭
重启