Redis Sentinel Mechanism

Redis Sentinel physical structure diagram

Role IP Port alias
master 127.0.01 6379 master node
slave-1 127.0.01 6380 slave-1 node
slave-2 127.0.01 6381 slave-2 node
sentinel-1 127.0.01 26379 sentinel-1 node
sentinel-2 127.0.01 26380 sentinel-2 node
sentinel-3 127.0.01 26381 sentinel-3 node

1. Start the master node

Configuration:

port 6379

daemonize yes

logfile “6379.log”

dbfilename “dump-6379.rdb”

dir “/opt/soft/redis/data/”

Start the master node, and use the following command to verify that the master node has started successfully:

redis-cli -h 127.0.0.1 -p 6379 ping

The topology diagram at this time is as follows:

2. Start two slave nodes

Configuration:

Same as the master node, just add one: slaveof 127.0.0.1 6379

Start two slave nodes and verify that the startup is successful.

3. Confirm the master-slave relationship

Master node perspective, use the info command to view

From the node perspective, use the info command to view

The topology diagram at this time is as follows:

4. Configure the sentinel node

Configuration:

port 26379

daemonize yes

dir /opt/soft/redis/data

sentinel monitor mymaster 127.0.0.1 6379 2

sentinel down-after-milliseconds mymaster 30000

sentinel parallel-syncs mymaster 1

sentinel failover-timeout mymaster 180000

  1). The default port of Sentinel node is 26379.

  2). Sentinel monitor mymaster 127.0.0.1 6379 2 configuration means that the sentinel-1 node needs to monitor the master node 127.0.0.1:6379, 2 means that at least 2 sentinel nodes are required to judge the failure of the master node, and mymaster is the alias of the master node.

5. Start the sentinel node

Configure the remaining two sentinel nodes as described above, and then start them separately

redis-sentinel redis-sentinel-26379.conf

6. Confirm

redis-cli -h 127.0.0.1 -p 26379 info sentinel

7. The final topology diagram is as follows:

8. Verification

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325068204&siteId=291194637