Seafile on CentOS Apache SSL MySQL

Seafile is an open source cloud storage server similar to the popular Dropbox. I have been waiting for an alternative for quite some time and I’m glad to see that one of the open source servers has finally gained a lot of ground.

This post is gear towards being a tutorial rather than anything else. See their website for more details: http://www.seafile.com

This tutorial accomplishes the following goals

  • Install the Seafile server
  • Restrict to a user
  • Auto start on restart
  • Secure access through Apache HTTP Server SSL
  • Run Seafile from a different path

Prerequisites:

  • MySQL Server
  • Apache HTTP Server with SSL

Contents

Seafile Installation

Create the Seafile path

$ mkdir /opt/seafile

Create the Seafile user

$ useradd -m -d /opt/seafile -s /bin/false seafile

Change the ownership of the Seafile path

$ chown seafile:seafile /opt/seafile

Change to the new user

$ sudo -u seafile -s /bin/sh

Download the latest Seafile from their website http://seafile.com/en/download/ and extract

$ cd /opt/seafile/
$ wget "https://bitbucket.org/haiwen/seafile/downloads/seafile-server_3.0.0_x86-64.tar.gz"
$ tar xzvf seafile-server_3.0.0_x86-64.tar.gz
$ rm -f seafile-server_3.0.0_x86-64.tar.gz

There are some dependencies for Seafile.

$ yum -y install sqlite python-simplejson python-setuptools python-imaging

Run the setup and create the MySQL user, database, and tables

$ cd /opt/seafile/seafile-server_3.0.0
$ ./setup-seafile-mysql.sh

This is my configuration:

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

server name: Domain
server ip/domain: domain.com
ccnet port: 10001

seafile data dir: /opt/seafile/seafile-data
seafile port: 12001
httpserver port: 8082

database: create new
ccnet database: ccnet-db
seafile database: seafile-db
seahub database: seahub-db
database user: seafile

Start Seafile server for the first time

$ /opt/seafile/seafile-server-latest/seafile.sh start

Start Seafile Hub server for the first time

$ /opt/seafile/seafile-server-latest/seafile.sh start

On the first run, seahub will ask you to set up your admin account:

----------------------------------------
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 ] user@domain.com

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

Enter the password again:
[ admin password again ]

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

Stop the servers

$ /opt/seafile/seafile-server-latest/seahub.sh stop
$ /opt/seafile/seafile-server-latest/seafile.sh stop

Return to root access and create a file in /etc/sysconfig/seafile

# Change the value of "user" to your linux user name
user=seafile

# Change the value of "script_path" to your path of seafile installation
seafile_dir=/opt/seafile
script_path=${seafile_dir}/seafile-server-latest
seafile_init_log=${seafile_dir}/logs/seafile.init.log
seahub_init_log=${seafile_dir}/logs/seahub.init.log

# Change the value of fastcgi to true if fastcgi is to be used
fastcgi=true

# Set the port of fastcgi, default is 8000. Change it if you need different.
fastcgi_port=8000

Create the initialization script for seafile in /etc/init.d/seafile

#!/bin/bash
#
# seafile

#
# chkconfig: - 68 32
# description: seafile

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

if [ -f /etc/sysconfig/seafile ];then
. /etc/sysconfig/seafile
else
echo "Config file /etc/sysconfig/seafile not found! Bye."
exit 200
fi

RETVAL=0

start() {
# Start daemons.
echo -n $"Starting seafile: "
ulimit -n 30000
su - ${user} -c"${script_path}/seafile.sh start >> ${seafile_init_log} 2>&1"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/seafile
return $RETVAL
}

stop() {
echo -n $"Shutting down seafile: "
su - ${user} -c"${script_path}/seafile.sh stop >> ${seafile_init_log} 2>&1"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seafile
return $RETVAL
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart}"
RETVAL=3
esac

exit $RETVAL

Create the initialization script for seafile in /etc/init.d/seahub

#!/bin/bash
#
# seahub

#
# chkconfig: - 69 31
# description: seahub

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

if [ -f /etc/sysconfig/seafile ];then
. /etc/sysconfig/seafile
else
echo "Config file /etc/sysconfig/seafile not found! Bye."
exit 200
fi

RETVAL=0

start() {
# Start daemons.
echo -n $"Starting seahub: "
ulimit -n 30000
if [ $fastcgi = true ];
then
su - ${user} -c"${script_path}/seahub.sh start-fastcgi ${fastcgi_port} >> ${seahub_init_log} 2>&1"
else
su - ${user} -c"${script_path}/seahub.sh start >> ${seahub_init_log} 2>&1"
fi
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/seahub
return $RETVAL
}

stop() {
echo -n $"Shutting down seafile: "
su - ${user} -c"${script_path}/seahub.sh stop >> ${seahub_init_log} 2>&1"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/seahub
return $RETVAL
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart}"
RETVAL=3
esac

exit $RETVAL

Change permissions and add it into chkconfig

$ chmod 755 /etc/init.d/seafile
$ chmod 755 /etc/init.d/seahub
$ chkconfig --add seafile
$ chkconfig seafile on
$ chkconfig --add seahub
$ chkconfig seahub on

Apache HTTP Server Setup

mod_fastcgi Installation

Install the required packages

$ yum install libtool httpd-devel apr-devel apr gcc make

Download the latest mod_fastcgi and extract

$ wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz
$ tar xzvf mod_fastcgi-current.tar.gz
$ cd mod_fastcgi-2.4.6/

Make a copy of Makefile.AP2

cp Makefile.AP2 Makefile

Compile and install mod_fastcgi for 32-bit OS

$ make top_dir=/usr/lib/httpd
$ make install top_dir=/usr/lib/httpd

Compile and install mod_fastcgi for 64-bit OS

$ make top_dir=/usr/lib64/httpd
$ make install top_dir=/usr/lib64/httpd

Seafile Configuration

Modify /opt/seafile/ccnet/ccnet.conf

SERVICE_URL = https://domain.com

Modify /opt/seafile/seahub_settings.py and add HTTP_SERVER_ROOT to the top of the file

SITE_ROOT = '/seahub/'
HTTP_SERVER_ROOT = 'https://domain.com/seafhttp'

Increase the upload and download limits

[httpserver]
port = 8082
# Set maximum upload file size to 5120M.
max_upload_size=5120

# Set maximum download directory size to 5120M.
max_download_dir_size=5120

Apache HTTP Server Configuration

In the /etc/httpd/conf.d/ssl.conf, add the FastCGI module to the top

LoadModule ssl_module modules/mod_ssl.so
LoadModule fastcgi_module modules/mod_fastcgi.so

Before the closing VirtualHost tag, add the Seafile Proxy

FastCGIExternalServer /var/www/html/seahub.fcgi -host 127.0.0.1:8000
Alias /media /opt/seafile/seafile-server-latest/seahub/media

RewriteEngine on
#
# seafile httpserver
#
ProxyPass /seafhttp http://127.0.0.1:8082
ProxyPassReverse /seafhttp http://127.0.0.1:8082
RewriteRule ^/seafhttp - [QSA,L]

#
# seahub
#
RewriteRule ^/(media.*)$ /$1 [QSA,L,PT]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(/seahub.*)$ /seahub.fcgi/$1 [QSA,L,E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Stop all the services

$ service httpd stop
$ service seahub stop
$ service seafile stop

Start all the services

$ service seafile start
$ service seahub start
$ service httpd start

Open the server on the browser

https://domain.com/seahub

 Firewall Configuration

To allow Seafile clients to connect to the server, modify /etc/sysconfig/iptables

# seafile
-A INPUT -p tcp -m multiport --dports 10001,12001 -m state --state NEW,ESTABLISHED -j ACCEPT
-A OUTPUT -p tcp -m multiport --sports 10001,12001 -m state --state ESTABLISHED -j ACCEPT

Reset the firewall and network

$ service iptables restart
$ service network restart

Edits

2014-06-10: Added upload/download limit settings

Leave a Reply

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.