Redis 5 : Configure Redis Sentinel2021/05/28 |
Configure Redis Sentinel to provide high availability for Redis Servers.
This example is based on the environment like follows.
If Primary Node would be down, Master role will failover to other Replica Node. | +----------------------+ | +----------------------+ | [ Redis Sentinel ] |10.0.0.30 | 10.0.0.31| [ Redis Primary ] | | dlp.srv.world +----------+----------+ www.srv.world | | | | | | +----------------------+ | +----------------------+ | +----------------------+ | +----------------------+ | [ Redis Replica#1 ] |10.0.0.51 | 10.0.0.52| [ Redis Replica#2 ] | | node01.srv.world +----------+----------+ node02.srv.world | | | | | +----------------------+ +----------------------+ |
[1] |
Configure replication Settings on all Nodes, refer to here.
Points to be aware of regarding replication settings, it needs to set the same authentication password on all Nodes. |
[2] | For Redis HA with Sentinel, if SELinux is enabled on Primary/Replica Nodes, it needs to add rules like follows. Add follows on All Nodes. |
[root@www ~]# semanage fcontext -a -t redis_conf_t /etc/redis.conf [root@www ~]# restorecon /etc/redis.conf |
[3] | Configure Sentinel Server. |
[root@dlp ~]#
dnf module -y install redis:5
[root@dlp ~]#
vi /etc/redis-sentinel.conf # line 26 : change (start service) daemonize yes
# line 84 : change # [sentinel monitor (any name) (Primary's IP) (Primary's Port) (Quorum)] # Quorum ⇒ run failover when the specified number of Sentinel servers look Primary is down sentinel monitor mymaster 10.0.0.31 6379 1
# line 104 : authentication password for Primary Node
sentinel auth-pass mymaster password
# line 113 : the duration Sentinel server looks Primary is down (30 sec by default below) sentinel down-after-milliseconds mymaster 30000 # line 121 : number of Replicas to be changed when running failover sentinel parallel-syncs mymaster 1 systemctl enable --now redis-sentinel |
[4] | That's OK, verify status on Sentinel server like follows. Furthermore, stop Redis manually on Primary Node and make sure Primary/Replica failover normally. |
[root@dlp ~]# redis-cli -p 26379 # show Primary Node for [mymaster] 127.0.0.1:26379> sentinel get-master-addr-by-name mymaster 1) "10.0.0.31" 2) "6379" # show details of Primary Node for [mymaster] 127.0.0.1:26379> sentinel master mymaster 1) "name" 2) "mymaster" 3) "ip" 4) "10.0.0.31" 5) "port" 6) "6379" 7) "runid" 8) "a45ecbf4af4d744dff207147105827e9f1527135" 9) "flags" 10) "master" ..... ..... # show Replica Nodes for [mymaster] 127.0.0.1:26379> sentinel slaves mymaster 1) 1) "name" 2) "10.0.0.52:6379" 3) "ip" 4) "10.0.0.52" 5) "port" 6) "6379" 7) "runid" 8) "2404e2d1bd2b5cdc7ef43c5efeabe4c38037534c" 9) "flags" 10) "slave" ..... ..... 2) 1) "name" 2) "10.0.0.51:6379" 3) "ip" 4) "10.0.0.51" 5) "port" 6) "6379" 7) "runid" 8) "fff20e3e0322e57831be21d88cd777652f7b6a48" 9) "flags" 10) "slave" ..... ..... |
Sponsored Link |
|