Menu Home

Setting up Redis 8 on Ubuntu 26.04 for Mastodon

Notice: Mastodon requires two kinds of cache. Sidekiq queues and home feeds, and the rails cache.
Large instances should consider running two or even separate Redis servers.

Working from https://docs.joinmastodon.org/admin/scaling/

Mastodon Server: maxmemory-policy: noeviction and appendonly yes, appendfsync everysec because we want to save the state.
Cache Server: `maxmemory-policy: allkeys-lru and save "" appendonly no` because we don’t care about state.
Sidekiq Server: xx

REDIS_URL (required for streaming)
CACHE_REDIS_URL (optional for ephemeral Rails cache)
SIDEKIQ_REDIS_URL (super optional for sidekiq)


Install Redis

sudo apt-get install lsb-release curl gpg
curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
sudo chmod 644 /usr/share/keyrings/redis-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
sudo apt-get update
sudo apt-get install redis

sudo systemctl enable redis-server
sudo systemctl start redis-server

Kernel tuning

# sudo nano /etc/sysctl.d/99-redis.conf

vm.overcommit_memory = 1
vm.swappiness = 1
net.core.somaxconn = 4096

Grub tuning

sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="transparent_hugepage=never"
sudo update-grub
sudo reboot

Tune redis.conf

sudo nano /etc/redis/redis.conf
bind 127.0.0.1 <private-vlan-ip>
protected-mode yes
requirepass <long random string>

maxmemory <bytes> (Leave a 1Gb or so for the OS)
tcp-backlog 65536 (default 511)

Configure CPU Affinity (Optional)

On real CPUs, you can lay them out, but vCPUs on a hypervisor likely get moved around…. so not worth it?

sudo nano /etc/redis/redis.conf
server-cpulist 0-2
bio-cpulist 3-4
bgsave-cpulist 5-6
aof-rewrite-cpulist 7

Tune systemd service (Optional)

sudo nano /usr/lib/systemd/system/redis-server.service
[Service]
LimitNOFILE=65535

Categories: Uncategorised

shlee

Leave a Reply

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

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)