Seafile est un cloud Open Source sous licence AGPLv3 permettant notamment le stockage et le partage de fichiers en ligne. Il a été créé à l’origine en 2009 par Daniel Pan à l’université de Tsinghua à Pékin. D’abord un projet de partage de fichiers peer-to-peer, il est devenu une solution de serveur centralisé dès 2010. Il est développé depuis 2012 par la société chinoise Seafile Ltd. et est actuellement en version 6.0.9.
Comparatif des fonctionnalités entre la version Entreprise et la version Communautaire : ici.
Il offre de nombreuses fonctionnalités, potentiellement étendues grâce à des plugins, dont :
- Partage de fichiers par lien public
- Sécurisation des partages par mot de passe ou date d’expiration des liens
- Synchronisation avec clients Android/iPhone ou Windows/Linux/MAC OS X
- Partage de fichiers ou de dossiers, en mode read-only ou read-write
- Gestion des versions de documents
- Verrouillage des fichiers en cas d’éditions concurrentes (version pro)
- Travail collaboratif par édition de documents
- Visualisation de nombreux formats de fichiers dont PDF, documents Office (version pro) et images
- Cryptage des données et des transferts
- Sauvegarde et récupération
- Authentification LDAP
- Certaines fonctionnalités ne sont accessibles que dans sa version Entreprise même si l’essentiel est présent dans sa version Communautaire
- etc.
Alternatives Open Source à Seafile :
Objectif
L’objectif de cet article est l’installation et la configuration d’un serveur LAM (Linux Apache MariaDB), avec Python et Django, auto-hébergé Seafile en version 6.0.9 sur une distribution Linux Debian Jessie 8.7 32bits.
Schéma logique

Pré-requis
1. Pré-requis avant réalisation
- Un serveur Debian Jessie 8.7 32 bits fonctionnel (installation basique avec utilitaires usuels du système et service SSH)
- Packages de base supplémentaires : sudo, resolvconf, tree, unzip
- Domaine utilisé : opensharing.priv
2. Configuration réseau initiale
Serveur Seafile | |
FQDN | seafile-test.opensharing.priv |
Adresse IP | 192.168.1.22 |
Réseau | 192.168.1.0/24 |
Passerelle | 192.168.1.1 |
dns-nameservers | 192.168.1.11 192.168.1.12 |
dns-search | opensharing.priv |
Contenu initial du fichier /etc/network/interfaces :
auto lo iface lo inet loopback allow-hotplug eth0 iface eth0 inet static address 192.168.1.22 netmask 255.255.255.0 network 192.168.1.0 broadcast 192.168.1.255 gateway 192.168.1.1 dns-search opensharing.priv dns-nameservers 192.168.1.11 192.168.1.12
Contenu initial du fichier /etc/hosts :
127.0.0.1 localhost.localdomain localhost 192.168.1.22 seafile-test.opensharing.priv seafile-test 192.168.1.22 seafile.opensharing.priv seafile
Rmq : L’adresse 127.0.1.1 doit être retirée sur un serveur à IP fixe et remplacée par cette dernière, tel que l’exemple ci-dessus.
Contenu initial du fichier /etc/host.conf :
order hosts, bind multi on
Contenu initial du fichier /etc/resolv.conf :
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8) # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN nameserver 192.168.1.11 nameserver 192.168.1.12 search opensharing.priv
Rmq :
Le fichier /etc/resolv.conf ne doit pas être édité dès lors que le paquet resolvconf a été installé.
Pour prendre en compte les modifications des fichiers de configuration relatifs au réseau, redémarrage du service réseau :
# /etc/init.d/networking restart # /etc/init.d/networking reload
Réalisation
1. Introduction
Seafile est constitué de trois services principaux, chacun étant géré par un script :
- Par défaut, Seafile n’utilise pas Apache comme serveur Web. Il embarque un frontend Web Python Django, appelé Seahub, reposant sur un serveur Web Python léger Gunicorn (Green Unicorn). Nous verrons plus loin comment configurer Seahub pour s’exécuter en mode fast-cgi derrière Apache. Seahub est en écoute sur le port 8000.
- Le deuxième service est appelé Seafile. Il gère les téléchargements, les uploads, la synchronisation de fichiers, etc. Nous verrons plus loin comment configurer Apache pour rediriger le trafic vers Seafile. Seafile est en écoute sur le port 8082.
- Un troisième service existe, interne cette fois-ci, permettant de gérer la communication entre Seahub et Seafile : il s’agit du service Ccnet.
A chaque service correspond une base de données :
-
seahub-db pour le service Seahub
seafile-db pour le service Seafile
ccnet-db pour le service Ccnet
Le script d’installation s’occupe de tout sous forme assistée :
- Vérification de la présence des dépendances requises
- Création du dépôt pour les données des utilisateurs
- Création des 3 services
- Création de leurs bases de données respectives
- Création de l’administrateur de ces dernières
2. Installation de MariaDB
# apt install mariadb-server mariadb-client
Installe les paquets suivants par dépendances :
libaio1 | libdbd-mysql-perl | libdbi-perl | libhtml-template-perl |
libmysqlclient18 | libreadline5 | libterm-readkey-perl | mariadb-client |
mariadb-client-10.0 | mariadb-client-core-10.0 | mariadb-common | mariadb-server |
mariadb-server-10.0 | mariadb-server-core-10.0 | mysql-common |
Choisir le mot de passe pour le compte d’administration de MariaDB (« root« ) et le confirmer.
# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. You already have a root password set, so you can safely answer 'n'. Change the root password? [Y/n] n ... skipping. By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
3. Installation des dépendances Python
# apt install python2.7 libpython2.7 python-setuptools python-imaging python-ldap python-mysqldb python-memcache python-urllib3
Installe les paquets suivants par dépendances :
libpython2.7 | python2.7 | python-cffi | python-cryptography |
python-ldap | python-memcache | python-mysqldb | python-ndg-httpsclient |
python-imaging | python-openssl | python-ply | python-pyasn1 |
python-pycparser | python-setuptools | python-urllib3 |
4. Installation de Seafile
# wget https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_6.0.9_i386.tar.gz # mkdir -p /opt/seafiledir/seafile/ # tar -zxvf seafile-server_6.0.9_i386.tar.gz --strip-components 1 -C /opt/seafiledir/seafile/ # cd /opt/seafiledir/seafile/
# ./setup-seafile-mysql.sh Checking python on this machine ... Checking python module: setuptools ... Done. Checking python module: python-imaging ... Done. Checking python module: python-mysqldb ... Done. ----------------------------------------------------------------- This script will guide you to setup your seafile server using MySQL. Make sure you have read seafile server manual at https://github.com/haiwen/seafile/wiki 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.opensharing.priv Where do you want to put your seafile data? Please use a volume with enough free space [ default "/opt/seafile-dir/seafile-data" ] 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 ] 1 What is the host of mysql server? [ default "localhost" ] What is the port of mysql server? [ default "3306" ] What is the password of the mysql root user? [ root password ] verifying password of user root ... done Enter the name for mysql user of seafile. It would be created if not exists. [ default "seafile" ] seafileadmin Enter the password for mysql user "seafileadmin": [ password for seafileadmin ] Enter the database name for ccnet-server: [ default "ccnet-db" ] Enter the database name for seafile-server: [ default "seafile-db" ] Enter the database name for seahub: [ default "seahub-db" ] --------------------------------- This is your configuration --------------------------------- server name: seafile server ip/domain: seafile.opensharing.priv seafile data dir: /opt/seafile-data fileserver port: 8082 database: create new ccnet database: ccnet-db seafile database: seafile-db seahub database: seahub-db database user: seafileadmin --------------------------------- Press ENTER to continue, or Ctrl-C to abort --------------------------------- Generating ccnet configuration ... done Successly create configuration dir /opt/seafiledir/ccnet. Generating seafile configuration ... Done. done Generating seahub configuration ... ---------------------------------------- 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| stop | restart } ----------------------------------------------------------------- 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://github.com/haiwen/seafile/wiki for information.
Rmq : Le script setup-seafile.sh est destiné à une installation avec SQLite et le script setup-seafile-mysql.sh à une installation avec MySQL ou MariaDB.
# ./seafile.sh start [04/11/17 12:03:23] ../common/session.c(132): using config file /opt/seafiledir/conf/ccnet.conf Starting seafile server, please wait ... Seafile server started Done. # LC_ALL=fr_FR.UTF-8 ./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@opensharing.priv 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.
5. Première connexion à Seafile
Saisir, dans la barre d’adresses, l’adresse suivante :
http://seafile.opensharing.priv:8000
redirigeant automatiquement vers :
http://seafile.opensharing.priv:8000/accounts/login/?next=/
Le portail d’authentification apparait. Saisir les identifiants de connexion de l’administrateur définis lors de la commande précédente.
La connexion à Seafile s’établit alors.
Pour aller plus loin
En l’état, le serveur Seafile est fonctionnel. Toutefois, il peut être amélioré en termes de sécurité, en cryptant les échanges en HTTPS par exemple.
Pour cela, nous allons installer et configurer Apache pour prendre en compte le protocole HTTPS et rediriger les requêtes vers Seahub.

1. Installation et configuration de Apache
# apt install apache2 apache2-doc
Installe les paquets suivants par dépendances :
apache2 | apache2-data | apache2-doc | apache2-utils |
# nano /etc/apache2/sites-available/seafile.conf
<VirtualHost *:80> DocumentRoot /var/www/seafile/ ServerName seafile.opensharing.priv Redirect permanent / https://seafile.opensharing.priv/ </VirtualHost> <VirtualHost *:443> ServerName seafile.opensharing.priv DocumentRoot /var/www/seafile/ SSLEngine On SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire SSLCertificateFile /etc/ssl/certs/seafileperso.crt SSLCertificateKeyFile /etc/ssl/private/seafileperso.key Alias /media /opt/seafiledir/seafile-server-latest/seahub/mediaRequire all granted RewriteEngine On ProxyPass /seafhttp http://127.0.0.1:8082 ProxyPassReverse /seafhttp http://127.0.0.1:8082 RewriteRule ^/seafhttp - [QSA,L] SetEnvIf Request_URI . proxy-fcgi-pathinfo=unescape SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 ProxyPass / fcgi://127.0.0.1:8000/ </VirtualHost>
Génération de la clef privée :
# openssl genrsa -out /etc/ssl/private/seafileperso.key 1024
Generating RSA private key, 1024 bit long modulus
...................................................++++++
.................................++++++
e is 65537 (0x10001)
Demande de certificat à partir de la clef :
# openssl req -new -key /etc/ssl/private/seafileperso.key -out /etc/ssl/certs/seafileperso.csr You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank. For some fields there will be a default value, if you enter '.', the field will be left blank. ----- Country Name (2 letter code) [AU]:FR State or Province Name (full name) [Some-State]:Ile-de-France Locality Name (eg, city) []:Paris Organization Name (eg, company) [Internet Widgits Pty Ltd]:OpenSharing Organizational Unit Name (eg, section) []:Service Informatique Common Name (e.g. server FQDN or YOUR name) []:seafile.opensharing.priv Email Address []:admin@opensharing.priv Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:seafilecertificate An optional company name []:OpenSharing
Construction du certificat :
# openssl x509 -req -days 365 -in /etc/ssl/certs/seafileperso.csr -signkey /etc/ssl/private/seafileperso.key -out /etc/ssl/certs/seafileperso.crt Signature ok subject=/C=FR/ST=Ile-de-France/L=Paris/O=OpenSharing/OU=Service Informatique/CN=seafile.opensharing.priv/emailAddress=admin@opensharing.priv Getting Private key
Activation du site et des modules :
# mkdir /var/www/seafile/ # chown www-data:www-data /var/www/seafile/ # a2ensite seafile # a2enmod ssl # a2enmod rewrite # a2enmod proxy_fcgi # a2enmod proxy_http # apachectl configtest Syntax OK
Arrêt des services Seahub et Seafile :
# ./seafile.sh stop # ./seahub.sh stop
Modification de la configuration du service Ccnet :
# nano /opt/seafiledir/conf/ccnet.conf
Remplacer
SERVICE_URL = http://seafile.opensharing.priv:8000
par :
SERVICE_URL = https://seafile.opensharing.priv
Modification de la configuration du service Seahub :
# nano /opt/seafiledir/conf/seahub_settings.py
Ajouter la ligne suivante en fin de fichier :
FILE_SERVER_ROOT = 'https://seafile.opensharing.priv/seafhttp'
Démarrage du service Seafile et du service Seahub en mode fast-cgi :
# service apache2 restart # ./seafile.sh start [04/11/17 16:08:01] ../common/session.c(132): using config file /opt/seafiledir/conf/ccnet.conf Starting seafile server, please wait ... Seafile server started Done. # LC_ALL=fr_FR.UTF-8 ./seahub.sh start-fastcgi Starting seahub (fastcgi) at 127.0.0.1:8000 ... Seahub is started Done.
2. Installation de phpMyAdmin
# apt install phpmyadmin
Installe les paquets suivants par dépendances :
dbconfig-common | javascript-common | libjs-jquery | libjs-sphinxdoc |
libjs-underscore | libmcrypt4 | php-gettext | php-tcpdf |
php5-gd | php5-mcrypt | phpmyadmin |
Choisir le serveur web à reconfigurer automatiquement, dans notre cas apache2.
Faut-il configurer la base de données de phpmyadmin avec dbconfig-common ? Non
On peut maintenant se connecter à phpMyAdmin via l’URL suivant :
127.0.0.1/phpmyadmin
3. Connexion en HTTPS au cloud
Saisir, dans la barre d’adresses, l’adresse suivante :
http://seafile.opensharing.priv
redirigeant automatiquement vers :
https://seafile.opensharing.priv
Le répondeur OCSP nous signifie que le certificat n’émane pas d’une autorité de certification reconnue, un message d’avertissement est donc émis.
Cliquer sur Avancé puis Ajouter une exception…
Il suffit ensuite de Confirmer l’exception de sécurité.
Le connexion est bien établie en HTTPS.
Et l’accès à Seahub par le port 8000 n’est plus fonctionnel.
4. Effectuer une sauvegarde manuelle complète
# ./opt/seafiledir/seafile/seafile.sh stop # ./opt/seafiledir/seafile/seahub.sh stop # mkdir -p /home/adminsys/backup/6.0.9/ # cd /home/adminsys/backup/6.0.9/ # tar -czvf backup-seafile-20170411.tar.gz -C /opt/ seafiledir/ # mysqldump --user=seafileadmin --password=seafileadminpw --databases seahub-db seafile-db ccnet-db > seafile-20170411.sql
5. Effectuer une restauration manuelle complète
# cd /home/adminsys/backup/6.0.9/ # tar -xzvf backup-seafile-20170411.tar.gz -C /opt/ # mysql --user=seafileadmin --password=seafileadminpw -D seahub-db -D seafile-db -D ccnet-db < seafile-20170411.sql # ./opt/seafiledir/seafile/seafile.sh start # LC_ALL=fr_FR.UTF-8 ./opt/seafiledir/seafile/seahub.sh start-fastcgi
Références