Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Principle of Redis Sentinel Mode

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Principle of Redis Sentinel Mode

Sentinel mode is a special mode. First of all, Redis provides the command of Sentinel. Sentinel is an independent process, which runs independently as a process. The principle is that Sentinel sends commands and waits for a response from Redis server to monitor multiple Redis instances running.

Linux-redis Sentinel Cluster instance

Command arrangement

Official website address: http://redisdoc.com/

Redis-cli info # View redis database information redis-cli info replication # View redis replication authorization information redis-cli info sentinel # View redis Sentinel information

Configuration proc

Train of thought:

Redis master and slave

The plan of one master and two slaves

1. Environment preparation, prepare the redis architecture of one master and two slaves

Redis-6379.conf

Port 6379daemonize yeslogfile "6379.log" dbfilename "dump-6379.rdb" dir "/ opt/redis/6379/" redis-6380.confport 6380daemonize yeslogfile "6380.log" dbfilename "dump-6380.rdb" dir "/ opt/redis/6380/" slaveof 127.0.0.1 6379redis-6381.confport 6381daemonize yeslogfile "6381.log" dbfilename "dump-6381.rdb" dir "/ opt/redis/6381/" slaveof 127.0.0.1 6379

two。 Prepare three data folders

Mkdir-p / opt/redis/ {6379pr 6380pl 6381}

three. Start three databases respectively

[root@master sbredis] # redis-server redis-6379.conf [root@master sbredis] # redis-server redis-6380.conf [root@master sbredis] # redis-server redis-6381.conf

4. Detect master-slave status

Redis-cli-p 6379 info replicationredis-cli-p 6380 info replicationredis-cli-p 6381 info replication

5. Prepare three redis sentinels to check the master-slave status.

Prepare the configuration files for the three sentinels

Redis-26379.conf

/ / Sentinel node port port 26379 dir / var/redis/data/logfile "26379.log" / / current Sentinel node monitoring 192.168.119.10 26379.log 6379 this master node / / 2 indicates that at least two Sentinel nodes are required to agree / / mymaster is the alias sentinel monitor mymaster 192.168.119.10 6379 2 of the master node to determine whether the Redis data node and the rest of the Sentinel node are reachable by periodic PING commands If it exceeds 30000 milliseconds for 30s and there is no reply, it is determined that the sentinel down-after-milliseconds mymaster 3000max is unreachable / when the Sentinel node set agrees on the failure determination of the master node, the Sentinel leader node will do the failover operation and select the new master node, and the original slave node will initiate a copy operation to the new master node. Limit the number of slaves that initiate a replication operation to a new master node to 1sentinel parallel-syncs mymaster 1 1sentinel parallel-syncs mymaster / failover timeout is 180000 Ms sentinel failover-timeout mymaster 180000redis-26380.confport 7000daemonize yesdir "/ opt/data" logfile "7000.log" dbfilename "dump-7000.rdb" cluster-enabled yes cluster-config-file nodes-7000.confcluster-require-full-coverage noredis-26381.conf

Three configuration files, just different ports, quickly generate configuration files through commands

[root@master sbredis] # sed "redis-26379.conf 26379 Universe 26380max" redis-26379.conf > redis-26380.conf [root@master sbredis] # sed "sqr 26379 Universe 26381gamg" redis-26379.conf > redis-26381.conf

6. Activate three sentinels respectively.

[root@master sbredis] # redis-sentinel redis-26379.conf [root@master sbredis] # redis-sentinel redis-26380.conf [root@master sbredis] # redis-sentinel redis-26381.conf

7. Detect sentinel, master-slave status

Redis-cli-p 26379 info sentinel

When you see the following message, it's just like me.

[root@master sbredis] # redis-cli-p 26379 info sentinelSentinelsentinel_masters:1sentinel_tilt:0sentinel_running_scripts:0sentinel_scripts_queue_length:0sentinel_simulate_failure_flags:0master0:name=s17ms,status=ok,address=127.0.0.1:6379,slaves=2,sentinels=3

8. Quiz, kill master redis, whether to switch automatically

Ps-ef | grep redis kill process..

9. Start redis 6379 again to see if it joins the master-slave cluster.

Redis-server redis-6379.conf

These are the details of the principle of Redis Sentinel mode, please pay attention to other related articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report