Setting up Vultr S3 Object Storage on my Mastodon instance
I did not setup S3 object storage while installing my own instance mut day later I was thinking that it could be easier to setup now than later. So here are couple of tips that I figured out.
Please keep in mind that you are doing this on your own risk! I do not take blame if anything goes wrong 😆
Move data to object storage
I suggest that you turn off your instance first. Then no new images will be generated. The command to do this is this:
sudo systemctl stop mastodon-*.service
Then it is time to move your existing data to your S3 object storage. These steps are from here: https://github.com/cybrespace/cybrespace-meta/blob/master/s3.md#configuring-mastodon-to-use-the-s3-bucket. You also may find this article from Vultr helpful: https://www.vultr.com/docs/how-to-use-s3cmd-with-vultr-object-storage/.
sudo apt-get install s3cmd
As the mastodon user run this command (you need S3 bucket info for this):
You can test that everything is working by creating test file and moving it to the bucket (use your own bucket name insted of BUCKET_NAME):
echo "test" > tmp.txts3cmd --acl-public put tmp.txt s3://BUCKET_NAME/tmp.txt
Navigate to mastodon folder:
To save some bandwidth, you can remove old remote media:
RAILS_ENV=production ./bin/tootctl media remove --days=7
Now you can move your content to the bucket (use your own bucket name insted of BUCKET_NAME):
s3cmd --acl-public sync --add-header="Cache-Control:public, max-age=315576000, immutable" public/system/ s3://BUCKET_NAME
This may take a while but after this is done your files are safely in the S3 object storage.
Next you need to edit your
.env.production file. Here are my S3 configurations for Vultr.
Use your own values for S3_BUCKET, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. Vultr does not care about S3_REGION value. Also change S3_HOSTNAME and S3_ENDPOINT. But do not put https:// to S3_HOSTNAME. Put https:// to S3_ENDPOINT. The https:// start was a bit of a head scratcher since I got best results with mentioned values. I tried with and without but this combo worked the best.
After setting the configuration values you can start up your instance with this command:
sudo systemctl start mastodon-*.service --all
With these changes and after your instance is back up you can try to upload an image and see if it goes to S3 object storage. Mine did and it will go.
If you want to help here is affiliate links!