You launch a single Redis 7 instance on a managed VM because the app team needed “a cache for sessions and rate-limits.” Six months later the cache is on the hot path — every page render, every API call, every queue ack reads or writes Redis. The VM reboots for a kernel patch on a Wednesday morning, the app fleet sees 12 minutes of cascading 500s, the post-mortem flags Redis as the single point of failure, and the obvious follow-up is: it’s been a single point of failure since day one, why are we discovering this now. The answer is that nobody scoped Redis as production state. You’re going to scope it as production state now: six nodes, three shards, automatic failover, TLS between members, ACL users instead of a shared password, and a listener bound to the private network only.
What’s happening
Redis Cluster splits the keyspace into 16384 hash slots and assigns each slot to exactly one master node. Replicas are attached to masters so that a failed master can be replaced by promoting its replica. With three masters and three replicas you can lose any one node and the cluster keeps serving; you cannot lose two nodes that hold the same shard’s master and replica without a partial outage on that shard’s slots. Clients (any modern Redis client library — redis-py, lettuce, ioredis, go-redis) connect to one node, learn the slot map on first contact, and thereafter route each key to the correct shard themselves. The cluster gossip protocol on TCP/16379 propagates topology changes and cluster forget events between nodes.
Two things people get wrong when they self-host this:
- Authentication. A
requirepassis a single shared secret. ACL users give you scoped credentials per application, per CI job, per admin operator — and per-credential rate limits, command filtering, and key-pattern restrictions. Use ACLs. - Listener. Redis bound to
0.0.0.0on a cloud VM with a public IP is how most “Redis ransom” botnet incidents start. Bind to the private interface only, and have the cloud firewall reject 6379/16379 from anywhere else.
TLS between cluster members and between clients and the cluster is no longer optional in our build standard. The CPU cost is real but small (single-digit-percent at the cache-hit rate of a typical SaaS), and the alternative — Redis traffic in plaintext on a shared VPC — keeps showing up in third-party security questionnaires.
How to verify
After the installer runs on all six nodes:
# Cluster topology from any node
redis-cli --tls \
--cacert /etc/redis/tls/ca.crt \
--cert /etc/redis/tls/redis.crt \
--key /etc/redis/tls/redis.key \
-h 10.20.0.11 -p 6379 -a "$ADMIN_PASS" \
cluster nodes
You should see six lines: three with role master (each owning a contiguous range of hash slots that together add up to 0-16383) and three with role slave (each pointing to a different master via slaveof). All six should show connected and zero should show fail or handshake.
# Slot distribution sanity check
redis-cli --tls ... cluster slots
If any range of the 16384 slots is unassigned, the cluster won’t accept writes for those keys. Re-run cluster create only on a clean state — do not “fix” slot gaps on a live cluster with cluster setslot without reading the resharding runbook.
# Replica lag from each master
redis-cli --tls ... -h 10.20.0.11 -p 6379 info replication | grep -E 'connected_slaves|slave|master_repl_offset'
A healthy replica reports state=online and an offset within a few hundred bytes of the master’s master_repl_offset.
The fix
Save the script as /root/setup-redis-cluster-node.sh and run it on each of the six nodes after editing NODE_NAME, NODE_IP, IS_BOOTSTRAP, and the PEER_* arrays at the top. The script does a full install on Ubuntu 22.04: base hardening (UFW, fail2ban, unattended-upgrades, SSH key-only), kernel/sysctl tuning for an in-memory store (vm.overcommit_memory=1, net.core.somaxconn=4096, transparent hugepages disabled), Redis 7.2 from the official Redis APT repo, a private internal CA + per-node TLS cert generated locally with OpenSSL 3, redis.conf configured for cluster mode on the private interface only, an ACL file with three users (admin, app, replication), and a one-shot redis-cli --cluster create step that runs only on the bootstrap node once all six are up.
#!/usr/bin/env bash
set -euo pipefail
### Ubuntu 22.04 Redis Cluster 7.x installer (6 nodes, 3+3)
### Run on each of the 6 nodes after editing the variables below
### Bootstrap node (IS_BOOTSTRAP=true) runs `cluster create` at the end
### No public listener — private IP only — cloud firewall must block 6379/16379 from outside
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
# === EDIT PER NODE ===
NODE_NAME="redis-m1" # redis-m1..m3 (masters), redis-r1..r3 (replicas)
NODE_IP="10.20.0.11" # this node's private IP
IS_BOOTSTRAP="true" # true on exactly one node (redis-m1)
CLUSTER_NAME="cache"
PEER_NAMES=("redis-m1" "redis-m2" "redis-m3" "redis-r1" "redis-r2" "redis-r3")
PEER_IPS=("10.20.0.11" "10.20.0.12" "10.20.0.13" "10.20.0.21" "10.20.0.22" "10.20.0.23")
ADMIN_PASS="CHANGE_ME_ADMIN"
APP_PASS="CHANGE_ME_APP"
REPL_PASS="CHANGE_ME_REPL"
INTERNAL_CIDR="10.20.0.0/16"
# =====================
echo
echo "========================================"
echo "Redis Cluster node ${NODE_NAME} (${NODE_IP})"
echo "========================================"
echo
echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
apt-get -y install curl gpg lsb-release ca-certificates \
ufw fail2ban unattended-upgrades \
openssl jq net-tools tcpdump lsof bind9-host vim
echo "==> Time sync"
timedatectl set-ntp true || true
echo "==> Kernel/sysctl tuning for Redis"
cat > /etc/sysctl.d/99-redis.conf <<'SYSCTL'
vm.overcommit_memory = 1
vm.swappiness = 1
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 10240 65535
fs.file-max = 1048576
SYSCTL
sysctl --system
echo "==> Disable transparent hugepages"
cat > /etc/systemd/system/disable-thp.service <<'THP'
[Unit]
Description=Disable Transparent Huge Pages
After=sysinit.target local-fs.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled; echo never > /sys/kernel/mm/transparent_hugepage/defrag'
RemainAfterExit=yes
[Install]
WantedBy=basic.target
THP
systemctl daemon-reload
systemctl enable --now disable-thp
cat > /etc/security/limits.d/99-redis.conf <<'LIMITS'
redis soft nofile 200000
redis hard nofile 200000
redis soft nproc 65535
redis hard nproc 65535
LIMITS
echo "==> Hardening SSH"
sed -i 's|^[#[:space:]]*PermitRootLogin.*|PermitRootLogin prohibit-password|' /etc/ssh/sshd_config
sed -i 's|^[#[:space:]]*PasswordAuthentication.*|PasswordAuthentication no|' /etc/ssh/sshd_config
sshd -t && systemctl restart ssh
echo "==> UFW — internal only, no public Redis ports"
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow from "${INTERNAL_CIDR}" to any port 6379 proto tcp
ufw allow from "${INTERNAL_CIDR}" to any port 16379 proto tcp
ufw --force enable
echo "==> fail2ban"
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
echo "==> Unattended security upgrades"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG
echo "==> Adding Redis APT repo (Redis 7.2)"
curl -fsSL https://packages.redis.io/gpg | gpg --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
apt-get update
apt-get -y install redis
systemctl stop redis-server || true
echo "==> TLS material (private CA — generated once on bootstrap, copied to peers)"
mkdir -p /etc/redis/tls
cd /etc/redis/tls
if [[ "${IS_BOOTSTRAP}" == "true" && ! -f ca.crt ]]; then
openssl req -x509 -newkey rsa:4096 -sha256 -nodes -days 3650 \
-keyout ca.key -out ca.crt \
-subj "/CN=Redis Cluster CA - ${CLUSTER_NAME}"
chmod 600 ca.key
echo " Bootstrap CA generated. Copy /etc/redis/tls/ca.crt and ca.key to peers before continuing."
fi
if [[ ! -f redis.crt ]]; then
if [[ ! -f ca.crt || ! -f ca.key ]]; then
echo "ERROR: copy ca.crt + ca.key from the bootstrap node to /etc/redis/tls/ before running on this peer." >&2
exit 2
fi
openssl req -newkey rsa:2048 -nodes \
-keyout redis.key -out redis.csr \
-subj "/CN=${NODE_NAME}" \
-addext "subjectAltName=DNS:${NODE_NAME},IP:${NODE_IP},IP:127.0.0.1"
cat > redis.ext <<EXT
subjectAltName=DNS:${NODE_NAME},IP:${NODE_IP},IP:127.0.0.1
extendedKeyUsage=serverAuth,clientAuth
EXT
openssl x509 -req -in redis.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-out redis.crt -days 825 -sha256 -extfile redis.ext
chmod 640 redis.key
chown root:redis redis.crt redis.key ca.crt
fi
cd -
echo "==> Writing /etc/redis/redis.conf"
cat > /etc/redis/redis.conf <<EOF
# Network — internal only
bind ${NODE_IP} 127.0.0.1
protected-mode yes
port 0
tls-port 6379
# TLS
tls-cert-file /etc/redis/tls/redis.crt
tls-key-file /etc/redis/tls/redis.key
tls-ca-cert-file /etc/redis/tls/ca.crt
tls-cluster yes
tls-replication yes
tls-auth-clients yes
tls-protocols "TLSv1.2 TLSv1.3"
# Cluster
cluster-enabled yes
cluster-config-file /var/lib/redis/nodes-${NODE_NAME}.conf
cluster-node-timeout 15000
cluster-require-full-coverage no
cluster-allow-reads-when-down no
cluster-announce-ip ${NODE_IP}
cluster-announce-port 6379
cluster-announce-bus-port 16379
# Persistence — RDB snapshots + AOF
appendonly yes
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
appendfsync everysec
aof-use-rdb-preamble yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
save 900 1
save 300 10
save 60 10000
dir /var/lib/redis
# Memory + eviction
maxmemory 4gb
maxmemory-policy allkeys-lru
# Logging
loglevel notice
logfile /var/log/redis/redis-server.log
syslog-enabled no
# Slow log
slowlog-log-slower-than 10000
slowlog-max-len 1024
# ACL
aclfile /etc/redis/users.acl
EOF
echo "==> Writing /etc/redis/users.acl"
cat > /etc/redis/users.acl <<EOF
# default — disabled. Forces clients to authenticate with a named user.
user default off nopass nocommands
# admin — operator account
user admin on >${ADMIN_PASS} ~* &* +@all
# app — application traffic
user app on >${APP_PASS} ~* &* -@dangerous -flushdb -flushall -keys -debug -shutdown -script +@all
# replication — used by replicas to connect to their master
user replication on >${REPL_PASS} +@all ~* &*
EOF
chmod 640 /etc/redis/users.acl
chown root:redis /etc/redis/users.acl
chown -R redis:redis /var/lib/redis
mkdir -p /var/log/redis
chown -R redis:redis /var/log/redis
# masterauth: required so replicas can auth to master during sync
cat >> /etc/redis/redis.conf <<EOF
# Used by replicas to authenticate to their master
masteruser replication
masterauth ${REPL_PASS}
EOF
chmod 640 /etc/redis/redis.conf
chown root:redis /etc/redis/redis.conf
echo "==> systemd unit overrides"
mkdir -p /etc/systemd/system/redis-server.service.d
cat > /etc/systemd/system/redis-server.service.d/override.conf <<'OVR'
[Service]
LimitNOFILE=200000
TimeoutStopSec=60
Restart=on-failure
OVR
systemctl daemon-reload
systemctl enable redis-server
systemctl start redis-server
echo "==> Waiting for Redis to accept TLS connections"
for i in {1..60}; do
if redis-cli --tls \
--cacert /etc/redis/tls/ca.crt \
--cert /etc/redis/tls/redis.crt \
--key /etc/redis/tls/redis.key \
-h "${NODE_IP}" -p 6379 \
--user admin -a "${ADMIN_PASS}" \
ping >/dev/null 2>&1; then
echo " Redis up."
break
fi
sleep 2
done
if [[ "${IS_BOOTSTRAP}" == "true" ]]; then
echo
echo "==> Bootstrap node — checking all 6 peers respond before cluster create"
ALL_UP=1
for ip in "${PEER_IPS[@]}"; do
if ! redis-cli --tls \
--cacert /etc/redis/tls/ca.crt \
--cert /etc/redis/tls/redis.crt \
--key /etc/redis/tls/redis.key \
-h "${ip}" -p 6379 \
--user admin -a "${ADMIN_PASS}" \
ping >/dev/null 2>&1; then
echo " ${ip} not reachable yet — re-run this script on the bootstrap node once all 6 are installed."
ALL_UP=0
fi
done
if [[ "${ALL_UP}" == "1" ]]; then
PEERS_ARG=""
for ip in "${PEER_IPS[@]}"; do
PEERS_ARG="${PEERS_ARG} ${ip}:6379"
done
echo "==> Creating cluster: ${PEERS_ARG}"
redis-cli --tls \
--cacert /etc/redis/tls/ca.crt \
--cert /etc/redis/tls/redis.crt \
--key /etc/redis/tls/redis.key \
--user admin -a "${ADMIN_PASS}" \
--cluster create${PEERS_ARG} \
--cluster-replicas 1 \
--cluster-yes
fi
fi
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Listeners:"
ss -lntp | grep -E ':(6379|16379)\b' || true
echo
echo "Cluster info:"
redis-cli --tls \
--cacert /etc/redis/tls/ca.crt \
--cert /etc/redis/tls/redis.crt \
--key /etc/redis/tls/redis.key \
-h "${NODE_IP}" -p 6379 \
--user admin -a "${ADMIN_PASS}" \
cluster info || true
echo
echo "Topology:"
redis-cli --tls \
--cacert /etc/redis/tls/ca.crt \
--cert /etc/redis/tls/redis.crt \
--key /etc/redis/tls/redis.key \
-h "${NODE_IP}" -p 6379 \
--user admin -a "${ADMIN_PASS}" \
cluster nodes || true
echo
echo "Client connect example:"
echo "redis-cli --tls --cacert /etc/redis/tls/ca.crt --cert /etc/redis/tls/redis.crt --key /etc/redis/tls/redis.key -h ${NODE_IP} -p 6379 --user app -a '<app pass>' -c"
echo
echo "(-c enables cluster-aware MOVED/ASK following in redis-cli.)"
Make it executable and run on the bootstrap node first to generate the CA, then copy ca.crt and ca.key to the other five nodes, then run on each peer, then re-run on the bootstrap node to actually execute cluster create:
chmod 700 /root/setup-redis-cluster-node.sh
/root/setup-redis-cluster-node.sh
# on bootstrap: copy CA out
scp /etc/redis/tls/ca.{crt,key} redis-m2:/etc/redis/tls/
# ... repeat for m3, r1, r2, r3
# then on each peer:
/root/setup-redis-cluster-node.sh
# then back on bootstrap:
/root/setup-redis-cluster-node.sh
Once cluster create succeeds, do a failover drill before production traffic. Pick one master, stop redis on it (systemctl stop redis-server), watch cluster nodes from another node — within 15 seconds the corresponding replica should be promoted to master. Restart the stopped node and it rejoins as a replica. If the promotion doesn’t happen, the most common cause is cluster-node-timeout set too high relative to your gossip latency, or one node’s cluster-announce-ip pointing at a wrong address.
Rotate the admin and app passwords by editing /etc/redis/users.acl and running redis-cli ... acl load — no restart needed.
For a Redis Cluster you don’t have to operate yourself, we run it on Cloud Compute under Managed Cloud Ops with eviction-rate and replication-lag alerting wired into our monitoring plane — start a scoping call if you want us to plan the build.