CentOS Stream 9
Sponsored Link

Valkey : Configure Sentinel2024/12/04

 

Configure Valkey Sentinel to provide high availability for Valkey Servers.

This example is based on the environment like follows.
If Primary Node would be down, Master role will failover to other Replica Node.

                                   |
+-----------------------+          |          +-----------------------+
|  [ Valkey Sentinel ]  |10.0.0.25 | 10.0.0.30|   [ Valkey Primary ]  |
|    ctrl.srv.world     +----------+----------+     dlp.srv.world     |
|                       |          |          |                       |
+-----------------------+          |          +-----------------------+
                                   |
+-----------------------+          |          +-----------------------+
| [ Valkey Replica#1 ]  |10.0.0.51 | 10.0.0.52|  [ Valkey 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 Valkey HA with Sentinel, if SELinux is enabled on Primary/Replica Nodes, it needs to add rules like follows. Add follows on All Nodes.
[root@dlp ~]#
semanage fcontext -a -t redis_conf_t /etc/valkey/valkey.conf

[root@dlp ~]#
restorecon /etc/valkey/valkey.conf

[3] Configure Sentinel Server.
# install from EPEL

[root@ctrl ~]#
dnf --enablerepo=epel -y install valkey
[root@ctrl ~]#
vi /etc/valkey/sentinel.conf
# line 15 : change (start service)

daemonize
yes
# line 92 : 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.30 6379 1
# line 112 : authentication password for Primary Node

sentinel auth-pass mymaster password
# line 133 : the duration Sentinel server looks Primary is down (30 sec by default below)

sentinel down-after-milliseconds mymaster 30000
# line 205 : number of Replicas to be changed when running failover

sentinel parallel-syncs mymaster 1
[root@ctrl ~]#
systemctl enable --now valkey-sentinel

[4] That's OK, verify status on Sentinel server like follows.
Furthermore, stop Valkey manually on Primary Node and make sure Primary/Replica failover normally.
[root@ctrl ~]#
valkey-cli -p 26379

# show Primary Node for [mymaster]
127.0.0.1:26379> sentinel get-master-addr-by-name mymaster 
1) "10.0.0.30"
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.30"
 5) "port"
 6) "6379"
 7) "runid"
 8) "a50abe9ce8a97f4f3504522a9c182adc1b987c95"
 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) "89978588a6f65d43a518e43ba8af2cca1a359bb8"
    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) "fe90c2d972795e4cb91f8074fc1b0a7c43047b36"
    9) "flags"
   10) "slave"
   .....
   .....
Matched Content