Redis Master/Slave Setup

tested on debian/buster

Install

grab the latest release

apt install gnupg1 curl lsb-release

#curl -fsSL https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg
curl -fsSL https://packages.redis.io/gpg | gpg1 --dearmor -o /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" > /etc/apt/sources.list.d/redis.list
cat /etc/apt/sources.list.d/redis.list
apt update

on servers

apt install redis redis-server
redis-server --version

on clients (incl. the servers themselves)

apt install redis-tools
redis-cli --version

tune the kernel

cd /etc/
mv -i sysctl.conf sysctl.conf.dist
grep -vE '^[[:space:]]*#|^[[:space:]]*$' sysctl.conf.dist > sysctl.conf.clean
grep -vE '^[[:space:]]*#|^[[:space:]]*$' sysctl.conf.dist > sysctl.conf
vi sysctl.conf # was therefore empty

net.core.somaxconn = 1024
vm.overcommit_memory = 1

    sysctl -p

Server setup

assuming internal and trusted network

cd /etc/redis/
mv -i redis.conf redis.conf.dist
grep -vE '^#|^$' redis.conf.dist > redis.conf.clean
grep -vE '^#|^$' redis.conf.dist > redis.conf
vi redis.conf

bind 0.0.0.0

# default acl user
#requirepass SOME-PASSWORD

and on the slave also as follows

assuming redis1 is defined as static name resolution

slaveof redis1 6379
#masterauth SOME-PASSWORD

Ready to go

systemctl restart redis-server
netstat -lntup | grep redis

systemctl status redis-server # not enabled yet
systemctl enable redis-server

Operations

if you enabled authentication for default acl user

export REDISCLI_AUTH=SOME-PASSWORD

List databases

redis-cli info | grep ^db

Print the key names of a given database, say db1 (default is db0)

select 1
keys *

Resources

Getting started with Redis https://redis.io/topics/quickstart

cli

https://redis.io/topics/rediscli

usage

https://www.baeldung.com/redis-list-all-databases

https://chartio.com/resources/tutorials/how-to-get-all-keys-in-redis/

https://stackoverflow.com/questions/12802726/how-to-list-all-redis-databases ==> INFO

https://redis.io/commands/KEYS

https://redis.io/commands/eval

tuning

https://www.digitalocean.com/community/cheatsheets/how-to-manage-redis-databases-and-keys

moar

https://redis.io/topics/persistence –> appendonly yes

https://laravel.com/docs/8.x/queues#installing-supervisor

https://laravel.com/docs/8.x/queues#supervisor-configuration

http://supervisord.org/running.html?highlight=reread

https://redis.io/download

https://stackoverflow.com/questions/7537905/how-to-set-password-for-redis


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun