Redis Sentinel high availability mode

In the daily Redis under the master-slave mode, we generally read and write in order to achieve the separation, it will not only improve efficiency, while at the master fails, we closed the slave read-only mode that enables applications to connect slave complete service of normal use . Sentinel helps us to switch automatically.
Sentinel is independent of the service Redis-server to run a distributed. When Sentinel deployment is no need to modify any redis configuration. Sentinel can during operation, whether to detect redis cluster master and slave state, when it is judged there is node failure, notification may be issued by Sentinel API itself or other applications, voting by a plurality of Sentinel manner, failover. The other a slave server to a master. Failure to replace the master. Finally Sentinel service back to the client a new address. Protect applications running.

heel

Sentinel Installation and Configuration

Here to distinguish between different ports, do not open too many servers the

Redis Redis service to build a master-slave architecture master-slave replication, in which the Master is 192.168.1.1, there is not a demonstration, will not go left to see

Configuring Sentinel

Sentinel template configuration files in Redis source package, you can copy it changes can be directly written without template

port 26379       ## 端口
daemonize yes      ## 后台启动
dir /soft/redis/data    ## 工作目录
logfile "/soft/redis/log/sentinel.log"    ## 日志目录
sentinel monitor mymaster 192.168.1.1 6379 2   ## 监控master,当判断失效时,至少需要2个sentinel判定master失败才可以。
sentinel down-after-milliseconds mymaster 10000    ## Sentinel 判断master失效的时间,单位为毫秒。
sentinel parallel-syncs mymaster 1   # 故障转移后每次有多少个slave向slave发起复制请求。
sentinel failover-timeout mymaster 60000  #1、同一个Sentinel对同一个master两次tailover的间隔。

#########################我是分割线#########################
#以下配置是当所有Sentinel节点启动之后,自动写入的配置

//自动发现的两个slave节点
sentinel konwn-slave mymaster 192.168.1.2 6379
sentinel konwn-slave mymaster 192.168.1.3 6379
//自动发现的两个Sentinel节点
sentinel known-sentinel mymaster 192.168.1.2 26379 814149a8600fede18177b7cc0611a86eab61699c
sentinel known-sentinel mymaster 192.168.1.3 26379  9ec521108aacc04347b0b5aa36d32680f394dc4b
sentinel current-epoch 0 #当前配置信息版本,如果配置文件发生变化,版本信息也会变化。

Start Sentinel

## 第一种启动方式(推荐)
[root@Master ~]# /soft/redis/bin/redis-sentinel /soft/redis/conf/sentlnel.conf 
## 第二种启动方式
[root@Master ~]# /soft/redis/bin/redis-server /soft/redis/conf/sentlnel.conf --sentinel

After three servers are configured to start to see the profile Sentinel, the extra information found in other roles.

Sentinel works explain

1) Each Sentinel server generally requires a frequency of once every 10s interval sends an INFO command to have the master and slaves. This task can be found by Slaves whether to add or delete nodes. When a Master is marked as offline, it will be modified to transmit a second command.

2) Each Sentinel send a frequency of once per second to the known master, slaves and other examples Sentinel pingcommand. If the pingcommand can not get a valid reply, and exceeds the value of down-after-milliseconds since the last option set response time, it will be marked as offline subjectively

3) Each Sentinel frequency will once every 2 seconds, by the publish-subscribe function, it monitors are all master server and send hello packet from Sentinel server information includes IP address of Sentinel, and port number to the other run ID (runid)

How to find the Slave Redis-Server

1. tasks 1, transmission INFOcommand, by analyzing INFOthe return value of the command, the Slave node discovery, monitoring and Slave. That is why the Sentinel configuration, no reason Redis-Server configuration information from the nodes.

2. Information topology INFOcommand to view the Redis-Server topology occurs when the main switch, or remove nodes from an increase, can be updated in real time to the monitoring list of Sentinel.

How to find other nodes Sentinel

1. Each Sentinel 3 mission are subscribed to by all the main server that monitors and from Sentinel server: hello channel, has not been seen before look Sentinel (looking for unknown sentinels). When a Sentinel found a new Sentinel, Sentinel it will add to a new list, and create connected to the node, the list contains the Sentinel known, monitored with a primary server for all other Sentinel.

2.Sentinel transmitted information further comprises the complete master server's current configuration. If a primary server configuration than the configuration Sentinel Sentinel contains sent to the old, then the Sentinel will update the configuration immediately.

The master node status information exchange between 3.Sentinel node, will be based on objective behind off the assembly line as well as a leader in the elections.

How to determine node fails

1. Through the above task, we can discover new Redis-Server node, you can also get the latest information, and access to the Sentinel node information.

2. timer task 2, per Redis-Server to the Master and Slave nodes. As well as other Sentinel node sends pingcommands.

3. the heartbeat of each node to achieve control of each node (Redis and Sentinel) by, this task is to determine the failed node important basis.

4. example Sentinel-1 was found down-after-milliseconds time period is not more than a node corresponding valid responses, Sentinel node failure is determined and marked offline. This behavior is called subjective offline.

Sentinel node 5. When the offline redis subjective when the master, the master determines asks Sentinel node to other nodes through the Sentinel sentinel is master-down-by-addr command. When more than the set number of votes (our three nodes, set 2 votes, forget recap front configuration), the node will make a decision of objective offline. Once off the assembly line after an objective judgment, behind everyone knows, we begin switched.

Guess you like

Origin www.cnblogs.com/songguoyou/p/11884192.html