Databases 10 min read

Setting Up Redis Sentinel for High Availability: Configuration and Failover Guide

This guide explains how to configure Redis Sentinel to monitor master‑slave instances, automatically promote a slave on master failure, and verify the high‑availability setup with detailed configuration files, startup commands, status checks, and failover testing steps.

Full-Stack Internet Architecture
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Setting Up Redis Sentinel for High Availability: Configuration and Failover Guide

Sentinel is Redis's high‑availability (HA) solution that continuously monitors one or more master servers and their slaves, and automatically promotes a slave to master when a monitored master goes down.

The core functions of Sentinel are:

Monitoring – constantly checks the health of masters and slaves.

Notification – sends alerts via API when a server encounters problems.

Automatic failover – promotes a slave to master and redirects clients to the new master.

0x01: High‑Availability Sentinel Design

Configuration files are created based on redis.conf and sentinel.conf:

cp /usr/local/redis/etc/redis.conf /usr/local/redis/redis-6379.conf
cp /usr/local/redis/etc/redis.conf /usr/local/redis/redis-26379.conf
cp /usr/local/redis/etc/redis.conf /usr/local/redis/redis-26380.conf

Sentinel configuration files:

cp sentinel.conf /usr/local/redis/sentinel-36378.conf
cp sentinel.conf /usr/local/redis/sentinel-36379.conf
cp sentinel.conf /usr/local/redis/sentinel-36380.conf

Master configuration (redis‑6379.conf)

bind 127.0.0.1 192.168.122.1
port 6379
daemonize yes
pidfile /var/run/redis_6379.pid
logfile "/tmp/redis-6379.log"
dbfilename dump-6379.rdb
requirepass new2020

Slave‑1 configuration (redis‑26379.conf)

bind 127.0.0.1 192.168.122.1
port 26379
daemonize yes
pidfile /var/run/redis_26379.pid
logfile "/tmp/redis-26379.log"
dbfilename dump-26379.rdb
requirepass new2020
replicaof 127.0.0.1 6379
masterauth new2020

Slave‑2 configuration (redis‑26380.conf)

bind 127.0.0.1 192.168.122.1
port 26380
daemonize yes
pidfile /var/run/redis_26380.pid
logfile "/tmp/redis-26380.log"
dbfilename dump-26380.rdb
requirepass new2020
replicaof 127.0.0.1 6379
masterauth new2020

Sentinel‑1 configuration (sentinel‑36378.conf)

bind 127.0.0.1 192.168.122.1
protected-mode no
port 36378
daemonize yes
pidfile /var/run/redis-sentinel-36378.pid
logfile "/tmp/redis-36378.log"
dir /tmp/36378
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel auth-pass mymaster new2020
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

Sentinel‑2 and Sentinel‑3 configurations are identical except for the port numbers (36379, 36380) and corresponding pidfile, logfile, and dir values.

0x02: Starting Redis Services

Start the master:

/usr/local/redis/bin/redis-server /usr/local/redis/redis-6379.conf

Start the two slaves:

/usr/local/redis/bin/redis-server /usr/local/redis/redis-26379.conf
/usr/local/redis/bin/redis-server /usr/local/redis/redis-26380.conf

Start the three sentinel instances:

/usr/local/redis/bin/redis-sentinel /usr/local/redis/sentinel-36378.conf
/usr/local/redis/bin/redis-sentinel /usr/local/redis/sentinel-36379.conf
/usr/local/redis/bin/redis-sentinel /usr/local/redis/sentinel-36380.conf

Verify that all processes are running: ps -ef | grep redis 0x03: Checking Service Status

Use redis-cli info on the master to see role:master and two connected slaves. Run the same command on each slave to see role:slave. On each sentinel, info sentinel shows one master, three sentinels, and the number of slaves.

0x04: Validating Automatic Failover

Stop the master process (e.g., shutdown or kill -9).

Observe that one of the slaves (port 26379) is promoted to master in the sentinel output.

Restart the original master (port 6379) and verify it now appears as a slave using info replication.

Example commands used during the test:

ps -ef | grep redis
kill -9 7973
/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 36378
info sentinel
/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379
info replication

After the failover, the cluster operates with the new master and the former master functions as a replica, confirming that Redis Sentinel provides reliable automatic failover.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Operationsdatabasehigh availabilityredisConfigurationsentinelfailover
Full-Stack Internet Architecture
Written by

Full-Stack Internet Architecture

Introducing full-stack Internet architecture technologies centered on Java

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.