Sentinel mode

First, Sentinel mode

1. The main function

There are two main functions Sentinel:
  A, monitors all node database is running properly.
  b, when the master database fails, you can automatically by voting mechanism, from the slave node to elect a new master, to achieve automatic switching from the database into a primary database.
After the Master-Slave switch, master_redis.conf, slave_redis.conf and sentinel.conf content will change, that will be more in line slaveof master_redis.conf configuration, monitoring target sentinel.conf will follow the exchange.

Redis Sentinel system for managing multiple Redis server, the system performs the following three tasks:
  A, monitoring (Monitoring): Sentinel (sentinel) will continue to check if your Master and Slave functioning properly.
  b, remind (Notification): When monitoring a Redis problems, Sentinel (sentinel) can send notifications to the administrator or other applications via the API.
  c, automatic failover (Automatic failover): When a Master does not work, Sentinel (sentinel) will start an automatic failover operation, it will be one of the Slave Master failure upgraded to the new Master, and let the failure of Master other Slave changed to copy the new Master; when a client attempts to connect Master fails, the cluster will return to the client-side address of the new Master, making the cluster can be used instead of the failed Master Master.

2. work

1) Each Sentinel transmitting a PING command to Master, Slave, and other examples Sentinel a frequency of once per second to its art.
2) If an instance (instance) from the last valid reply time exceeds the value of the PING command own-after-milliseconds specified by the option, then the instance is marked subjective Sentinel offline.
3) If a Master is marked as subjective offline, all this is being monitored to be sure the Master Sentinel Master indeed entered a subjective offline state once per second.
4) When a sufficient number of Sentinel (equal to a value greater than the specified configuration file) into the subjective confirmation Master does offline state, the Master will be marked offline objective within a specified time frame.
5) All Master In general, each Sentinel it will be known to a frequency of once every 10 seconds, the Slave sends an INFO command.
6) When the Master Sentinel objective is marked offline, Sentinel all frequencies of the offline Master Slave sends an INFO command will be changed once every second from 10 seconds.
7) If there is not enough number of Master Sentinel consent has been off the assembly line, the objective offline Master status will be removed. If the Master valid responses to the Sentinel return to the PING command, Master subjective offline status will be removed.

 

Subjective offline
Sentry (the Sentinel) once a second node to send the PING command to establish an example of a command connection, if there is no response to respond effectively comprises (PONG / LOADING / MASTERDOWN) in the down-after-milliseconds milliseconds except Sentinel will state the structural body in the present example is marked as offline SRI_S_DOWN subjective
and objective offline
when a master node is found in the sentinel node subjective offline state, it will issue a query to the other sentinel node, which is not It has been subjective off the assembly line. If more than one node quorum configuration parameters considered subjective offline, the sentinel node will own the structure is maintained in the master node labeled SRI_O_DOWN objective offline

 

3. advantages and disadvantages

Advantages: high availability, if the primary node fails to achieve branch hazards
drawbacks:
  1) seems to be no way to do the level of development, under circumstances, if a lot of content.
  2) from the primary data server to the master copy frequently, such performance degradation caused.
  3) When the primary server goes down, the switching from the primary server to the server that time, the service can not be used.

Second, separate read and write mode Sentinel

The Sentinel mode, the client generally two connection remains connected to the sentinel, and connecting the master. Of course, operation using the master data connection, if the master fails, the current address can be obtained by connecting the master sentinel.

General client connection process is as follows:

  1. Sentinel connection, the master ip and port acquired based on the name of the master.

  2. Connect master via ip and port.

In addition, some of the company's own package redis client can be obtained by the master and slaves sentinel, using separate read and write, read slaves, write master.

Third, build Sentinel mode

We need to have a master-slave environment, with the main front has 2 master-slave from the environment.

1.sentinel build process

mkdir / Data / 26380 
CD / Data / 26380 
Vim sentinel.conf 
Port 26380 
the dir " / Data / 26380 " 
sentinel Monitor mymaster 127.0 . 0.1  6380  . 1            #. 1 represents the number of sentinel, when there are large redis clusters, a plurality of sentinel when there is a sentinel believe that a redis master is down, then it goes down, the switchover from 
sentinel Down - the After - milliseconds mymaster 5000       # 5000 milliseconds down the main library, start switch 
sentinel auth - Pass mymaster 123456  

start : 
[DB01 26380 @ root ] # Redis - sentinel / the Data / 26380 / sentinel.conf   &> / tmp / . sentinel log  & 

if there is a problem: 
1 ) re-prepare main environmental 2
 2 out of sentinel process) the kill
 3 ) Delete sentinel directory All files under
 4 ) re-build sentinel
View Code

2. After the build is completed, the test

Redis - CLI - P 6380  - A 123456  the shutdown 
Redis - CLI - P 6381  - A 123456 info Replication  

starting the main library source ( 6380 ), see state. 
Redis - Server / Data / 6380 / redis.conf 
Redis - CLI - P 6380  - A 123456 info Replication  

the Sentinel management commands: 
Redis - CLI - P26380 
PING: return PONG. 
SENTINEL masters: List all the main server being monitored 
SENTINEL slaves < Master name >  

SENTINEL GET - Master - addr - by - name < Master name > : IP address and port number to return the given name of the primary server. 
RESET SENTINEL < pattern > : Reset all the names in a given pattern, and pattern matching primary server. 
Failover SENTINEL < Master name > : When the primary server fails, without asking other Sentinel opinion, forced to start an automatic failover.
View Code

 

 

Guess you like

Origin www.cnblogs.com/xufengnian/p/11920633.html