Seafile is an open-source file sync and share software. You can upload files and sync them across different devices. Seafile provides a web interface but also native clients for macOS, Linux, Windows, and for the mobile platforms Android and iOS. These clients share the files across different devices. Seafile also provides drive clients that enable you to access files on the server without syncing to a local disk, like a network drive.
You can use Seafile by subscribing to a hosting provider. But in this tutorial, I will show you how to self-host Seafile and install it on a VPS. For this example, I use a VPS from Hetzner (referral link). I'm testing this on the smallest Hetzner server offering (CX11) with 2GB of RAM and 20GB of disk space. If you are looking for a VPS with much more disk space, I recommend looking at Contabo. The smallest Contabo VPS presently (February 2022) for EUR 4.99 / month includes a 200 GB SSD.
In this tutorial, I will install the free Community Edition of Seafile. There is also a Pro Edition, which is also free for up to 3 users, but for this tutorial, I don't need the additional features of the Pro Edition. Check out this page to see the differences between the Community and Pro Editions.
DNS ¶
Before setting up the server, I created a subdomain in the DNS configuration. This is needed if you want to use TLS, which is highly recommended. For this demo, I use the domain sea.rasc.ch
.
In the web console of my DNS provider, I inserted an A record that points to the IP address of my VPS. Also, add an AAAA
record if the server has a public IPv6 address.
sea.rasc.ch. 86400 IN A 51.38.124.133
If your DNS provider supports this feature, I also recommend adding a CAA record. Either for the whole domain if you get all your certificates from one CA or just for the subdomain if you use multiple certificate authorities.
rasc.ch. 86400 IN CAA 0 issue "letsencrypt.org"
// OR
sea.rasc.ch. 86400 IN CAA 0 issue "letsencrypt.org"
Docker ¶
I run all the following commands as a root user on a Debian 11. If you are not logged in as root, prepend sudo
to the commands or switch to root with sudo -i
.
First, make sure that the system is up-to-date.
apt update
apt full-upgrade
The easiest way to install Seafile is with Docker. Install Docker following the installation instructions on this web page: https://docs.docker.com/engine/install/debian/
Test the Docker installation with docker run hello-world
. You should see the Hello from Docker!
message if everything is set up correctly.
We also need to install docker compose.
https://docs.docker.com/compose/
mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/latest/download/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
chmod +x ~/.docker/cli-plugins/docker-compose
Check if it works:
$ docker compose version
Docker Compose version v2.2.3
You don't have to use Docker. Instead, you can install Seafile directly on Linux. Doing it the manual way gives you complete control over the Seafile installation.
Visit the official documentation page for more information about this topic:
https://manual.seafile.com/latest/deploy/
Seafile ¶
Download the Seafile docker-compose.yml to your server. Open it in an editor.
mkdir /opt/seafile
cd /opt/seafile
curl -o docker-compose.yml https://download.seafile.com/seafhttp/files/e9f11f66-ef7c-4b9d-b107-a9f2ce57a6d0/docker-compose.yml
nano docker-compose.yml
You should change:
- The password of MariaDb root (
MYSQL_ROOT_PASSWORD
andDB_ROOT_PASSWD
) - The volume directory of MySQL data (volumes)
- The volume directory of Seafile data (volumes).
SEAFILE_ADMIN_EMAIL
andSEAFILE_ADMIN_PASSWORD
- If you want to use TLS, update
SEAFILE_SERVER_HOSTNAME
andSEAFILE_SERVER_LETSENCRYPT
Here is the complete docker-compose.yml
I used for this demo installation.
version: '2.0'
services:
db:
image: mariadb:10.5
container_name: seafile-mysql
environment:
- MYSQL_ROOT_PASSWORD=do_not_use_this_password_change_me
- MYSQL_LOG_CONSOLE=true
volumes:
- /opt/seafile/db:/var/lib/mysql
networks:
- seafile-net
memcached:
image: memcached:1.5.6
container_name: seafile-memcached
entrypoint: memcached -m 256
networks:
- seafile-net
seafile:
image: seafileltd/seafile-mc:latest
container_name: seafile
ports:
- "8000:80"
volumes:
- /opt/seafile/data:/shared
environment:
- DB_HOST=db
- DB_ROOT_PASSWD=do_not_use_this_password_change_me
- TIME_ZONE=Etc/UTC
- SEAFILE_ADMIN_EMAIL=me@rasc.ch
- SEAFILE_ADMIN_PASSWORD=a_very_secret_password_change_me
- SEAFILE_SERVER_LETSENCRYPT=false
- SEAFILE_SERVER_HOSTNAME=sea.rasc.ch
depends_on:
- db
- memcached
networks:
- seafile-net
networks:
seafile-net:
By default, Seafile listens on ports 80 and 443 and automatically configures a Let's Encrypt certificate. But in this installation, I wanted to install it on a server where a Caddy server was already installed that listens on ports 80 and 443. Therefore, I changed the port mapping in the docker-compose.yml ("8000:80"
), so Seafile listens on port 8000.
If you want to follow my installation and also use Caddy, install Caddy following the instructions on this page:
https://caddyserver.com/docs/install#debian-ubuntu-raspbian
Open the Caddy configuration.
nano /etc/caddy/Caddyfile
and paste the following configuration:
{
email <valid_email_address_for_lets_encrypt>
}
sea.rasc.ch {
reverse_proxy 127.0.0.1:8000
}
Change the domain name. Restart Caddy with the command systemctl restart caddy
.
Again, this is optional. Seafile can directly listen on ports 80 and 443 and configure the TLS certificate. But the setup with Caddy allows you to host multiple services on one server.
Start the Seafile containers.
docker compose up -d
Open a browser and enter the domain name. Seafile should greet you with the login screen.
Log in with the configured admin email and password.
If you are interested in installing the Pro Edition, visit this page:
https://manual.seafile.com/latest/docker/pro-edition/deploy_seafile_pro_with_docker/
Client ¶
You can upload and download files over the web interface, but installing a client is more convenient. Here, I installed the Windows syncing client. You can find all provided clients on the download page: https://www.seafile.com/en/download/
The first time you start a native client, it presents a dialog where you must enter the server address and your login credentials.
If you install a syncing client, it syncs the remote library to your local computer, and each time you add files locally, it syncs them to the remote server. On the other hand, a drive client enables you to access files without syncing to the local disk. It works like a network drive.
Upgrade ¶
It is recommended to update Seafile from time to time. Run the following commands manually or create a scheduled job that does it automatically.
docker pull seafileltd/seafile-mc:latest
cd /opt/seafile
docker-compose down
docker-compose up -d
Backup ¶
You usually don't have a backup on a VPS out of the box. Some VPS providers have snapshot tools where you can take a snapshot of the whole server.
For a mission-critical Seafile installation, you should look at installing a Seafile cluster. Check out the following page for more information:
https://manual.seafile.com/latest/docker/cluster/deploy_seafile_cluster_with_docker/
In this section, I show you a simple backup approach where a script runs once a day and copies everything to an Amazon S3 bucket.
If you want to follow this tutorial, create a user on AWS. Then, take a note of the access and secret key. This is the policy I attached to the user.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": [
"arn:aws:s3:::rasc.seafile/*",
"arn:aws:s3:::rasc.seafile"
]
}
]
}
Also, create an S3 bucket. I created a bucket with the name rasc.seafile
. Change this name in the policy and script to the bucket you created.
Install the Amazon S3 command-line tools.
apt install s3cmd
In the /opt/seafile
folder, create a new file called backup-seafile.sh
and paste the following code.
#!/bin/sh
rm -fr /opt/seafile/backup
mkdir /opt/seafile/backup
cd /opt/seafile/backup
docker exec -it seafile-mysql mysqldump -uroot --opt ccnet_db > ccnet_db.sql
docker exec -it seafile-mysql mysqldump -uroot --opt seafile_db > seafile_db.sql
docker exec -it seafile-mysql mysqldump -uroot --opt seahub_db > seahub_db.sql
cp -R /opt/seafile/data/seafile /opt/seafile/backup/data/
cd /opt/seafile/backup/data && rm -rf ccnet
cd /opt/seafile
rm -fr backup.tar.gz
tar czf backup.tar.gz backup
s3cmd --access_key=AK... --secret_key=cd... sync /opt/seafile/backup.tar.gz s3://rasc.seafile
rm -fr /opt/seafile/backup.tar.gz
rm -fr /opt/seafile/backup
Make the script executable:
cd /opt/seafile
chmod 700 backup-seafile.sh
Next, install a timer service in systemd. This takes care of starting our backup job daily at a specified time.
Create a file seafile-backup.timer
and paste this code into the file.
[Unit]
Description=Run seafile-backup once a day
[Timer]
OnCalendar=*-*-* 05:00:00
RandomizedDelaySec=30
Persistent=true
[Install]
WantedBy=timers.target
Change OnCalendar
if you want to run this script at a different time or more often than just daily. See the documentation for information about the supported format:
https://www.freedesktop.org/software/systemd/man/latest/systemd.time.html
Create the systemd service file seafile-backup.service
and paste this code into the file:
[Unit]
Description=backup-seafile
[Service]
WorkingDirectory=/opt/seafile
Type=oneshot
ExecStart=/opt/seafile/backup-seafile.sh
Then, link these files into the systemd folder, reload systemd, start, and enable the timer:
ln -s /opt/seafile/seafile-backup.timer /lib/systemd/system/seafile-backup.timer
ln -s /opt/seafile/seafile-backup.service /lib/systemd/system/seafile-backup.service
systemctl daemon-reload
systemctl start seafile-backup.timer
systemctl enable seafile-backup.timer
Check if the timer is installed correctly.
systemctl list-timers
Manually start the job.
systemctl start seafile-backup
journalctl -u seafile-backup
To recover a backup, check out the following page from the official documentation:
https://manual.seafile.com/latest/docker/deploy_seafile_with_docker/#recovery
This concludes the tutorial about self-hosting Seafile. A powerful file sync software and a good alternative to Dropbox, Google Drive, and others.