Have you ever wondered what would be to have your own personal Dropbox/Google Drive/Box alternative?
Thanks to open source you can do it fairly quickly.
You can find the podcast episode about self hosted file sync service on the techie leadership show - https://techieleadership.com/bonus-3-self-hosting-your-own-file-services-with-nedjalko-milenkov/.
Before getting our hands dirty, let's just see why we should even bother self hosting our own file server.
- You are your own boss
- The storage is limited by the storage on your server or cloud provider
- Your data stays yours and you have complete ownership
- No ads
- Can be cheaper than paying monthly for Dropbox/Google Drive/Box and etc.
- You need to take care of your server from time to time
- Upfront cost can be higher if you purchase the hardware (does not apply to cloud)
You will be surprised that there are quire a few open source alternatives for self hosted file synchronisation.
To name a few:
- Seafile - https://www.seafile.com
- Nextcloud - https://nextcloud.com
- ownCloud - https://owncloud.com
This tutorial will cover how to install Seafile.
I have tested Seafile, Nextcloud and ownCloud and found that Seafile perform better for my needs, however both Nextcloud and ownCloud are great alternatives. I'll write another article on comparing the 3 solutions and tutorials on how to install them so make sure you subscribe or check the RSS feed.
In short Seafile is very fast, reliable and easy to maintain. It does one thing and does it great - file sync, file storage and file sharing. It's been on the market since 2012.
There are many ways to install Seafile. Too keep it simple and short (to justify the title of the tutorial 🙂) here are the prerequisites that you will need in term of basic knowledge and infrastructure.
- Basic knowledge of Docker Compose
- Linux with installed Docker Compose (in this tutorial we will use DigitalOcean*)
- Domain name and basic knowledge on how to manage it
DigitalOcean* is a fast, reliable and cheap cloud provider. You can use it for development or running production system on it. I am using it for both and so far I am quite happy with the service.
This step will cover how to setup a DigitalOcean droplet (virtual machine). If you are using another cloud provider or your own linux server, you can skip it.
The cheapest plan on DigitalOcean is for $5 and includes 1 GB / 1 CPU, 25 GB SSD Disk, 1000 GB transfer, which is not bad for a start. You can add additional volume for $0.10 per gigabyte.
DigitalOcean has a marketplace, which has images of virtual machines with preinstalled software. We are going to use the marketplace to install a virtual machine with preconfigured Docker Compose. Cool isn't it?
- Here is the link* for the Docker Compose image on the DigitalOcean marketplace.
- To create the droplet click the big blue button Create Docker Droplet.
- After you register/login, you will see the droplet configuration screen.
- Choose the Basic plan.
- Choose the virtual machine for $5 a month.
- Choose a datacenter region. It's better to chose a region, which is close to you or the users who will use the service.
- For Authentication choose SSH keys. Create a new SSH key with New SSH Key button if you don't already have a key. Here is the DigitalOcean tutorial on how to use the SSH keys - https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/create-with-putty/ .
- Choose a hostname. It is recommended to be the same as the domain or subdomain that you will use. In my case the domain will be drive.myhub.io. Please change the domain in the tutorial to yours.
- Press the big green button Create droplet
- That's it. After a few minutes, you will have a dedicated virtual machine, with real IP and Docker and Docker Compose preinstalled and configured for you.
- Let's create some firewall rules. Go to Networking->Firewalls on the left panel. Click Create Firewall. For name choose Seafile (anything will work actually).
- Go to the SSH row in the Inbound Rules. In the Sources remove the values ALL IPv4 and ALL IPv6.
- You need to add your IP address, which you can find from this site https://www.ipify.org for an example. This step will ensure that only your IP will have SSH access. That's the main admin channel for your virtual machine. You can add as many IPs there. Make sure to update them if your IP keeps changing.
- Still in the Inbound Rules click to add a new rule New rule and from the dropdown choose HTTP. Leave the Sources to ALL IPv4, ALL IPv6.
- Still in the Inbound Rules click to add a new rule New rule and from the dropdown choose HTTPS. Leave the Sources to ALL IPv4, ALL IPv6.
- Step 14 and 15 will ensure that your droplet (virtual machine) will have ports 80 (HTTP) and 443 (HTTPS) accessible from everywhere.
- Go to Apply to Droplets and start typing the name of your droplet. In our case it will be drive.myhub.io.
- Press the big green button Create Firewall.
- We've created a simple firewall for our droplet. Now let's configure the domain name. I assume that you already have a domain name and know how to add an A record.
- From the control panel on the left go to Projects and select your space. It's probably named Personal. That space will contain all your droplets. You should see your droplet and it's IP. You need then to create an A record for your domain to point to that IP. In my case I made drive.myhub.io to point to my droplet's IP.
I assume that you already have completed the DigitalOcean steps or you have your own server. Just make sure to point your domain/subdomain to your server's IP. In this tutorial, my domain drive.myhub.io is pointing to my droplet with an A DNS record.
- Let's ssh to the server. (Note: You need to configure your SSH profiel. The tutorial for DigitalOcean is here.)
- Create folder for our Seafile instance.
mkdir seafile cd seafile
- Create the docker-compose.yml file
- Paste the following content into the file.
version: '2.0' services: nginx: image: nginx:1.19.0 ports: - 443:443 volumes: - /root/seafile/nginx-container/nginx.conf:/etc/nginx/nginx.conf - /root/seafile/nginx-container/ssl:/ssl/ depends_on: - seafile restart: "always" networks: - seafile-net db: image: mariadb:10.1 environment: - MYSQL_ROOT_PASSWORD=somepassword # Requested, set the root''s password of MySQL service. - MYSQL_LOG_CONSOLE=true volumes: - /root/seafile/mysql-container:/var/lib/mysql # Requested, specifies the path to MySQL data persistent store. restart: "always" networks: - seafile-net memcached: image: memcached:1.5.6 entrypoint: memcached -m 256 restart: "always" networks: - seafile-net seafile: image: seafileltd/seafile-mc:8.0.3 expose: - 80 volumes: - /root/seafile/seafile-container/data:/shared # Requested, specifies the path to Seafile data persistent store. environment: - DB_HOST=db - DB_ROOT_PASSWD=somepassword # Requested, the value shuold be root's password of MySQL service. - TIME_ZONE=Europe/Sofia # Optional, default is UTC. Should be uncomment and set to your local time zone. - SEAFILE_ADMIN_EMAILfirstname.lastname@example.org # Specifies Seafile admin user, default is 'email@example.com'. - SEAFILE_ADMIN_PASSWORD=adminpassword # Specifies Seafile admin password - SEAFILE_SERVER_LETSENCRYPT=false # Whether to use https or not. - SEAFILE_SERVER_HOSTNAME=drive.myhub.io # Specifies your host name if https is enabled. depends_on: - db - memcached restart: "always" networks: - seafile-net networks: seafile-net:
To be continued...
The full tutorial will be available on Tuesday 16.02.2021. Stay tuned :)
* Some of the links have my referral code. If you use them you might get a small bonus from the referral program and so do I.