Setting up Seafile on Ubuntu to sync files involves creating databases for Seafile components and installing Seafile dependencies.
As a part of our Server Management Services, we help our Customers with software installations regularly.
Let us today discuss the steps to sync and share files with Seafile on Ubuntu.
How to sync and share files with Seafile on Ubuntu?
Seafile is a file synchronization and sharing platform. It allows us to share files and folders using cross-platform syncing and password-protected links to files with expiration dates.
Here we will install and configure Seafile on an Ubuntu 18.04 server. We will use MariaDB to store data for the different components of Seafile, and Apache as the proxy server to handle the web traffic. Finally, we will be able use the web interface to access Seafile from desktop or mobile clients, allowing us to sync and share files with other users or groups on the server or with the public.
Creating Databases for the Seafile Components
Seafile requires three components in order to work properly. These three components are:
- Seahub: Seafile’s web frontend, written in Python using the Django web framework. From Seahub we can access, manage, and share the files using a web browser.
- Seafile server: The data service daemon that manages the raw file upload, download, and synchronization. We do not interact with the server directly, but use one of the client programs or the Seahub web interface.
- Ccnet server: The RPC service daemon to enable internal communication between the different components of Seafile. For example, when we use Seahub, it is able to access data from the Seafile server using the Ccnet RPC service.
Each of these components stores its data separately in its own database. In this step, we will create the three MariaDB databases and a user before proceeding to set up the server.
First, log in to the server using SSH with the username and IP address:
$ ssh bob@your_server_ip
Connect to the MariaDB database server as administrator (root):
$ sudo mariadb
At the MariaDB prompt, use the following SQL command to create the database user:
MariaDB [(none)]> CREATE USER 'bob'@'localhost' IDENTIFIED BY 'password';
Next, we will create the following databases to store the data of the three Seafile components:
- ccnetdb for the Ccnet server.
- seahubdb for the Seahub web frontend.
- seafiledb for the Seafile file server.
At the MariaDB prompt, we can create our databases:
MariaDB [(none)]> CREATE DATABASE ccnetdb CHARACTER SET = 'utf8';
MariaDB [(none)]> CREATE DATABASE seafiledb CHARACTER SET = 'utf8';
MariaDB [(none)]> CREATE DATABASE seahubdb CHARACTER SET = 'utf8';
Then, grant all privileges to the Seafile database user to access and make changes in these databases:
MariaDB [(none)]> GRANT ALL PRIVILEGES ON ccnetdb.* to bob@localhost;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON seafiledb.* to bob@localhost;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON seahubdb.* to bob@localhost;
Finally, exit the MariaDB prompt by typing exit.
Installing Dependencies and Downloading Seafile
Some parts of Seafile are written in Python and therefore require additional Python modules and programs to work. In this step, we will install these required dependencies before downloading and extracting the Seafile server package.
First, install pip and setuptools. The corresponding Debian package are called python3-pip and python3-setuptools respectively. We can install them using apt:
$ sudo apt install -y python3-pip python3-setuptools
Once pip and setuptools are installed, we can install additional dependencies from Python package index (PyPI) using the pip3 command:
$ pip3 install Pillow captcha django-simple-captcha
Seafile requires Pillow, a python library for image processing, and captcha and django-simple-captcha to provide captcha support for authentication.
Now that we have installed the necessary dependencies, we can download the Seafile server package.
Seafile creates additional directories during setup. To keep them all organized, create a new directory and change into it:
$ mkdir seafile
$ cd seafile
We can now download the latest version (7.1.4) of the Seafile server from the website by running the following command:
$ wget https://download.seadrive.org/seafile-server_7.1.4_x86-64.tar.gz
Seafile distributes the download as a compressed tar archive, which means we will need to extract it before proceeding. Extract the archive using tar:
$ tar -zxvf seafile-server_7.1.4_x86-64.tar.gz
Now change into the extracted directory:
$ cd seafile-server-7.1.4
Configuring the Seafile Server
Seafile needs some information about the setup before we start the services for the first time. This includes details like the domain name and the database configuration. To initiate the series of question prompts to provide this information, we can run the script setup_seafile_mysql.sh, which is included in the archive we extracted.
Run the script using bash:
$ bash setup-seafile-mysql.sh
The script will now prompt us with a series of questions. Wherever defaults are mentioned, pressing the ENTER key will use that value.
While it asks for the MariaDB database server, we will only need to provide the username and password of the mariadb user that we created.
After providing the password, the script will request the names of the Seafile databases. Use ccnetdb, seafiledb, and seahubdb for this article. The script will then verify if there is a successful connection to the databases before proceeding to display a summary of the initial configuration.
Configuring the Apache Web Server
In this step, we will configure the Apache web server to forward all requests to Seafile. Using Apache in this manner allows us to use a URL without a port number, enable HTTPS connections to Seafile, and make use of the caching functionality that Apache provides for better performance.
To begin forwarding requests, we will need to enable the proxy_http module in the Apache configuration. This module provides features for proxying HTTP and HTTPS requests. The following command will enable the module:
$ sudo a2enmod proxy_http
The Apache rewrite and ssl modules are also required for this setup.
Next, update the virtual host configuration of your_domain to forward requests to the Seafile file server and to the Seahub web interface.
Open the configuration file in a text editor:
$ sudo nano /etc/apache2/sites-enabled/your_domain-le-ssl.conf
The lines from ServerAdmin to SSLCertificateKeyFile are part of the initial Apache and Let’s Encrypt configuration.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/your_domain/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/your_domain/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
Alias /media /home/sammy/seafile/seafile-server-latest/seahub/media
<Location /media>
Require all granted
</Location>
# seafile fileserver
ProxyPass /seafhttp http://127.0.0.1:8082
ProxyPassReverse /seafhttp http://127.0.0.1:8082
RewriteEngine On
RewriteRule ^/seafhttp - [QSA,L]
# seahub web interface
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
</VirtualHost>
</IfModule>
The Alias directive maps the URL path your_domain/media to a local path in the file system that Seafile uses. The following Location directive enables access to content in this directory. The ProxyPass and ProxyPassReverse directives make Apache act as a reverse proxy for this host, forwarding requests to / and /seafhttp to the Seafile web interface and file server running on local host ports 8000 and 8082 respectively. The RewriteRule directive passes all requests to /seafhttp unchanged and stops processing further rules ([QSA,L]).
Save and exit the file.
Test if there are any syntax errors in the virtual host configuration:
$ sudo apache2ctl configtest
If it reports Syntax OK, then there are no issues with your configuration. Restart Apache for the changes to take effect:
$ sudo systemctl restart apache2
Updating Seafile’s Configuration and Starting Services
As we are now using Apache to proxy all requests to Seafile, we will need to update the URLs in Seafile’s configuration files in the conf directory using a text editor before we start the Seafile service.
Open ccnet.conf in a text editor:
$ nano /home/bob/seafile/conf/ccnet.conf
Modify the SERVICE_URL setting in the file to point to the new HTTPS URL without the port number. For example, update /home/bob/seafile/conf/ccnet.conf
SERVICE_URL = https://your_domain
Save and exit the file once we have added the content.
Now open seahub_settings.py in a text editor:
$ nano /home/bob/seafile/conf/seahub_settings.py
We can now add a FILE_SERVER_ROOT setting in the file to specify the path where the file server is listening for file uploads and downloads. Update /home/bob/seafile/conf/seahub_settings.py :
SECRET_KEY = "..."
FILE_SERVER_ROOT = 'https://your_domain/seafhttp'
Save and exit seahub_settings.py.
Now we can start the Seafile service and the Seahub interface:
$ cd /home/bob/seafile/seafile-server-7.1.4
$ ./seafile.sh start
$ ./seahub.sh start
As this is the first time we have started the Seahub service, it will prompt us to create an admin account. Enter a valid email address and a password for this admin user:
Open https://your_domain in a web browser and log in using the Seafile admin email address and password.
Once logged in successfully, we can access the admin interface or create new users.
Now that we have verified the web interface is working correctly, we can enable these services to start automatically at system boot in the next step.
Enabling the Seafile Server to Start at System Boot
To enable the file server and the web interface to start automatically at boot, we can create the respective systemd service files and activate them.
Create a systemd service file for the Seafile file server:
$ sudo nano /etc/systemd/system/seafile.service
Add the following content to the file:
[Unit]
Description=Seafile
After=network.target mariadb.service
[Service]
Type=forking
ExecStart=/home/bob/seafile/seafile-server-latest/seafile.sh start
ExecStop=/home/bob/seafile/seafile-server-latest/seafile.sh stop
User=bob
Group=bob
[Install]
WantedBy=multi-user.target
Here, the ExectStart and ExecStop lines indicate the commands that run to start and stop the Seafile service. The service will run with bob as the User and Group. The After line specifies that the Seafile service will start after the networking and MySQL service has started.
Save seafile.service and exit.
Now, create a systemd service file for the Seahub web interface:
$ sudo nano /etc/systemd/system/seahub.service
This is similar to the Seafile service. The only difference is that the web interface is started after the Seafile service. Add the following content to this file:
[Unit]
Description=Seafile hub
After=network.target seafile.service
[Service]
Type=forking
ExecStart=/home/bob/seafile/seafile-server-latest/seahub.sh start
ExecStop=/home/bob/seafile/seafile-server-latest/seahub.sh stop
User=bob
Group=bob
[Install]
WantedBy=multi-user.target
Save seahub.service and exit.
Finally, to enable both the Seafile and Seahub services to start automatically at boot, run the following commands:
$ sudo systemctl enable seafile.service
$ sudo systemctl enable seahub.service
When the server is rebooted, Seafile will start automatically.
Testing File Syncing and Sharing Functionality
In this step, we will test the file synchronization and sharing functionality of the server we have set up and ensure they are working correctly. To do this, we will need to install the Seafile client program on a separate computer and/or a mobile device.
Visit the download page on the Seafile website and follow the instructions to install the latest version of the program on the computer.
Once we have installed the Seafile client, we can test the file synchronization and sharing functionality.
Open the Seafile client program on the computer or device. Accept the default location for the Seafile folder and click Next.
In the next window, enter the server address, username, and password, then click Login.
At the home page, right click on My Library and click Sync this library. Accept the default value for the location on the computer or device.
Add a file, for example a document or a photo, into the My Library folder. After some time, the file will upload to the server.
Now, log in to the web interface at https://your_domain and verify that the file is present on the server.
Click on Share next to the file to generate a download link for this file.
[Need any further assistance to sync files via seafile? – We’re available 24*7]
Conclusion
In short, today we saw how our Support Engineers setup Seafile on Ubuntu. We can use the Seafile server to sync files, add users and groups, and share files between them or with the public without relying on an external service.
0 Comments