How to install Seafile on CentOS 7

Seafile on CentOS 7

Introduction

Seafile is a private file hosting platform, similar to Dropbox, Google Drive, OneDrive and Mega. Its parts are released under open source licenses, in particular:

  • Seafile iOS client: Apache License v2
  • Seafile Android client: GPLv3
  • Desktop syncing client: GPLv2
  • Seafile Server core: AGPLv3
  • Seahub (Seafile server Web UI): Apache License v2

It supports file encryption and group sharing.

This tutorial explains how to install Seafile on CentOS 7 with NGINX as your web server and MariaDB as your database.

Getting started

First of all, Seafile is written in Python, so it requires the following dependencies:

# yum install python-imaging MySQL-python python-memcached python-ldap python-urllib3
Install and configure MariaDB

Install MariaDB; available on EPEL:

# yum install epel-release

then:

# yum install mariadb mariadb-server

At the end of this process, start the program and configure the MariaDB root account, executing:

# systemctl start mysqld

and

# mysql_secure_installation
Set root password? [Y/n]
New password:
Re-enter new password:
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]

Seafile requires three different databases (one for each component) :

  • ccnet-db
  • seafile-db
  • seahub-db

So, create these databases and a user, seauser:

# mysql -u root -p

In the MariaDB shell:

mysql> CREATE DATABASE ccnet-db CHARACTER SET = 'utf8';
mysql> CREATE DATABASE seafile-db CHARACTER SET = 'utf8';
mysql> CREATE DATABASE seahub-db CHARACTER SET = 'utf8';
mysql> CREATE USER 'seauser'@'localhost' IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON ccnet-db TO [email protected] IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON seafile-db TO [email protected] IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON seahub-db TO [email protected] IDENTIFIED BY 'user_strong_password';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
Install NGINX

Since the EPEL repository is available, it’s possible to install NGINX with yum:

# yum install nginx

Start it with systemd:

# systemctl start nginx.service

Create a user and a group, both named nginx:

# adduser --user-group --system --no-create-home nginx

Install and configure Seafile

Create a new directory:

# mkdir /var/www/seafile
# cd /var/www/seafile

There, download Seafile with wget:

# wget https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_6.0.8_x86-64.tar.gz

Extract the archive:

# tar xf seafile-server_6.0.8_x86-64.tar.gz

Rename the extracted directory:

# mv seafile-server-6.0.8 seafile-server
# cd seafile-server

There is a script, named setup-seafile-mysql.sh

in order to configure the database, execute it:

# ./setup-seafile-mysql.sh

It will ask for some information:

  • server name: myserver
  • server ip or domain: localhost
  • seafile data dir: press Enter, and it will use the current directory
  • fileserver port: Enter, and it should use 8082

Next, it will display the following:

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

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

Chose option 2, and then:

  • use deafult host: localhost
  • default port: 3306
  • mysql user: ‘seauser’
  • password for Seafile mysql user: ‘user_strong_password’
  • ccnet database: ‘ccnet-db’
  • seafile database: ‘seafile-db’
  • seahub database: ‘seahub-db’

Next, the script will create required tables for Seafile.

Start Seafile and Seahub:

# ./seafile.sh start
# ./seahub.sh start

During execution, seahub.sh will ask for admin informations, particularly your email and password.

After this, Seafile will be running and it will be possible to access it with a web browser, at localhost:8000.
Next, you’ll need to configure NGINX as the reverse proxy. But first, it’s necessary to create a systemd service.

Configuring services

Change the Seafile installation directory and cache owner to user nginx:

# chown -R nginx:nginx /var/www/*
# chown -R nginx:nginx /tmp/seahub_cache

Then create a service:

# $EDITOR /etc/systemd/system/seafile.service

In this file, paste the following configuration:

[Unit]
Description=Seafile - the open source, self-hosted file sync
Before=seahub.service
After=network.target mariadb.service
 
[Service]
Type=oneshot
ExecStart=/var/www/seafile/seafile-server/seafile.sh start
ExecStop=/var/www/seafile/seafile-server/seafile.sh stop
RemainAfterExit=yes
User=nginx
Group=nginx
 
[Install]
WantedBy=multi-user.target

Save, exit and do the same with SeaHub:

# $EDITOR /etc/systemd/system/seahub.service

and paste:

[Unit]
Description=SeaHub
After=network.target seafile.target mariadb.service
 
[Service]
Type=oneshot
ExecStart=/var/www/seafile/seafile-server/seahub.sh start-fastcgi
ExecStop=/var/www/seafile/seafile-server/seahub.sh stop
RemainAfterExit=yes
User=nginx
Group=nginx
 
[Install]
WantedBy=multi-user.target

Save, exit and then:

# systemctl daemon-reload
# systemctl start seafile
# systemctl start seahub

Configure NGINX

Seafile is correctly running, now configure NGINX for running Seafile behind it. Create a new Virtual Host file:

# $EDITOR /etc/nginx/conf.d/seafile.conf

and there:


server {
    listen 80;
    server_name seafile.mydomain.com;

    proxy_set_header X-Forwarded-For $remote_addr;

    location / {
        fastcgi_pass    127.0.0.1:8000;
        fastcgi_param   SCRIPT_FILENAME     $document_root$fastcgi_script_name;
        fastcgi_param   PATH_INFO           $fastcgi_script_name;

        fastcgi_param    SERVER_PROTOCOL        $server_protocol;
        fastcgi_param   QUERY_STRING        $query_string;
        fastcgi_param   REQUEST_METHOD      $request_method;
        fastcgi_param   CONTENT_TYPE        $content_type;
        fastcgi_param   CONTENT_LENGTH      $content_length;
        fastcgi_param    SERVER_ADDR         $server_addr;
        fastcgi_param    SERVER_PORT         $server_port;
        fastcgi_param    SERVER_NAME         $server_name;
        fastcgi_param   REMOTE_ADDR         $remote_addr;

        access_log      /var/log/nginx/seahub.access.log;
        error_log       /var/log/nginx/seahub.error.log;
        fastcgi_read_timeout 36000;
    }

    location /seafhttp {
        rewrite ^/seafhttp(.*)$ $1 break;
        proxy_pass http://127.0.0.1:8082;
        client_max_body_size 0;
        proxy_connect_timeout  36000s;
        proxy_read_timeout  36000s;
        proxy_send_timeout  36000s;
        send_timeout  36000s;
    }

    location /media {
        root /path/to/your/directory;
    }
}

Save, exit and test NGINX, like this:

# nginx -t

Configure domain in ccnet.conf and seahub_setting.py

Modify the value of SERVICE_URL in ccnet.conf to let Seafile know the domain, protocol and port chosen:

# $EDITOR /var/www/seafile/conf/ccnet.conf

and make the change:

SERVICE_URL = http://seafile.mydomain.com

Save, exit and edit SeaHub configuration file:

# $EDITOR /var/www/seafile/conf/seahub_setting.py

There:

# FILE_SERVER_ROOT = 'http://seafile.mydomain.com/seafhttp'

Save, exit and restart services:

# systemctl restart seafile
# systemctl restart seahub

Test Seafile

With a web browser, go to URL: http://seafile.mydomain.com; it will show a login form in which you can enter the admin account info you previously created. That’s all! Now you can use Seafile like any other cloud storage system!