The setup
I have a failover redis setup that consists of three sentinels and two redis servers, which are all on separate boxes.
The setup looks like :
-------------------
| Sentinel1 - AMS |\
------------------- \ ---------------------------
| -/| Redis Server1 (M) - FRA |
------------------- / ---------------------------
| Sentinel2 - FRA |--
------------------- \ ---------------------------
| -\| Redis Server2 (S) - AMS |
------------------- / ---------------------------
| Sentinel3 - LON |/
-------------------
All sentinels and servers can see each other via VPN.
The configuration for the sentinels is :
# Ansible managed
daemonize yes
pidfile "/var/run/redis/redis-sentinel.pid"
logfile "/var/log/redis/redis-sentinel.log"
# Note the ip changes for each sentinel - 12,13,14
bind 192.168.1.14
port 26379
dir "/var/lib/redis"
sentinel monitor q-redis-01 192.168.1.10 6379 2
sentinel down-after-milliseconds q-redis-01 10000
sentinel auth-pass q-redis-01 XXX
And the excerpt configuration for the redis servers is :
# Ansible managed
daemonize yes
pidfile "/var/run/redis/redis-server.pid"
port 6379
tcp-backlog 511
# Note the ip changes for each server - 10, 11
bind 192.168.1.10
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/var/log/redis/redis-server.log"
databases 10
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/var/lib/redis"
masterauth "XXX"
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
# Note Server 1 has priority 10 and Server 2 has 20
slave-priority 10
requirepass "XXX"
...
As the configuration in Server2 I also have this line :
slaveof 192.168.1.10 6379
The problem
The setup works and when Server 1 is unreachable, Server 2 is promoted to master.
What I want to achieve though is when Server 1 recovers, I want to become the master again automatically.
I need this to happen, because the datacenter of FRA is closer to the rest of the infrastructure and the whole setup is used for failover, not for scalability.
The question
Is it possible to configure the redis sentinels to promote back a recovered master node to be the master in the group automatically?