Mastodon is an open-source, federated (i.e., decentralized) social network, inspired by Twitter's "microblogging" format, and used by upwards of 4.4M early-adopters, to share links, pictures, video and text.
Why would I run my own instance?
That's a good question. After all, there are all sorts of public instances available, with a range of themes and communities. You may want to run your own instance because you like the tech, because you just think it's cool
You may also have realized that since Mastodon is federated, users on your instance can follow, toot, and interact with users on any other instance!
If you're not into that much effort / pain, you're welcome to join our instance
Why /var/data/runtime/mastodon and not just /var/data/mastodon?
The data won't be able to be backed up by a regular filesystem backup, because it'll be in use. We still need to store it somewhere though, so we use /var/data/runtime, which is excluded from automated backups. See Data Layout for details.
Setup Mastodon environment
Create /var/data/config/mastodon/mastodon.env something like the example below..
/var/data/config/mastodon/mastodon.env
# This is a sample configuration file. You can generate your configuration# with the `rake mastodon:setup` interactive setup wizard, but to customize# your setup even further, you'll need to edit it manually. This sample does# not demonstrate all available configuration options. Please look at# https://docs.joinmastodon.org/admin/config/ for the full documentation.# Note that this file accepts slightly different syntax depending on whether# you are using `docker-compose` or not. In particular, if you use# `docker-compose`, the value of each declared variable will be taken verbatim,# including surrounding quotes.# See: https://github.com/mastodon/mastodon/issues/16895# Federation# ----------# This identifies your server and cannot be changed safely later# ----------LOCAL_DOMAIN=example.com# Redis# -----REDIS_HOST=redisREDIS_PORT=6379# PostgreSQL# ----------DB_HOST=dbDB_USER=postgresDB_NAME=postgresDB_PASS=tootmeupbuttercupDB_PORT=5432# Elasticsearch (optional)# ------------------------ES_ENABLED=falseES_HOST=esES_PORT=9200# Authentication for ES (optional)ES_USER=elasticES_PASS=password# Secrets# -------# Make sure to use `rake secret` to generate secrets# -------SECRET_KEY_BASE=imafreaksecretbabyOTP_SECRET=imtoosecretformysocks# Web Push# --------# Generate with `rake mastodon:webpush:generate_vapid_key`# docker run -it tootsuite/mastodon bundle exec rake mastodon:webpush:generate_vapid_key# --------VAPID_PRIVATE_KEY=VAPID_PUBLIC_KEY=# Sending mail# ------------SMTP_SERVER=smtp.mailgun.orgSMTP_PORT=587SMTP_LOGIN=SMTP_PASSWORD=SMTP_FROM_ADDRESS=notifications@example.com# File storage (optional)# -----------------------S3_ENABLED=trueS3_BUCKET=files.example.comAWS_ACCESS_KEY_ID=AWS_SECRET_ACCESS_KEY=S3_ALIAS_HOST=files.example.com# IP and session retention# -----------------------# Make sure to modify the scheduling of ip_cleanup_scheduler in config/sidekiq.yml# to be less than daily if you lower IP_RETENTION_PERIOD below two days (172800).# -----------------------IP_RETENTION_PERIOD=31556952SESSION_RETENTION_PERIOD=31556952
Mastodon Docker Swarm config
Create a docker swarm config file in docker-compose syntax (v3), something like the example below.. example:
Fast-track with premix! 🚀
"Premix" is a git repository which includes necessary docker-compose and env files for all published recipes. This means that you can launch any recipe with just a git pull and a docker stack deploy 👍.
🚀 Update: Premix now includes an ansible playbook, enabling you to deploy an entire stack + recipes, with a single ansible command! (more here)
Setup unique static subnets for every stack you deploy. This avoids IP/gateway conflicts which can otherwise occur when you're creating/removing stacks a lot. See my list here.
Pre-warming
Unlike most recipes, we can't just deploy Mastodon into Docker Swarm, and trust it to setup its database itself. We have to "pre-warm" it using docker-compose, per the official docs (Docker Swarm is not officially supported)
Start with docker-compose
From the /var/data/config/mastodon directory, run the following to start up the Mastodon environment using docker-compose. This will result in a broken environment, since the database isn't configured yet, but it provides us the opportunity to configure it.
root@raphael:/var/data/config/mastodon#docker-compose-fmastodon.ymlrun--rmwebbin/tootctlaccountscreatebatman--emailbatman@batcave.org--confirmed--roleadmin
WARNING:Someservices(streaming,web)usethe'deploy'key,whichwillbeignored.Composedoesnotsupport'deploy'configuration-use`dockerstackdeploy`todeploytoaswarm.
OK
Newpassword:c6eb8e0d10cd6f0aa874b7a384177a08
root@raphael:/var/data/config/mastodon#
Turn off docker-compose
We've setup the essestials now, everything else can be configured either via the UI or via the .env file, so tear down the docker-compose environment with:
Now hit the URL you defined in your config, and you should see your beautiful new Mastodon instance! Login with your configured credentials, navigate to Preferences, and have fun tweaking and tooting away!
If your instance feels lonely, try using some relays to bring in the federated firehose!
Summary
What have we achieved? Even though we had to jump through some extra hoops to setup database and users, we now have a fully-swarmed Mastodon instance, ready to federate with the world!
Summary
Created:
Mastodon configured, running, and ready to toot!
Chef's notes 📓
Or, you can just reset your password from the UI, assuming you have SMTP working ↩
Tip your waiter (sponsor) 👏
Did you receive excellent service? Want to compliment the chef? (..and support development of current and future recipes!) Sponsor me on Github / Ko-Fi / Patreon, or see the contribute page for more (free or paid) ways to say thank you! 👏
Employ your chef (engage) 🤝
Is this too much of a geeky PITA? Do you just want results, stat? I do this for a living - I'm a full-time Kubernetes contractor, providing consulting and engineering expertise to businesses needing short-term, short-notice support in the cloud-native space, including AWS/Azure/GKE, Kubernetes, CI/CD and automation.
Want to know now when this recipe gets updated, or when future recipes are added? Subscribe to the RSS feed, or leave your email address below, and we'll keep you updated.