Effective total cost: $3–4/mo
Decide on an EC2 instance type:
- At AWS Console → EC2 → Instance Types, filter for ≥1 GB RAM and sort by price.
- t3a.micro is lowest.
- Look up what t3a.micro means:
- t: general-purpose with a burstable CPU quota
- 3: the current generation
- a: AMD
- micro: the second lowest configuration
- Calculate cost:
- $6.89/mo when paying hourly
- $4.00/mo when paying annually
- $2.59/mo when paying every 3 years
Prepare your AWS account:
- Set up an alarm for your estimated monthly bill so you're notified early of any unanticipated expenses.
- Import your SSH public key. (EC2 → us-west-2 → Key pairs)
Have ready:
- a domain name and DNS host
- an outgoing mail server
- I use AWS SES since it's easy (decent reputation, automatic DKIM, etc.) and inexpensive ($0.01/mo), but any SMTP provider will do, and you could also set up a traditional mail server on the EC2 instance.
- static file storage/hosting
- I use AWS S3 ($0.10/mo), but a variety of providers offer "S3-compatible" service, and you could also just use the filesystem on the EC2 instance. My storage has been growing linearly at 0.65 GB/mo ($0.02/mo²).
Start an EC2 instance:
- Launch an instance (EC2 → us-west-2 → Instances) with:
- Image: Ubuntu Server 18.04 LTS (HVM), SSD Volume Type (64-bit x86)
- Type: t3a.micro
- Enable termination protection: Yes
- T2/T3 Unlimited: No
- Storage: 8 GiB standard (HDD, $0.40/mo)
- Tags:
- Name:
Mastodon
- Name:
- Security Group:
- Name:
mastodon
- SSH from anywhere
- HTTP from anywhere
- HTTPS from anywhere
- Name:
- Set up a static IP address and publish an A record at your preferred DNS host.
Prepare the host:
- SSH in as
ubuntu
. - Add 1 GB of swap:
- Make a swap file at
/swapfile
. - Add a swap entry in
/etc/fstab
. - Set
vm.swappiness=10
in/etc/sysctl.conf
.
- Make a swap file at
- Tune for memory exhaustion:
- Set
nvm.vfs_cache_pressure=200
in/etc/sysctl.conf
.
- Set
- Enable swap compression:
- Append
zswap.enabled=1
toGRUB_CMDLINE_LINUX_DEFAULT
in/etc/default/grub.d/50-cloudimg-settings.cfg
. - Run
sudo update-grub
.
- Append
- Update/upgrade apt packages.
- If it prompts you to reinstall GRUB, skip that; it has no effect in EC2.
- Reboot.
Install Mastodon:
- Follow Mastodon's instructions.
- To tune PostgreSQL, set:
effective_cache_size = 512MB
- When editing
.env.production
, pay particular attention to:LOCAL_DOMAIN
SINGLE_USER_MODE
SMTP…
S3…
andAWS…
- When registering services, set:
- mastodon-sidekiq:
--concurrency 1
- mastodon-streaming:
STREAMING_CLUSTER_NUM=1
- mastodon-web:
MAX_THREADS=2
andWEB_CONCURRENCY=1
- mastodon-sidekiq:
- To tune PostgreSQL, set:
- Reboot.
- Sign in to the web interface and review/configure admin settings.
Try out the setup for a few days/weeks, then commit to a longer payment term:
- At EC2 → Reserved Instances → Purchase, filter for t3a.micro, sort by effective rate, and purchase a reservation.
- Wait a few hours for payment processing to complete.
- At EC2 → Reserved Instances, confirm that the reservation is active.
borgmatic configuration:
location:
repositories:
- …
atime: false
source_directories:
- /home/mastodon/live
patterns:
- "+ /home/mastodon/live/.env.production"
- "! /home/mastodon/live/*"
retention:
keep_daily: 7
keep_monthly: 12
hooks:
postgresql_databases:
- name: mastodon_production
username: postgres