Notification Server

目前,客户端和 Web 界面上的文件和资料库的状态更新是基于 轮询服务器 的。由于轮询存在延迟,客户端无法实时反映最新状态。客户端需要定期刷新资料库的修改、文件锁定、子目录权限等信息,这会给服务器带来额外的性能开销。
在 Web 界面中打开目录时,文件的锁定状态无法实时更新,需要刷新页面。
Notification Server 使用 WebSocket 协议 ,与客户端或 Web 界面保持双向通信连接。当上述变化发生时, seaf-server 会通知通知服务器,再由通知服务器实时通知客户端或 Web 界面。这样不仅提高了实时性,还减少了服务器的性能开销。
支持的更新提醒类型
  1. 资料库已更新
  2. 资料库下的文件锁状态发生变化
  3. 资料库下的目录权限发生变化
如何配置运行
Seafile 12.0 开始,通知服务器通过单独的 Docker 镜像部署。
seafile 13.0:
首先下载 notification-server.yml 到 Seafile 目录:
            
                
                
wget https://manual.seafile.com/13.0/repo/docker/notification-server.yml
修改 .env 文件,将 notification-server.yml 加入 COMPOSE_FILE
            
                
                
COMPOSE_FILE='seafile-server.yml,caddy.yml,notification-server.yml'
然后添加或修改以下配置:
            
                
                
ENABLE_NOTIFICATION_SERVER=true
最后运行 Notification Server
            
                
                
docker compose down
docker compose up -d
seafile 12.0:
首先下载 notification-server.yml 到 Seafile 目录:
            
                
                
wget https://manual.seafile.com/12.0/repo/docker/notification-server.yml
修改 .env 文件,将 notification-server.yml 加入 COMPOSE_FILE
            
                
                
COMPOSE_FILE='seafile-server.yml,caddy.yml,notification-server.yml'
seafile.conf 中添加以下配置:
            
                
                
[notification]
enabled = true
# the ip of notification server. (default is `notification-server` in Docker)
host = notification-server
# the port of notification server
port = 8083
最后运行 Notification Server
            
                
                
docker compose down
docker compose up -d
检查 notification 服务运行状态
Notification Server 正在运行时,你可以浏览器访问 http://127.0.0.1:8083/ping ,它将返回 {"ret" : "pong"} 。如果你配置了反向代理,可以浏览器访问 https://{server}/notification/ping
兼容的客户端
  1. Seadrive 3.0.1 或更高版本
  2. Seafile 客户端 8.0.11 或更高版本
如果客户端成功连接通知服务器,在 seafile.log seadrive.log 中会有如下日志:
            
                
                
Notification server is enabled on the remote server xxxx
Seafile 集群使用 Notification Server
Notification Server 企业版 中没有额外功能,与社区版工作方式相同。
如果启用了集群,需要在其中一台服务器或单独的服务器上部署通知服务器,并配置负载均衡器将 WebSocket 请求 转发到该节点。
13.0:
下载 .env notification-server.yml
            
                
                
wget https://manual.seafile.com/13.0/repo/docker/notification-server/notification-server.yml
wget -O .env https://manual.seafile.com/13.0/repo/docker/notification-server/env
然后根据环境修改 .env 文件,需要修改的字段:
变量名
描述
SEAFILE_MYSQL_DB_HOST
Seafile MySQL 主机
SEAFILE_MYSQL_DB_USER
Seafile MySQL 用户,默认为 seafile
SEAFILE_MYSQL_DB_PASSWORD
Seafile MySQL 密码
TIME_ZONE
时区
JWT_PRIVATE_KEY
JWT 密钥,与 Seafile .env 中保持一致
SEAFILE_SERVER_HOSTNAME
Seafile 主机名
SEAFILE_SERVER_PROTOCOL
http 或 https
启动 notification 服务:
            
                
                
docker compose up -d
然后修改部署 Seafile 的主机 .env 文件:
            
                
                
ENABLE_NOTIFICATION_SERVER=true
NOTIFICATION_SERVER_URL=https://seafile.example.com/notification
INNER_NOTIFICATION_SERVER_URL=http://<your notification server host>:8083
12.0:
下载 .env notification-server.yml
            
                
                
wget https://manual.seafile.com/12.0/repo/docker/notification-server/standalone/notification-server.yml
wget -O .env https://manual.seafile.com/12.0/repo/docker/notification-server/standalone/env
然后根据环境修改 .env 文件,需要修改的字段:
变量
说明
NOTIFICATION_SERVER_VOLUME
通知服务器数据的卷目录
SEAFILE_MYSQL_DB_HOST
Seafile 的 MySQL 主机地址
SEAFILE_MYSQL_DB_USER
Seafile 的 MySQL 用户名,默认为 seafile
SEAFILE_MYSQL_DB_PASSWORD
Seafile 的 MySQL 密码
TIME_ZONE
时区
JWT_PRIVATE_KEY
JWT 私钥,与 Seafile .env 文件中的配置保持一致
SEAFILE_SERVER_HOSTNAME
Seafile 服务器主机名
SEAFILE_SERVER_PROTOCOL
使用的协议,http 或 https
启动 notification 服务:
            
                
                
docker compose up -d
然后修改部署 Seafile 的主机的 seafile.conf 文件:
            
                
                
[notification]
enabled = true
# the ip of notification server.
host = 192.168.0.83
# the port of notification server
port = 8083
你需要根据以下转发规则配置负载均衡器:
  1. /notification/ping 请求通过 HTTP 协议 转发到通知服务器
  2. 将 URL 前缀为 /notification WebSocket 请求 转发到通知服务器
以下是 haproxy 的配置示例(需要 haproxy 版本 >= 2.0)。其他负载均衡器配置方式类似:
            
                
                
#/etc/haproxy/haproxy.cfg

# 其他已有 haproxy 配置
......

frontend seafile
     bind 0.0.0.0:80
     mode http
     option httplog
     option dontlognull
     option forwardfor
     acl notif_ping_request url_sub -i /notification/ping
     acl ws_requests url -i /notification
     acl hdr_connection_upgrade hdr(Connection) -i upgrade
     acl hdr_upgrade_websocket hdr(Upgrade) -i websocket
     use_backend ws_backend if hdr_connection_upgrade hdr_upgrade_websocket
     use_backend notif_ping_backend if notif_ping_request
     use_backend ws_backend if ws_requests
     default_backend backup_nodes

backend backup_nodes
     cookie SERVERID insert indirect nocache
     server seafileserver01 192.168.0.137:80

backend notif_ping_backend
     option forwardfor
     server ws 192.168.0.137:8083

backend ws_backend
     option forwardfor # 设置 X-Forwarded-For
     server ws 192.168.0.137:8083