Redis provides two high-availability mechanisms: Sentinel for automatic failover on a primary-replica setup, and Cluster for horizontal partitioning across multiple nodes. Both are production-grade solutions supported on RHEL 8 through the EPEL 8 repository or directly from the Redis package. Understanding when to use each helps you design a topology that meets your durability and throughput requirements. This tutorial covers configuring a three-instance Sentinel setup and a six-node Redis Cluster from scratch.
Prerequisites
- RHEL 8 server(s) with root or
sudoaccess - EPEL 8 repository enabled:
dnf install -y epel-release firewalldinstalled and active- For Sentinel: one primary + two replicas (can share a single host on different ports for testing)
- For Cluster: six nodes, each on a distinct port (can be co-hosted for testing)
Step 1 — Install Redis
Install Redis from EPEL 8 and enable the service. Redis 6.x is available in EPEL 8; Redis 7.x can be installed from the Remi repository if a newer version is required.
dnf install -y epel-release
dnf install -y redis
systemctl enable --now redis
systemctl status redis
Step 2 — Configure Redis Sentinel
Sentinel monitors a primary Redis instance and automatically promotes a replica when the primary becomes unreachable. Create three Sentinel configuration files — one per Sentinel instance. On a single host, use ports 26379, 26380, and 26381.
# /etc/redis/sentinel-26379.conf
port 26379
daemonize yes
logfile /var/log/redis/sentinel-26379.log
pidfile /var/run/redis/sentinel-26379.pid
# Monitor primary on 127.0.0.1:6379, quorum = 2
sentinel monitor mymaster 127.0.0.1 6379 2
# Mark primary down after 5 seconds of no response
sentinel down-after-milliseconds mymaster 5000
# Allow 10 seconds for a failover to complete
sentinel failover-timeout mymaster 10000
# Only one replica syncs with the new primary during failover
sentinel parallel-syncs mymaster 1
# Copy config for the remaining two Sentinel instances, changing the port
cp /etc/redis/sentinel-26379.conf /etc/redis/sentinel-26380.conf
sed -i 's/26379/26380/g' /etc/redis/sentinel-26380.conf
cp /etc/redis/sentinel-26379.conf /etc/redis/sentinel-26381.conf
sed -i 's/26379/26381/g' /etc/redis/sentinel-26381.conf
Start all three Sentinel processes:
redis-sentinel /etc/redis/sentinel-26379.conf
redis-sentinel /etc/redis/sentinel-26380.conf
redis-sentinel /etc/redis/sentinel-26381.conf
# Verify Sentinel sees the primary
redis-cli -p 26379 sentinel masters
Step 3 — Connect an Application via Sentinel
Applications should connect through the Sentinel API rather than hardcoding the primary address. The Sentinel returns the current primary’s address, which changes during failover. Below is an example using redis-cli to discover the primary at runtime.
# Ask Sentinel for the current primary address
redis-cli -p 26379 sentinel get-master-addr-by-name mymaster
# Expected output:
# 1) "127.0.0.1"
# 2) "6379"
In application code, use a Sentinel-aware Redis client (e.g., Jedis, ioredis, redis-py with Sentinel()) that automatically reconnects to the new primary after failover.
Step 4 — Set Up a Six-Node Redis Cluster
Redis Cluster shards keyspace across nodes and provides automatic failover without Sentinel. A minimum production setup uses six nodes: three primary shards and three replicas. Create separate configuration files for each node.
# Template: /etc/redis/redis-7000.conf
port 7000
cluster-enabled yes
cluster-config-file /var/lib/redis/nodes-7000.conf
cluster-node-timeout 5000
appendonly yes
daemonize yes
logfile /var/log/redis/redis-7000.log
pidfile /var/run/redis/redis-7000.pid
dir /var/lib/redis
# Generate configs for all 6 nodes (ports 7000-7005)
for port in 7000 7001 7002 7003 7004 7005; do
cp /etc/redis/redis-7000.conf /etc/redis/redis-${port}.conf
sed -i "s/7000/${port}/g" /etc/redis/redis-${port}.conf
redis-server /etc/redis/redis-${port}.conf
done
# Verify all nodes are running
redis-cli -p 7000 ping
Step 5 — Bootstrap the Redis Cluster
Use redis-cli --cluster create to assign hash slots to primary nodes and attach replicas. The --cluster-replicas 1 flag assigns one replica per primary.
redis-cli --cluster create
127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002
127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
--cluster-replicas 1
# Type 'yes' when prompted to accept the slot assignments
# Verify cluster topology
redis-cli -c -p 7000 cluster info
redis-cli -c -p 7000 cluster nodes
Step 6 — Open Firewall Ports
Each Redis node requires its client port and a bus port (client port + 10000) for cluster communication. Open all required ports in firewalld.
# Sentinel ports
firewall-cmd --permanent --add-port=26379-26381/tcp
# Redis Cluster client ports
firewall-cmd --permanent --add-port=7000-7005/tcp
# Redis Cluster bus ports
firewall-cmd --permanent --add-port=17000-17005/tcp
firewall-cmd --reload
Conclusion
You have configured both a Redis Sentinel topology for automatic primary failover and a six-node Redis Cluster for horizontal sharding on RHEL 8. Sentinel is the right choice when you need high availability on a single dataset, while Cluster is preferable when dataset size exceeds the memory of a single node or when you need to distribute write throughput. Both setups can coexist in larger architectures serving different workloads.
Next steps: How to Secure Redis with TLS on RHEL 8, How to Monitor Redis with Prometheus on RHEL 8, and How to Persist Redis Data with RDB and AOF on RHEL 8.