How to mount DigitalOcean Space on CentOS 7

DigitalOcean S3 compatible object storage called Spaces allows you to store and serve large amounts of data. They are easy to create and are ready to be used within seconds without any configuration. They are ideal for storing static unstructured data like audio, video and images as well as binary files, archives, backups etc.

What’s so cool about Spaces compared to Amazon S3 is the fact that their pricing structure is WAY more easier to understand and predict. For $5/month you get 250 GB of storage and 1 TB of outbound transfer (inbound/upload is always free). Every additional GB stored costs $0.02 and every additional GB transferred costs $0.01. On top of that you can even serve these files utilizing use their free CDN service at no additional cost! (This alone on Amazon CloudFront can cost you a little fortune!).

Now back to the main topic: mounting DigitalOcean Space as a folder on your server that can be used to store any kind of data.

1. To start with the process you’ll need to install s3fs and some dependencies for it to work normally:

sudo yum update

sudo yum install automake autotools-dev fuse g++ git libcurl4-gnutls-dev libfuse-dev libssl-dev libxml2-dev make pkg-config

cd ~

git clone https://github.com/s3fs-fuse/s3fs-fuse.git

cd s3fs-fuse

./autogen.sh

./configure

make

sudo make install

2. Next you’ll need to create a file that will hold your Spaces API Key and Secret Key (don’t forget to replace these keys with KEY:SECRET_KEY’ in the command below):

echo ‘KEY:SECRET_KEY’ > ~/.passwd-s3fs


chmod 600 ~/.passwd-s3fs

3. Now we need to create a folder that will be a mounting point for Spaces

mkdir /backup

4. Now we can mount the Space

s3fs SPACE_NAME /backup -o passwd_file=~/.passwd-s3fs -o url=https://nyc3.digitaloceanspaces.com -o use_path_request_style

If your space is not in New York than Amsterdam or somewhere else: replace nyc3 with ams3 or the whatever is correct.

By this point the your DigitalOcean space should be mounted at /spaces path and you’ll be able to use it just any local folder. You could copy files in and out, rsync data there etc. Note that accessing files in that folder is done over your networks since these files are actually hosted remotely and that will burn your server’s bandwidth. You can see that this folder is mounted if you run df -h in the command line. In case you need to unmount it for any reason:let’s say you’re writing a backup bash script where it will mount the Space copy backups over and unmount it when it’s done, all you need to run is umount /backup and it’s done!

If you reboot your system this folder will not get mounted again so in order for that to be done on the boot you’ll need to edit fstab file that is located at /etc/fstab. Open the file for editing in your favorite text editor and add this line at the end of the file:

s3fs#SPACE_NAME /backup fuse allow_other,_netdev,nosuid,nodev,url=https://nyc3.digitaloceanspaces.com 0 0

After saving the changes to fstab file run:

sudo mount -a

Now the Space will be auto-mounted on every server boot. Now you can host unlimited number of files there and access them easily. You can mount same Space on couple servers so they all can access them at the same time or use it for your backups…

There are so many situations where this can be incredibly useful and I don’t have a doubt you’ll use this to create something really cool.

How to quickly and safely remove your Google+ account
How to view HEIC images on Windows

Comments

Leave a Reply

Your email address will not be published / Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.