Hosting my own Mastodon instance

⚠️ Read this before deep diving

I've been dealing with Mastodon's high disk usage for the last week. Have a read before installing your own Mastodon instance. I would recommend checking out Pleroma and Akkoma before taking a decision. They have way less system requirements than Mastodon.

EDIT November 8th

Self-hosting

That's right, I know have ricard.social as my Mastodon home. Here's how this went down...

(I will assume that you're at least a little bit familiar with Mastodon and the Fediverse. If not, have a quick read before diving into my post 🤓)

🛑 mastodon.technology is shutting down

This great instance of 24.000 users is shutting down. The owner can't maintain it anymore, but that is fine! The beauty of the Fediverse is that you can move somewhere else, take your followers and continue sharing, reading, communicating...

At this point I thought I'd try to host my own Mastodon instance. I did try in the past and failed 🫠 I had hopes now it would be different. Lucky me, it was 🍀

😁 I'm proud to say that all the setup was done from my hotel room, in Busan 🇰🇷 (the big city at the boom of South Korea) ✈️ 👨‍💻

🤷‍♂️ Why host your own instance?

  • Because we can. Unlike with Twitter.
  • Complete control over what you see, who can talk to you, etc. You could block entire instances, mute people and so on with a regular account in someone else's instance. Having your own just gives you more super powers.
  • Hopefully by self-hosting I won't have to move again.
  • Self-hosting gives you extra authority. As anybody could create an account with your username in any instance, by having my own instance with my domain, it's easier to know who is behind this account.

👨‍💻 Was it hard to have it up and running?

A little bit, yes. I'm not a black belt in system engineering but I know my way around NGINX and basic Ubuntu administration.

  • The official documentation is good. A great step by step that in most cases should be enough. It wasn't for me.
  • The official mastodon forum is helpful as many people post there issues and you end up there after googling your error.
  • Still, I ended up in a state in which I saw no error and didn't know what to do. I slept on it and finally understood I had low memory issues.
  • I had to double my server capacity to 2GB RAM. Truth is, it already was at its limit. I'm self hosting a dozen sites and services. So adding a Mastodon instance on top was too much for it. Even tring to add swap space wasn't possible as I was at near full disk.

As soon as I upgraded it all worked out.

I'm very happy with the process and the end result. I hope to be more engaged on Mastodon now. I mean, now I really have to use it 😁

Do you usually self-host services?

Have you tried self-hosting a Mastodon instance?

Comments

  1. ⚠️ I have written a follow-up post moving from B2 to Scaleway as Object Storage provider. This post is still valid, the only thing is I’m not longer using B2, which might be perfectly fine for your needs 👍

    When I installed my private personal Mastodon instance y quickly noticed Mastodon has storage issues, so I tried to improve it by setting up a bunch of cron jobs to purge cached files.

    All the commands used are out of the box, no hacking involved but it’s something that’s not really highlighted in the installation guides and it’s quite important.

    I’ve been battling with a steady reduction of disk space for the last month. Not terrible but not great.

    After reading a lot from other users that the actual costs of moving the cached files with a CDN in front were so low I deiced to make the jump. External object storage provider was the next step.

    Why?

    Disk space, obviously 😄 The reality is that VPS providers don’t give you that much disk space. My VPS provider Linode, offers great shared CPU plans such as:

    5$ for 1 CPU, 1GB of RAM and 25 GB of disk space

    It’s quite cheap, if you ask me 💜

    But that’s not enough for Mastodon’s media usage. Nowadays the space should be cheap, and it actually is, but you have to use object storage. Regular SSD disk space was not meant for this use case.

    Linode also offers object storage, nice. In fact (at the time of the writing) they offer 250GB for only 5$ extra. Five dollars is not much but it’s a flat fee 😢 If you go with AWS or BackBlaze the price starts from 0$ 🤩 Unless you already have two hundred GB of media, you’re probably better off with a dynamically priced provider to start with just like I did 😉

    What’s my setup?

    BackBlaze: the object storage provider with lower prices than Amazon’s famous S3 but it has a compatible S3 API (be mindful when creating an account, select the correct region US vs EU). It has partnership with Cloudflare for very cheap close to free CDN. You need however to move your domain’s DNS to Cloudflare if you want to use their CDN.

    CloudFront from Amazon Web Services: I didn’t move my domain’s DNS to Cloudflare so I used AWS. It has an absurdly high free tier which I can’t possibly make use of. My CDN forecasted usage is less than 2% of the free tier 🤭

    AWS CLI: I’ve used to do the initial sync between my disk and the S3 bucket in BackBlaze. It takes a while, sit tight and grab a coffee.

    Configuring your .env.production file

    From your Mastodon folder

    ~/live/.env.productionCode language: JavaScript (javascript)

    Here’s what I had to add, customize the values based on your S3 and URL’s:

    .wp-block-code {
    border: 0;
    padding: 0;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    }

    .wp-block-code > span {
    display: block;
    overflow: auto;
    }

    .shcb-language {
    border: 0;
    clip: rect(1px, 1px, 1px, 1px);
    -webkit-clip-path: inset(50%);
    clip-path: inset(50%);
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    word-wrap: normal;
    word-break: normal;
    }

    .hljs {
    box-sizing: border-box;
    }

    .hljs.shcb-code-table {
    display: table;
    width: 100%;
    }

    .hljs.shcb-code-table > .shcb-loc {
    color: inherit;
    display: table-row;
    width: 100%;
    }

    .hljs.shcb-code-table .shcb-loc > span {
    display: table-cell;
    }

    .wp-block-code code.hljs:not(.shcb-wrap-lines) {
    white-space: pre;
    }

    .wp-block-code code.hljs.shcb-wrap-lines {
    white-space: pre-wrap;
    }

    .hljs.shcb-line-numbers {
    border-spacing: 0;
    counter-reset: line;
    }

    .hljs.shcb-line-numbers > .shcb-loc {
    counter-increment: line;
    }

    .hljs.shcb-line-numbers .shcb-loc > span {
    padding-left: 0.75em;
    }

    .hljs.shcb-line-numbers .shcb-loc::before {
    border-right: 1px solid #ddd;
    content: counter(line);
    display: table-cell;
    padding: 0 0.75em;
    text-align: right;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    white-space: nowrap;
    width: 1%;
    }

    S3_ENABLED=true
    S3_PROTOCOL=https
    S3_ENDPOINT=https://XXXXX.backblazeb2.com
    S3_HOSTNAME=XXXX.backblazeb2.com
    S3_BUCKET=XXXX
    AWS_ACCESS_KEY_ID=XXXX
    AWS_SECRET_ACCESS_KEY=XXXX
    S3_ALIAS_HOST=media.ricard.socialCode language: JavaScript (javascript)

    Code language: Bash (bash)

    What’s the Mastodon retention policy?

    I’ve set up the purging of attachments and previews to 4 days running every night.

    Before doing the S3 migration I had it to one day but considering how cheap it is, seven feels like a nice number.

    How cheap is the whole thing?

    I’m honestly surprised how low the cost of the whole move is. For the past month:

    BackBlaze S3 bucket:

    💾 Disk usage (60 GB): USD $0.16

    📈 Transactions: USD $0.25

    📉 Downloaded GB: 0€

    💰 Cost: USD $0.41

    Amazon Web Services CloudFront CDN:

    📈 Transactions: 1% from the free tier

    📉 Downloaded GB: 1.2% from the free tier

    💰 Monthly cost: free

    Conclusion

    There is no doubt a move to object storage should be your default if you attempt to host a Mastodon instance. It doesn’t matter if for a private single-user, 10 users, or 10.000 users. The cost of hosting the media files in a S3-compatible bucket will be far cheaper than locally on the same server.

    Have you moved your files to an object storage? Have you encountered any issues?

    Any other cloud storage provider you recommend?

Leave a Reply

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