Comment procéder pour installer Seafile sur CentOS 7
Introduction
Seafile est une plateforme d'hébergement de fichiers privés, similaire à Dropbox, Google Drive, OneDrive et Mega. Ses parties sont diffusées sous licences open source, notamment :
- Client iOS Seafile : Licence Apache v2
- Client Android Seafile : GPLv3
- Client de synchronisation de bureau : GPLv2
- Noyau du serveur Seafile : AGPLv3
- Seahub (interface utilisateur Web du serveur Seafile) : licence Apache v2
Il prend en charge le cryptage de fichiers et le partage de groupe.
Ce tutoriel explique comment installer Seafile sur CentOS 7 avec NGINX comme serveur Web et MariaDB comme base de données.
Commencer
Tout d'abord, Seafile est écrit en Python, il nécessite donc les dépendances suivantes :
yum install python-imaging MySQL-python python-memcached python-ldap python-urllib3
Installer et configurer MariaDB
Installez MariaDB ; disponible sur EPEL :
yum install epel-release
alors :
yum install mariadb mariadb-server
À la fin de ce processus, démarrez le programme et configurez le compte root MariaDB en exécutant :
systemctl start mysqld
et
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 nécessite trois bases de données différentes (une pour chaque composant) :
- ccnet-db
- fichier marin-db
- seahub-db
Alors, créez ces bases de données et un utilisateur,
seauser
:
mysql -u root -p
Dans le shell MariaDB :
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 seauser@localhost IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON seafile-db TO seauser@localhost IDENTIFIED BY 'user_strong_password';
mysql> GRANT ALL PRIVILEGES ON seahub-db TO seauser@localhost IDENTIFIED BY 'user_strong_password';
mysql> FLUSH PRIVILEGES;
mysql> EXIT;
Installer NGINX
Puisque le dépôt EPEL est disponible, il est possible d'installer NGINX avec yum :
yum install nginx
Démarrez-le avec systemd :
systemctl start nginx.service
Créez un utilisateur et un groupe, tous deux nommés
nginx
:
adduser --user-group --system --no-create-home nginx
Installer et configurer Seafile
Créez un nouveau répertoire :
mkdir /var/www/seafile
cd /var/www/seafile
Là, téléchargez Seafile avec
wget
:
wget https://bintray.com/artifact/download/seafile-org/seafile/seafile-server_6.0.8_x86-64.tar.gz
Extrayez l'archive :
tar xf seafile-server_6.0.8_x86-64.tar.gz
Renommez le répertoire extrait :
mv seafile-server-6.0.8 seafile-server
cd seafile-server
Il existe un script nommé
setup-seafile-mysql.sh
afin de configurer la base de données, exécutez-la :
./setup-seafile-mysql.sh
Il vous demandera quelques informations :
- nom du serveur : monserveur
- IP ou domaine du serveur : localhost
- seafile data dir : appuyez sur Entrée, et il utilisera le répertoire actuel
- port du serveur de fichiers : entrez, et il devrait utiliser 8082
Ensuite, il affichera ce qui suit :
-------------------------------------------------------
Please choose a way to initialize Seafile databases:
-------------------------------------------------------
[1] Create new ccnet/seafile/seahub databases
[2] Use existing ccnet/seafile/seahub databases
Choisissez l'option 2, puis :
- utiliser l'hôte par défaut : localhost
- port par défaut : 3306
- Utilisateur MySQL : 'seauser'
- mot de passe pour l'utilisateur mysql Seafile : 'user_strong_password'
- Base de données ccnet : 'ccnet-db'
- base de données seafile : 'seafile-db'
- base de données Seahub : « seahub-db »
Ensuite, le script créera les tables requises pour Seafile.
Démarrez Seafile et Seahub :
./seafile.sh start
./seahub.sh start
Lors de l'exécution, seahub.sh vous demandera des informations d'administrateur, notamment votre email et votre mot de passe.
Après cela, Seafile sera exécuté et il sera possible d'y accéder avec un navigateur Web, à localhost:8000.
Ensuite, vous devrez configurer NGINX comme proxy inverse. Mais d’abord, il faut créer un service systemd.
Configuration des services
Changez le répertoire d'installation de Seafile et le propriétaire du cache en utilisateur
nginx
:
chown -R nginx:nginx /var/www/*
chown -R nginx:nginx /tmp/seahub_cache
Créez ensuite un service :
$EDITOR /etc/systemd/system/seafile.service
Dans ce fichier, collez la configuration suivante :
[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
Enregistrez, quittez et faites de même avec SeaHub :
$EDITOR /etc/systemd/system/seahub.service
et collez :
[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
Enregistrez, quittez puis :
systemctl daemon-reload
systemctl start seafile
systemctl start seahub
Configurer NGINX
Seafile fonctionne correctement, configurez maintenant NGINX pour exécuter Seafile derrière lui. Créez un nouveau fichier d'hôte virtuel :
$EDITOR /etc/nginx/conf.d/seafile.conf
et là:
<span class="hljs-section">server</span> {
<span class="hljs-attribute">listen</span> <span class="hljs-number">80</span>;
<span class="hljs-attribute">server_name</span> seafile.mydomain.com;
<span class="hljs-attribute">proxy_set_header</span> X-Forwarded-For <span class="hljs-variable">$remote_addr</span>;
<span class="hljs-attribute">location</span> / {
<span class="hljs-attribute">fastcgi_pass</span> <span class="hljs-number">127.0.0.1:8000</span>;
<span class="hljs-attribute">fastcgi_param</span> SCRIPT_FILENAME <span class="hljs-variable">$document_root</span><span class="hljs-variable">$fastcgi_script_name</span>;
<span class="hljs-attribute">fastcgi_param</span> PATH_INFO <span class="hljs-variable">$fastcgi_script_name</span>;
<span class="hljs-attribute">fastcgi_param</span> SERVER_PROTOCOL <span class="hljs-variable">$server_protocol</span>;
<span class="hljs-attribute">fastcgi_param</span> QUERY_STRING <span class="hljs-variable">$query_string</span>;
<span class="hljs-attribute">fastcgi_param</span> REQUEST_METHOD <span class="hljs-variable">$request_method</span>;
<span class="hljs-attribute">fastcgi_param</span> CONTENT_TYPE <span class="hljs-variable">$content_type</span>;
<span class="hljs-attribute">fastcgi_param</span> CONTENT_LENGTH <span class="hljs-variable">$content_length</span>;
<span class="hljs-attribute">fastcgi_param</span> SERVER_ADDR <span class="hljs-variable">$server_addr</span>;
<span class="hljs-attribute">fastcgi_param</span> SERVER_PORT <span class="hljs-variable">$server_port</span>;
<span class="hljs-attribute">fastcgi_param</span> SERVER_NAME <span class="hljs-variable">$server_name</span>;
<span class="hljs-attribute">fastcgi_param</span> REMOTE_ADDR <span class="hljs-variable">$remote_addr</span>;
<span class="hljs-attribute">access_log</span> /var/log/nginx/seahub.access.log;
<span class="hljs-attribute">error_log</span> /var/log/nginx/seahub.<span class="hljs-literal">error</span>.log;
<span class="hljs-attribute">fastcgi_read_timeout</span> <span class="hljs-number">36000</span>;
}
<span class="hljs-attribute">location</span> /seafhttp {
<span class="hljs-attribute">rewrite</span><span class="hljs-regexp"> ^/seafhttp(.*)$</span> <span class="hljs-variable">$1</span> <span class="hljs-literal">break</span>;
<span class="hljs-attribute">proxy_pass</span> http://127.0.0.1:8082;
<span class="hljs-attribute">client_max_body_size</span> <span class="hljs-number">0</span>;
<span class="hljs-attribute">proxy_connect_timeout</span> <span class="hljs-number">36000s</span>;
<span class="hljs-attribute">proxy_read_timeout</span> <span class="hljs-number">36000s</span>;
<span class="hljs-attribute">proxy_send_timeout</span> <span class="hljs-number">36000s</span>;
<span class="hljs-attribute">send_timeout</span> <span class="hljs-number">36000s</span>;
}
<span class="hljs-attribute">location</span> /media {
<span class="hljs-attribute">root</span> /path/to/your/directory;
}
}
Enregistrez, quittez et testez NGINX, comme ceci :
nginx -t
Configurer le domaine dans ccnet.conf et seahub_setting.py
Modifier la valeur de
SERVICE_URL
dans ccnet.conf pour indiquer à Seafile le domaine, le protocole et le port choisis :
$EDITOR /var/www/seafile/conf/ccnet.conf
et fais le changement :
SERVICE_URL = http://seafile.mydomain.com
Enregistrez, quittez et modifiez le fichier de configuration SeaHub :
$EDITOR /var/www/seafile/conf/seahub_setting.py
Là :
FILE_SERVER_ROOT = 'http://seafile.mydomain.com/seafhttp'
Enregistrez, quittez et redémarrez les services :
systemctl restart seafile
systemctl restart seahub
Tester le fichier marin
Avec un navigateur Web, accédez à l'URL : http://seafile.mydomain.com ; il affichera un formulaire de connexion dans lequel vous pourrez saisir les informations du compte administrateur que vous avez précédemment créé. C'est tout! Vous pouvez désormais utiliser Seafile comme n’importe quel autre système de stockage cloud !