Merge branch 'socat-keepalive'

This commit is contained in:
Gerrit Gogel 2021-01-25 15:29:43 +01:00
commit 1cbb7909f1
5 changed files with 17 additions and 7 deletions

View file

@ -269,11 +269,11 @@ seafile-net:
``` ```
#### Reverse Proxy load balancing #### Reverse Proxy load balancing
If you want to run frontend replicas (clustering), you'll need to enable IP hash based load balancing. The load balancer, in this case *seafile-caddy*, will then create so called sticky sessions, which means that a client connecting with a certain IP will be forwarded to the same service for the time being. If you want to run frontend replicas (clustering), you'll need to enable dnsrr endpoint mode, which is needed for proper load balancing.
To enable IP hash based load balancing you have to configure the following options: To enable load balancing you have to configure the following options:
Set the endpoint mode for the frontend services to dnsrr. This will enable *seafile-caddy* to see the IPs of all replicas, instead the default virtual IP (VIP) created by the Swarm routing mesh. Set the endpoint mode for the frontend services *seahub* and *seahub-media* to dnsrr. This will enable *seafile-caddy* to see the IPs of all replicas, instead the default virtual IP (VIP) created by the Swarm routing mesh.
``` ```
deploy: deploy:
mode: replicated mode: replicated
@ -287,6 +287,14 @@ environment:
- SWARM_DNS=true - SWARM_DNS=true
``` ```
The load balancer, in this case *seafile-caddy*, will then create so called sticky sessions, which means that a client connecting with a certain IP will be forwarded to the same service for the time being. Hashing is based on the header `X-Forwarded-For`. This is better than client ip based hashing, when you have another reverse proxy in front of *seafile-caddy*, which is highly recommended. With client ip based hashing *seafile-caddy* would just forward everything to the same container, as it only sees the IP of the reverse proxy. Instead the X-Forwarder-For header contains the actual client IP.
It is also recommended to use dnsrr mode on the *seafile-server*, when you run multiple replicas of *seahub*. This will enable *seafile-server* to see the actual IPs of the *seahub* replicas when they connect to it, instead of a single virtual IP for all of them. This will circumvent probable IP:PORT overlaps in the TCP connection between *seahub* and *seafile-server* if you run many *seahub* replicas.
```
deploy:
endpoint_mode: dnsrr
```
#### Example #### Example
You can check out this example and use it as a starting point for you Docker Swarm deployment. It is using [lucaslorentz/caddy-docker-proxy](https://manual.seafile.com/docker/deploy%20seafile%20with%20docker/) as the external reverse proxy and the GlusterFS plugin from [marcelo-ochoa/docker-volume-plugins](https://github.com/marcelo-ochoa/docker-volume-plugins). This resembles my personal production setup. You can check out this example and use it as a starting point for you Docker Swarm deployment. It is using [lucaslorentz/caddy-docker-proxy](https://manual.seafile.com/docker/deploy%20seafile%20with%20docker/) as the external reverse proxy and the GlusterFS plugin from [marcelo-ochoa/docker-volume-plugins](https://github.com/marcelo-ochoa/docker-volume-plugins). This resembles my personal production setup.

View file

@ -17,6 +17,8 @@ services:
- memcached - memcached
networks: networks:
- seafile-net - seafile-net
deploy:
endpoint_mode: dnsrr
seahub: seahub:
image: ggogel/seahub:8.0.2 image: ggogel/seahub:8.0.2

View file

@ -4,7 +4,7 @@
http:// https:// { http:// https:// {
reverse_proxy seahub:8000 { reverse_proxy seahub:8000 {
lb_policy ip_hash lb_policy header X-Forwarded-For
} }
handle_path /seafhttp* { handle_path /seafhttp* {
uri strip_prefix seafhttp uri strip_prefix seafhttp
@ -12,6 +12,6 @@ http:// https:// {
} }
reverse_proxy /seafdav/* seafile-server:8080 reverse_proxy /seafdav/* seafile-server:8080
reverse_proxy /media/* seahub-media:80 { reverse_proxy /media/* seahub-media:80 {
lb_policy ip_hash lb_policy header X-Forwarded-For
} }
} }

View file

@ -9,4 +9,4 @@ while [ ! -S /opt/seafile/seafile-server-latest/runtime/seafile.sock ]; do
sleep 1 sleep 1
done done
socat -d -d TCP-LISTEN:8001,fork,reuseaddr UNIX:/opt/seafile/seafile-server-latest/runtime/seafile.sock,forever,keepalive socat -v -d -d -d -d TCP-LISTEN:8001,fork,reuseaddr UNIX:/opt/seafile/seafile-server-latest/runtime/seafile.sock,forever

View file

@ -3,7 +3,7 @@
/scripts/create_data_links.sh /scripts/create_data_links.sh
mkdir -p /opt/seafile/seafile-server-latest/runtime mkdir -p /opt/seafile/seafile-server-latest/runtime
socat -d -d UNIX-LISTEN:/opt/seafile/seafile-server-latest/runtime/seafile.sock,fork TCP:seafile-server:8001,forever,keepalive & socat -v -d -d -d -d UNIX-LISTEN:/opt/seafile/seafile-server-latest/runtime/seafile.sock,fork TCP:seafile-server:8001,forever,keepalive,keepidle=10,keepintvl=10,keepcnt=2 &
python3 /opt/seafile/seafile-server-latest/seahub/manage.py runserver 0.0.0.0:8000 python3 /opt/seafile/seafile-server-latest/seahub/manage.py runserver 0.0.0.0:8000