redis-sentinel- Sentinel cluster - a simple deployment

The main function of Redis Sentinel

The main function of the master node comprises a Sentinel survival detected, the master-slave operation is detected, automatic failover (failover), the master-slave switching. Redis Sentinel is a minimum configuration from a master.

The Redis Sentinel system can be used to manage multiple Redis server, the system can perform the following four tasks:

monitor

Sentinel will continue to check whether the primary server and from the server to run properly.

Notice

When a monitored Redis server problem, Sentinel send notifications to the administrator or other applications through the API script.

Automatic failover

When the master node does not work, the Sentinel will start an automatic failover operation, it sends the failure of the master node is a master-slave relationship in which a new master node from upgraded, and the other from the node point to the new primary node.

Configuration Provider

In the Redis Sentinel mode, the client application in connection initialization is Sentinel node set, obtain information from the master node.

Subjective and objective offline offline

By default, each Sentinel node transmits a frequency of once per second PING command Redis Sentinel node and other nodes, and determines whether the node to reply online nodes.

Subjective offline

Subjective offline for all master node and slave node. If the down-after-milliseconds milliseconds, the Sentinel did not receive a valid response destination node, the node will be determined offline subjective.

Objective offline

Objective offline only applies to the master node. If the primary node fails, by Sentinel node sentinel is-master-down-by-addr command inquiry to other Sentinel node determines the state of the node. If more than The master node determines the node number is not reachable, the master node determines Sentinel node objective offline.

The organization chart below

master, slave profile contents

# cat 6380/redis-6380.conf

port 6380
logfile ""
#调试时可打开日志
#logfile "./redis-6380"
#守护进程模式
daemonize yes
bind 127.0.0.1


# cat 6381/redis-6381.conf 

port 6381
logfile "./redis-6381"
daemonize yes
replicaof 127.0.0.1 6380
bind 127.0.0.1

sentinel profile contents

cat 26379/redis-sentinel.conf


port 26379
# 守护进程模式
daemonize yes
pidfile /var/run/redis-sentinel.pid
logfile ""
#调试时可打开日志
#logfile /var/log/redis/sentinel.log
dir /tmp
# 哨兵监控这个master,在至少quorum个哨兵实例都认为master down后把master标记为odown
# (objective down客观down;相对应的存在sdown,subjective down,主观down)状态。
# slaves是自动发现,所以你没必要明确指定slaves。
sentinel monitor mymaster 127.0.0.1 6380 2
# master或slave多长时间(默认30秒)不能使用后标记为s_down状态。
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
# 若sentinel在该配置值内未能完成failover操作(即故障时master/slave自动切换),则认为本次failover失败。
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes

cat 26380/redis-sentinel.conf

port 26380
daemonize yes
pidfile /var/run/redis-sentinel.pid
logfile /var/log/redis/sentinel.log
dir /tmp
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
bind 127.0.0.1
 
cat 26381/redis-sentinel.conf

port 26381
daemonize yes
pidfile /var/run/redis-sentinel.pid
logfile /var/log/redis/sentinel.log
dir /tmp
sentinel monitor mymaster 127.0.0.1 6380 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
bind 127.0.0.1

Start each service

redis-server 6380/redis-6380.conf 
redis-server 6381/redis-6381.conf 
redis-server 26379/redis-sentinel.conf --sentinel
redis-server 26380/redis-sentinel.conf --sentinel
redis-server 26381/redis-sentinel.conf --sentinel
#启动后配置文件会被修改

Verifying the cluster state

#连接到sentinel节点

redis-cli -h 127.0.0.1 -p 26381

#查询主节点状态

127.0.0.1:26381> SENTINEL get-master-addr-by-name mymaster
1) "127.0.0.1"
2) "6380"


127.0.0.1:26381> SENTINEL slaves mymaster
127.0.0.1:26381> SENTINEL sentinels mymaster
#第一个将提供有关连接到主服务器的从服务器的类似信息,
#第二个将提供有关其他Sentinel的信息。

#查询哨兵状态

127.0.0.1:26381> info sentinel
# Sentinel

sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6380,slaves=1,sentinels=3

#模拟故障  关闭主节点进程
#再次查询

127.0.0.1:26381> SENTINEL get-master-addr-by-name mymaster
1) "127.0.0.1"
2) "6381"

#成功切换
#验证成功

Reference material

https://www.cnblogs.com/bingshu/p/9776610.html blog
https://redis.io/topics/sentinel official website data

Guess you like

Origin www.cnblogs.com/66li/p/12058737.html