seafile

Seafile jest to apka "webowa", otwarto źródłowa przypominającona G-drive bądż One-Drive. Największą jej zaletą jest to, że sami jesteśmy panami i władcami własnych danych. Nikt nie będzie ich skanował, przeczesywał czy bóg wie co jeszcze z nimi robił. Ma jeszcze jedną fajną dodatkową zaletę, umożliwi szyfrowanie danych po stronie klienta, tuż przed wysłaniem. Nawet jeśli ktoś nam się wbije na serwer jakimś cudem to nic z nimi nie zrobi.

Gotową paczkę pobieramy z oficialnej strony www.seafile.com

Na chwię obecną mamy do pobranie trzy paczki:

  • 6.2.5 64bit
  • 6.2.5 32bit
  • 6.3.4 64bit

Różnice pomiędzy wersjami można znaleźć w logu zmian. Aczkolwiek im nowsza tym lepsza, mówi samo za siebie.

Na potrzebę tego artykułu przyjmiemy, że cała instalacja będzie odbywać się na Debian-ie 9. Wymagane są dwie paczki, które należy zainstalować aby spełnić wymagane zalerzności:

apt install python-imaging sqlite3

1. Instalacja

Dodajemy użytkownika za pomocą którego będziemy odpalać nasze deamony.

useradd -m -r -d /srv/seafile -s /usr/sbin/nologin seafile

Jak widać całą aplikacje oraz dane będziemy trzymać pod ścieżką /var/seafile. Przełączamy się na user-a seafile i pobieramy archiwum, a następnie rozpakowywujemy.

sudo -u seafile -s /bin/bash
SEAFILE_SERVER_VERSION=6.3.4
wget https://download.seadrive.org/seafile-server_$SEAFILE_SERVER_VERSION\_x86-64.tar.gz
tar -xvf seafile-server_$SEAFILE_SERVER_VERSION\_x86-64.tar.gz

Powinnismy otrzymać coś takiego:

seafile
  ├── seafile-server-6.3.4
  └── seafile-server_6.3.4_x86-64.tar.gz

Przechodzimy do katalogu seafile-server-6.3.4 i uruchamiamy skrypt instalacyjny. W zależności od wersji silinka bazdodanowego wybieramy odpowiednio:

  • setup-seafile.sh - SQLite
  • setup-seafile-mysql.sh - MySQL/MariaDB

Na potrzeby tego artukułu zainstalujemy wersję bazująza na bazie SQLite. .

seafile@debian:~/seafile-server-6.3.4$ ./setup-seafile.sh
-----------------------------------------------------------------
This script will guide you to config and setup your seafile server.

Make sure you have read seafile server manual at

    https://github.com/haiwen/seafile/wiki

Note: This script will guide your to setup seafile server using sqlite3,
which may have problems if your disk is on a NFS/CIFS/USB.
In these cases, we sugguest you setup seafile server using MySQL.

Press [ENTER] to continue
-----------------------------------------------------------------

Checking packages needed by seafile ...

Checking python on this machine ...
Find python: python2.7

  Checking python module: setuptools ... Done.
  Checking python module: python-imaging ... Done.
  Checking python module: python-sqlite3 ... Done.

Checking for sqlite3 ...Done.

Checking Done.

What would you like to use as the name of this seafile server?
Your seafile users will be able to see the name in their seafile client.
You can use a-z, A-Z, 0-9, _ and -, and the length should be 3 ~ 15
[server name]: Seafile

What is the ip or domain of this server?
For example, www.mycompany.com, or, 192.168.1.101

[This server's ip or domain]: example.pl

Where would you like to store your seafile data?
Note: Please use a volume with enough free space.
[default: /srv/seafile/seafile-data ]

What tcp port do you want to use for seafile fileserver?
8082 is the recommended port.
[default: 8082 ]

This is your config information:

server name:        Seafile
server ip/domain:   example.pl
seafile data dir:   /srv/seafile/seafile-data
fileserver port:    8082

If you are OK with the configuration, press [ENTER] to continue.

Generating ccnet configuration in /srv/seafile/ccnet...

done
Successly create configuration dir /srv/seafile/ccnet.

Generating seafile configuration in /srv/seafile/seafile-data ...

Done.

-----------------------------------------------------------------
Seahub is the web interface for seafile server.
Now let's setup seahub configuration. Press [ENTER] to continue
-----------------------------------------------------------------

Creating seahub database now, it may take one minute, please wait...

Done.

creating seafile-server-latest symbolic link ... done

-----------------------------------------------------------------
Your seafile server configuration has been completed successfully.
-----------------------------------------------------------------

run seafile server:     ./seafile.sh { start | stop | restart }
run seahub  server:     ./seahub.sh  { start <port> | stop | restart <port> }

-----------------------------------------------------------------
If the server is behind a firewall, remember to open these tcp ports:
-----------------------------------------------------------------

port of seafile fileserver:   8082
port of seahub:               8000

When problems occur, refer to

      https://github.com/haiwen/seafile/wiki

for more information.

Jak widać sama instalacja sprowadza się do podania kilku kluczowych elementów jak:

  • nazwa serwera.
  • adres IP bądź nazwę hosta.
  • ścieżka na serwerze gdzie będą nasze dane przechowywane.
  • oraz port na którym aplikacja będzie nasłuchiwać.

Pierwszy etap instalacji możemy uznać za ukończony. W ramach testu spróbujemy uruchomić aplikację.

cd ../seafile-server-latest
./seafile.sh start
./seahub.sh start

Podczas uruchamiania seahub zostanie utworzony użytkownik z uprawnieniami admina (nasze pierwsze konto), za pomocą którego będziemy się logować. Oczywiście te dane podajemy sami.

Odpalamy teraz przeglądarkę i wpisujemy adres IP bądź nazwę hosta, którą podawaliśmy podczas instalacji plus numer portu: 8000. W moim przypadku jest to: http://example.pl:8000 Po sprawdzeniu, czy wszystko jestk ok możemy przystąpic do dalszej części. Stopujemy naszą "apkę". Teraz struktura katalogu wygląda zgoła inaczej, mianowicie doszło parę nowych katalogów:

seafile
  ├── ccnet
  ├── conf
  ├── logs
  ├── pids
  ├── seafile-data
  ├── seafile-server-6.3.4
  ├── seafile-server_6.3.4_x86-64.tar.gz
  ├── seafile-server-latest -> seafile-server-6.3.4
  ├── seahub-data
  └── seahub.db

2. Nginx i chowanie się za SSL (a raczej TLS)

Jako że podstawowa instalacja nie zawiera łącznia się do serwisu z wykorzystaniem szyfrowanego połącznia, warto byłoby dodać taką możliwość. W obecnej formie wszystkie nasze dane wysyłane/pobierane są jawnym tekstem (w tym także nazwa użytkownika i hasło). Jakby było tego mało otwarte mamy dwa dodatkowe porty: 8000 oraz 8082. W domyślniej konfiguracji nasłuchują na wszystkich interfejsach sieciowych (poniżej).

Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:8082            0.0.0.0:*               LISTEN

Zaczniemy od "przestawienia" interfejsów tak aby nasłuchiwały na localhost-cie. Wszystkie pliki konfiguracyje do seafile znajdują się pod ścieżką: /srv/seafile/conf. Otwieramy plik gunicorn.conf i zmieniamy wpis z:

bind = "0.0.0.0:8000"
na
bind = "127.0.0.1:8000"

Bardzo podobną operacje wykonujemy na seafile.conf. Pod kategorią [fileserver] dodajemy wpis:

host=127.0.0.1

Teraz zajmiemy się instalacja web serwera, jakim jest Nginx. Jako root odpalamy komendę:

apt install nginx

Następnie przechodzimy pod ścieżkę, gdzie trzymana jest konfiguracja web serwera: /etc/nginx/sites-avaiable. Tworzymy plik o dowolnej nazwie, w którym to będzie przechowywana konfiguracja naszej chmurki. W moimi przypadku jest to seafile z podaną zawartością poniżej:

    server {
        listen 80;
        server_name  example.pl;
        rewrite ^ https://$http_host$request_uri? permanent;    # force redirect http to https
        server_tokens off;
    }
    server {
        listen 443;
        ssl on;
        ssl_certificate /etc/ssl/cacert.pem;        # path to your cacert.pem
        ssl_certificate_key /etc/ssl/privkey.pem;    # path to your privkey.pem
        server_name example.pl;
        ssl_session_timeout 5m;
        ssl_session_cache shared:SSL:5m;

        # Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
        ssl_dhparam /etc/nginx/dhparam.pem;

        # secure settings (A+ at SSL Labs ssltest at time of writing)
        # see https://wiki.mozilla.org/Security/Server_Side_TLS#Nginx
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-CAMELLIA256-SHA:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-SEED-SHA:DHE-RSA-CAMELLIA128-SHA:HIGH:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS';
        ssl_prefer_server_ciphers on;

        proxy_set_header X-Forwarded-For $remote_addr;

        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains";
        server_tokens off;

        location / {
            proxy_pass         http://127.0.0.1:8000;
            proxy_set_header   Host $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_set_header   X-Forwarded-Proto https;

            access_log      /var/log/nginx/seahub.access.log;
            error_log       /var/log/nginx/seahub.error.log;

            proxy_read_timeout  1200s;

            client_max_body_size 0;
        }

        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 /srv/seafile/seafile-server-latest/seahub;
        }
    }

Oczywiście musicie dostosować podaną konfigurację pod swoje ustawienie systemowe. Podać ares IP bądź domenę (wpis server_name example.pl), ścieżkę do certifikatu i klucza prywatnego (ssl_certificate oraz ssl_certificate_key) jaki i parametru DH (wpis ssl_dhparam). Reszta powinna być ok, jeżeli robiliście według tego poradnika. Dokładnej analizy konfiguracji nie będę robił, jako że znajdziecie je tutaj i po części tutaj Po zapisaniu zmian należy jeszcze poinformować naszego Nginx-a aby zaczytał w/w konfigurację. Mianowice tworzymy symlinka:

root@debian:/etc/nginx/sites-enable# ln -s ../sites-avaiable/seafile seafile

3. Dostosowanie Seafile pod ustawienia Nginx-a

jako że wymusiliśmy na nasze aplikacji używanie bezpiecznego protokołu HTTPS, musimy dostosować konfigurację Seafile. W pliku ccnet.conf zmieniamy wartość zmiennej SERVICE_URL tak aby URL zaczynał się od HTTPS\:

SERVICE_URL = https://example.pl

Bardzo podobna zmiana dotyczy pliku seahub_settings.py. Analogicznie zmieniamy zmienna FILE_SERVER_ROOT

FILE_SERVER_ROOT = 'https://example.pl/seafhttp'

4. Autmoatyczny start w trakcie uruchaminia/restartu serwera.

Tworzymy dwa pliki typu service. Pierwszy:

sudo nano /etc/systemd/system/seafile.service

Zawartość tego pliku powinna zawierać:

[Unit]
Description=Seafile
After=network.target

[Service]
Type=forking
ExecStart=${seafile_dir}/seafile-server-latest/seafile.sh start
ExecStop=${seafile_dir}/seafile-server-latest/seafile.sh stop
User=seafile
Group=seafile

[Install]
WantedBy=multi-user.target

Drugi:

sudo nano /etc/systemd/system/seahub.service

Plus zawartość:

[Unit]
Description=Seafile hub
After=network.target seafile.service

[Service]
Type=forking
ExecStart=${seafile_dir}/seafile-server-latest/seahub.sh start
ExecStop=${seafile_dir}/seafile-server-latest/seahub.sh stop
User=seafile
Group=seafile

[Install]
WantedBy=multi-user.target

Mając tak przygotowana konfigurację odpalamy wszystko po kolei, a następnie włączamy autostart:

systemctl start seafile.service
systemctl start seahub.service
systemctl start nginx.service

systemctl enable seafile.service
systemctl enable seahub.service
systemctl enable nginx.service

Next Post