Syncronize and share files in the cloud with Seafile

Seafile is a synchronization and file sharing solution, designed to provide high reliability, performance and productivity. With Seafile you can sync, share and collaborate between teams using different devices. The core of the Seafile server is written in C programming language, is small and has excellent performance. The web interface is developed in Python/Django and allows to manage (add, share, delete) your files in the cloud, it is also possible to install a client/drive which makes it easy to handle your files from the comfort of your device.

Download

At time of writing this, the last available version is: 9.0.10, check the download section for the last available version.

$ wget https://s3.eu-central-1.amazonaws.com/download.seadrive.org/seafile-server_9.0.10_x86-64.tar.gz

Create seafile DIR under /opt DIR

$ sudo mkdir /opt/seafile

Move the downloaded file to /opt/seafile

$ sudo mv seafile-server_* /opt/seafile

Move to /opt/seafile

$ cd /opt/seafile

Untar

$ sudo tar -xzf seafile-server_*

Create installed DIR

$ sudo mkdir installed

Move the tar.gz to installed DIR

$ sudo mv seafile-server_* installed/

Create the databases

Seafile use MySQL or MariaDB as database backend check this guides to install one of them in your server:

CREATE DATABASE `ccnet_db` CHARACTER SET = 'utf8';
CREATE DATABASE `seafile_db` CHARACTER SET = 'utf8';
CREATE DATABASE `seahub_db` CHARACTER SET = 'utf8';

Create seafile database user

Check MySQL user administration for more information on this topic.

CREATE USER 'seafile'@'localhost' IDENTIFIED BY 'contraseña';
GRANT ALL PRIVILEGES ON `ccnet_db`.* to `seafile`@localhost;
GRANT ALL PRIVILEGES ON `seafile_db`.* to `seafile`@localhost;
GRANT ALL PRIVILEGES ON `seahub_db`.* to `seafile`@localhost;
FLUSH PRIVILEGES;

Change authentication method for seafile user

If you are having problems connecting to the DB it is likely that you have to change the MySQL authentication method, you can have more details at MySQL 8.0, change root password

ALTER USER seafile@localhost IDENTIFIED WITH mysql_native_password BY 'contraseña';
FLUSH PRIVILEGES;

Install Python tools

$ sudo apt-get install python3 python3-setuptools python3-pip libmysqlclient-dev -y
$ sudo pip3 install --timeout=3600 Pillow pylibmc captcha jinja2 sqlalchemy \
    django-pylibmc django-simple-captcha python3-ldap mysqlclient

Environment variables

Put this configuration on /etc/environment

LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
export LC_ALL LANG LANGUAGE

and do:

$ source /etc/environment

In case you get an error like this:

/bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

check the solution on stackoverflow

Install

Seafile developers provide us with a setup-seafile-mysql.sh utility that allows us to perform the installation process in a simple and comfortable way.

$ sudo ./setup-seafile-mysql.sh 
Checking python on this machine ...

-----------------------------------------------------------------
This script will guide you to setup your seafile server using MySQL.
Make sure you have read seafile server manual at

        https://download.seafile.com/published/seafile-manual/home.md

Press ENTER to continue
-----------------------------------------------------------------

What is the name of the server? It will be displayed on the client.
3 - 15 letters or digits
[ server name ] seafile

What is the ip or domain of the server?
For example: www.mycompany.com, 192.168.1.101
[ This server's ip or domain ] seafile.mydomain.local

Which port do you want to use for the seafile fileserver?
[ default "8082" ] 

-------------------------------------------------------
Please choose a way to initialize seafile databases:
-------------------------------------------------------

[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases

[ 1 or 2 ] 2

What is the host of mysql server?
[ default "localhost" ] 

What is the port of mysql server?
[ default "3306" ] 

Which mysql user to use for seafile?
[ mysql user for seafile ] seafile

What is the password for mysql user "seafile"?
[ password for seafile ] 

verifying password of user seafile ...  done

Enter the existing database name for ccnet:
[ ccnet database ] ccnet_db

verifying user "seafile" access to database ccnet_db ...  done

Enter the existing database name for seafile:
[ seafile database ] seafile_db

verifying user "seafile" access to database seafile_db ...  done

Enter the existing database name for seahub:
[ seahub database ] seahub_db

verifying user "seafile" access to database seahub_db ...  done

---------------------------------
This is your configuration
---------------------------------

    server name:            seafile
    server ip/domain:       seafile.mydomain.local

    seafile data dir:       /opt/seafile/seafile-data
    fileserver port:        8082

    database:               use existing
    ccnet database:         ccnet_db
    seafile database:       seafile_db
    seahub database:        seahub_db
    database user:          seafile



---------------------------------
Press ENTER to continue, or Ctrl-C to abort
---------------------------------
Generating ccnet configuration ...

Generating seafile configuration ...

done
Generating seahub configuration ...

----------------------------------------
Now creating ccnet database tables ...

----------------------------------------
----------------------------------------
Now creating seafile database tables ...

----------------------------------------
----------------------------------------
Now creating seahub database tables ...

----------------------------------------

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




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

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

-----------------------------------------------------------------
If you are behind a firewall, remember to allow input/output of these tcp ports:
-----------------------------------------------------------------

port of seafile fileserver:   8082
port of seahub:               8000

When problems occur, Refer to

        https://download.seafile.com/published/seafile-manual/home.md

for information.

Directory structure

Once the Seafile is installed we must have a directory structure like the one shown below:

$ sudo tree -dL 3 /opt/seafile/
/opt/seafile/
├── ccnet
├── conf
├── seafile-data
│   └── library-template
├── seafile-server-9.0.10
│   ├── runtime
│   ├── seafile
│   │   ├── bin
│   │   ├── docs
│   │   ├── include
│   │   └── lib
│   ├── seahub
│   │   ├── bin
│   │   ├── fabfile
│   │   ├── frontend
│   │   ├── locale
│   │   ├── media
│   │   ├── scripts
│   │   ├── seahub
│   │   ├── sql
│   │   ├── static
│   │   ├── tests
│   │   ├── thirdpart
│   │   └── tools
│   ├── sql
│   │   ├── mysql
│   │   └── sqlite
│   └── upgrade
│       └── sql
├── seafile-server-latest -> seafile-server-9.0.10
└── seahub-data
    └── avatars
        └── groups

Configurations

You can find the configuration under

$ sudo tree /opt/seafile/conf
/opt/seafile/conf
├── ccnet.conf
├── gunicorn.conf.py
├── __pycache__
│   ├── gunicorn.conf.cpython-39.pyc
│   └── seahub_settings.cpython-39.pyc
├── seafdav.conf
├── seafile.conf
└── seahub_settings.py

Start the services

Start the file server

$ sudo ./seafile.sh start

Starting seafile server, please wait ...
** Message: 22:08:49.496: seafile-controller.c(621): No seafevents.

Seafile server started

Done.

Start the frontend/web admin

Pay special attention to the mail and password you are requested because they are the credentials of the administrator user and with which you will authenticate in the web interface.

sudo ./seahub.sh start

Starting seahub at port 8000 ...

----------------------------------------
It's the first time you start the seafile server. Now let's create the admin account
----------------------------------------

What is the email for the admin account?
[ admin email ] admin@myemail.com

What is the password for the admin account?
[ admin password ] 

Enter the password again:
[ admin password again ] 



----------------------------------------
Successfully created seafile admin
----------------------------------------




Seahub is started

Done.

If you have any issue starting seahub sevice execute to find out it:

$ sudo ./seahub.sh start-fastcgi
Starting seahub (fastcgi) at 127.0.0.1:8000 ...
Traceback (most recent call last)
...

Reset user admin

$ sudo ./reset-admin.sh

Map the web admin to non default IP and Port

By default the web interface is only accessible via 127.0.0.1:8000 you can change this behavior by editing the /opt/seafile/conf/gunicorn.conf.py file and modifying the bind directive.

# default 127.0.0.1:8000
bind = "IP:Puerto"

Restart the seahub service

$ sudo ./seahub.sh restart

You can now access the Seafile by putting in your browser http://IP:Puerto.

Note that exposing that exposing the Gunicorn service impply some security risk so it is a good practice to put it behind a reverse proxy like nginx.

Install Memcache

If you have more than 50 users install Memcached which will increase the performance of the web interface.

$ sudo apt-get install memcached libmemcached-dev -y && \
sudo pip3 install --timeout=3600 pylibmc django-pylibmc

Start Memcache with the OS

$ sudo systemctl enable --now memcached

Using Memcache

Add the following lines to seahub_settings.py

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

Using systemd

Stopping the services

$ sudo ./seahub.sh stop 
$ sudo ./seafile.sh stop

Create seafile user and group

$ sudo  adduser --system --group --HOME /opt/seafile --shell /usr/sbin/nologin --no-create-home seafile
Adding system user `seafile' (UID 108) ...
Adding new group `seafile' (GID 114) ...
Adding new user `seafile' (UID 108) with group `seafile' ...
Not creating home directory `/opt/seafile'.

Change the owner for seafile data

$ sudo chown -Rc seafile:seafile /opt/seafile/{seafile,seahub}-data
changed ownership of '/opt/seafile/seafile-data/httptemp/cluster-shared' from root:root to seafile:seafile
changed ownership of '/opt/seafile/seafile-data/httptemp' from root:root to seafile:seafile
changed ownership of '/opt/seafile/seafile-data/tmpfiles' from root:root to seafile:seafile
...
changed ownership of '/opt/seafile/seahub-data/avatars/default.png' from root:root to seafile:seafile
changed ownership of '/opt/seafile/seahub-data/avatars' from root:root to seafile:seafile
changed ownership of '/opt/seafile/seahub-data' from root:root to seafile:seafile

Change the group owner of conf DIR

$ sudo chown :seafile -Rc /opt/seafile/conf/
changed ownership of '/opt/seafile/conf/seafile.conf' from root:root to :seafile
changed ownership of '/opt/seafile/conf/seahub_settings.py' from root:root to :seafile
changed ownership of '/opt/seafile/conf/seafdav.conf' from root:root to :seafile
...

We allow the group to access the configuration directory:

$ sudo chmod g=rx -c /opt/seafile/conf/
mode of '/opt/seafile/conf/' changed from 0700 (rwx------) to 0750 (rwxr-x---)

We give write permission to the cache dir:

$ sudo chmod g=rwx -c /opt/seafile/conf/__pycache__
mode of '/opt/seafile/conf/__pycache__' changed from 0755 (rwxr-xr-x) to 0775 (rwxrwxr-x)

Change the owner of DIR logs

$ sudo chown seafile:seafile -Rc /opt/seafile/logs/
changed ownership of '/opt/seafile/logs/onlyoffice.log' from root:root to seafile:seafile
changed ownership of '/opt/seafile/logs/controller.log' from root:root to seafile:seafile
...

Change the owner of DIR pids

$ sudo chown seafile:seafile -Rc /opt/seafile/pids
changed ownership of '/opt/seafile/pids/seahub.pid' from root:root to seafile:seafile
changed ownership of '/opt/seafile/pids/seaf-server.pid' from root:root to seafile:seafile
changed ownership of '/opt/seafile/pids' from root:root to seafile:seafile

Change seahub_settings.py permissions

With the following command we allow the seahub to access its configuration file.

$ sudo chmod g+r -c /opt/seafile/conf/seahub_settings.py
mode of '/opt/seafile/conf/seahub_settings.py' changed from 0700 (rwx------) to 0740 (rwxr-----)

Allow the RPC server to access socket files

The RPC server uses sockets file components communication, the following error tells us that we should change the permissions settings.

socket file exists, delete it anyway
delete socket file failed : Permission denied

Now we change the owner:

$ sudo chown seafile:seafile -Rc /opt/seafile/seafile-server-latest/runtime/
changed ownership of '/opt/seafile/seafile-server-latest/runtime/seahub.conf' from root:root to seafile:seafile
changed ownership of '/opt/seafile/seafile-server-latest/runtime/seafile.sock' from root:root to seafile:seafile
changed ownership of '/opt/seafile/seafile-server-latest/runtime/' from root:root to seafile:seafile

Create system units

With the following command we create a seafile system unit

$ sudo systemctl edit --force --full seafile

and add

[Unit]
Description=Seafile Cloud Storage
After=network.target mysql.service

[Service]
Type=forking
ExecStart=/opt/seafile/seafile-server-latest/seafile.sh start
ExecStop=/opt/seafile/seafile-server-latest/seafile.sh stop
User=seafile
Group=seafile

[Install]
WantedBy=multi-user.target

Create a seahub system unit

$ sudo systemctl edit --force --full seahub

and add

[Unit]
Description=Seafile Web System Administration (Seahub) 
After=network.target seafile.service

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

[Install]
WantedBy=multi-user.target

seafile service

Start

sudo systemctl start seafile

Check the status

$ sudo systemctl status seafile
● seafile.service - Seafile Cloud Storage
     Loaded: loaded (/etc/systemd/system/seafile.service; disabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-02-16 23:20:20 UTC; 20s ago
    Process: 1605 ExecStart=/opt/seafile/seafile-server-latest/seafile.sh start (code=exited, status=0/SUCCESS)
      Tasks: 18 (limit: 1129)
     Memory: 7.0M
        CPU: 61ms
     CGroup: /system.slice/seafile.service
             ├─1625 /opt/seafile/seafile-server-9.0.10/seafile/bin/seafile-controller -c /opt/seafile/ccnet -d /opt/seafile/seafile-data -F /opt/seafile/conf
             └─1627 seaf-server -F /opt/seafile/conf -c /opt/seafile/ccnet -d /opt/seafile/seafile-data -l /opt/seafile/logs/seafile.log -P /opt/seafile/pids/seaf-server.pid -p /opt/seafile/>

Feb 16 23:20:17 bullseye systemd[1]: Starting Seafile Cloud Storage...
Feb 16 23:20:17 bullseye seafile.sh[1605]: Starting seafile server, please wait ...
Feb 16 23:20:17 bullseye seafile-control[1623]: seafile-controller.c(621): No seafevents.
Feb 16 23:20:20 bullseye seafile.sh[1605]: Seafile server started
Feb 16 23:20:20 bullseye seafile.sh[1605]: Done.
Feb 16 23:20:20 bullseye systemd[1]: Started Seafile Cloud Storage.

Start with the OS

$ sudo systemctl enable seafile
Created symlink /etc/systemd/system/multi-user.target.wants/seafile.service → /etc/systemd/system/seafile.service.

Seahub service

Start

$ sudo systemctl start seahub

Check the status

$ sudo systemctl status seahub
● seahub.service - Seafile Web System Administration (Seahub)
     Loaded: loaded (/etc/systemd/system/seahub.service; disabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-02-16 23:24:42 UTC; 37s ago
    Process: 1706 ExecStart=/opt/seafile/seafile-server-latest/seahub.sh start (code=exited, status=0/SUCCESS)
   Main PID: 1720 (python3)
      Tasks: 6 (limit: 1129)
     Memory: 63.9M
        CPU: 581ms
     CGroup: /system.slice/seahub.service
             ├─1720 python3 /opt/seafile/seafile-server-9.0.10/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload
             ├─1721 python3 /opt/seafile/seafile-server-9.0.10/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload
             ├─1722 python3 /opt/seafile/seafile-server-9.0.10/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload
             ├─1723 python3 /opt/seafile/seafile-server-9.0.10/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload
             ├─1724 python3 /opt/seafile/seafile-server-9.0.10/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload
             └─1725 python3 /opt/seafile/seafile-server-9.0.10/seahub/thirdpart/bin/gunicorn seahub.wsgi:application -c /opt/seafile/conf/gunicorn.conf.py --preload

Feb 16 23:24:37 bullseye systemd[1]: Starting Seafile Web System Administration (Seahub)...
Feb 16 23:24:37 bullseye seahub.sh[1706]: LC_ALL is not set in ENV, set to en_US.UTF-8
Feb 16 23:24:37 bullseye seahub.sh[1706]: Starting seahub at port 8000 ...
Feb 16 23:24:42 bullseye seahub.sh[1706]: Seahub is started
Feb 16 23:24:42 bullseye seahub.sh[1706]: Done.
Feb 16 23:24:42 bullseye systemd[1]: Started Seafile Web System Administration (Seahub).

Start with the OS

$ sudo systemctl enable seahub
Created symlink /etc/systemd/system/multi-user.target.wants/seahub.service → /etc/systemd/system/seahub.service.

Setup NGINX as reverse proxy

Related topics

Create a virtual host and add the following settings, adjust server_name directives, proxy_pass according to your settings.

og_format seafileformat '$http_x_forwarded_for $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $upstream_response_time';
server {    
    listen 80;
    server_name seafile.mydomain.local;
    
    # Put here your SSL
    # listen 443 ssl http2;
    # include snippets/intefid-ssl.conf;
    
    # Max file size useful for file uploading 
    # 
    client_max_body_size 200M;

    proxy_set_header X-Forwarded-For $remote_addr;
    
    location / {
        # NGINX acting as reverse proxy
        #
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        #
        # Set the backend url and port, port is optional for standard services, the
        # $backend_port is defined as a map, see conf.d/mapper.conf also when there is
        # a variable as a part of proxy_pass URL a resolver is needed, 
        # see conf.d/resolver.conf
        #
        proxy_pass http://127.0.0.1:8000;
        
        access_log    /var/log/nginx/seahub.access.log seafileformat;
        error_log       /var/log/nginx/seahub.error.log;
    }

    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        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;

        access_log      /var/log/nginx/seafhttp.access.log seafileformat;
        error_log       /var/log/nginx/seafhttp.error.log;
    }
}

Now you can put in your browser: http://seafile.mydomain.local

Login


Library


YouTube video

Further readings:

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.