Redis Sentinel mode to achieve high availability cluster

  First look at what has been done Sentinel are: the Redis Redis Sentinel system for managing multiple servers (instance), the system performs the following three tasks:

  • Monitoring (Monitoring ): Sentinel will continue to check your server if the primary server and from functioning properly.
  • Remind (the Notification) : When monitoring a Redis server problem, Sentinel can send notifications to the administrator or other applications via the API.
  • Automatic failover (Automatic failover) : when a primary server is not working properly, Sentinel will automatically start a failover operation, it will fail the primary server upgrade from one server to the new master server, and let the failure of the primary server other copied from the server to the new primary server; when the client attempts to connect to the primary server fails, the cluster will return to the client address of the new primary server side, so that the new master cluster may be used instead of the failed server.

   Redis Sentinel is a distributed system, you can run multiple processes Sentinel (progress) in a framework, these processes use rumors protocol (gossip protocols) to receive information on the master server is offline, and use the voting agreement (agreement protocols ) to decide whether to perform automatic failover, and choose which from the server as the new master.

   Redis Sentinel (Sentinel) there is a separate executable file redis-sentinel, but it is actually just a Redis server in a special mode of operation, by Redis Sentinel redis to monitor a cluster, then automatically fail if the cluster fails migrate.

  For Redis Sentinel, there are two start-up mode, as follows: 

  For redis-sentinel program, you can use the following command to start the Sentinel system:

redis-sentinel /path/to/sentinel.conf

  For redis-server program, you can start the Redis server running in a Sentinel mode with the following command:

redis-server /path/to/sentinel.conf --sentinel

The present embodiment is implemented in three architectures redis, three sentinel

node IP port
redis1 127.0.0.1 7000(master)
redis2 127.0.0.1 7001(slave)
redis3 127.0.0.1 7001(slave)
redis-sentinel1 127.0.0.1 26379
redis-sentinel2 127.0.0.1 26380
redis-sentinel3 127.0.0.1 26381

 

 

 

 

 

  First, configure the cluster redis

  It 1. Opens the configuration from the master node of
  the master node: New redis-7000.conf
    configuration:

port 7000
daemonize yes
pidfile /var/run/redis-7000.pid
logfile "7000.log" 
dir "/root/redis/data"

    Start: redis-server redis-7000.conf

  From node: New redis-7001.conf and redis-7002.conf file
  slave1 configuration:

port 7001
daemonize yes
pidfile /var/run/redis-7001.pid
logfile "7001.log"
dir "/root/redis/data"
slaveof 127.0.0.1 7000

  slave2 configuration:

port 7002
daemonize yes
pidfile /var/run/redis-7002.pid
logfile "7002.log"
dir "/root/redis/data"
slaveof 127.0.0.1 7000

    Start: redis-server redis-7001.conf

       redis-server redis-7002.conf

  Verify redis clusters: After logging redis1 info replication, its role as master

 

After logging redis2 info replication, he found the role of role: slave, whose main master_host: 127.0.0.1, master_port: 7000

 

   The situation with the situation redis3 redis2 is the same, can increase data redis1, and then in the node 2 and 3 to see if the synchronization is successful, the node 2 and 3 can only read, not write permissions and other operations to verify the cluster correctness.

  Second, the configuration of the main monitor turned sentinel node (sentinel is a special Redis)

    1. Configure three sentinel nodes

New three profiles: redis-sentinel-26379.conf, redis-sentinel-26380.conf, redis-sentinel-26381.conf

port 26379
daemonize yes
dir "/root/redis/data"
logfile "26379.log"
sentinel monitor mymaster 127.0.0.1 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
port 26380
daemonize yes
dir "/root/redis/data"
logfile "26380.log"
sentinel monitor mymaster 127.0.0.1 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
port 26381
daemonize yes
dir "/root/redis/data"
logfile "26381.log"
sentinel monitor mymaster 127.0.0.1 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000

Respectively above manner three start sentinel: redis-sentinel redis-sentinel-26379.conf

               redis-sentinel  redis-sentinel-26380.conf

               redis-sentinel  redis-sentinel-26381.conf

Check whether the three guards started successfully:

  After three sentinel start, you can log in as login redis as sentry, but the sentry had his own API, many commands such as increased data sentinel is not recognized. Then we log into any of the eleven check the info about each sentry, you can see the amount of information as well as slaves and sentinel of the master from the figure below.

 

   Then there is a problem, we did not start when the sentinel node redis slave configuration and other sentinel nodes Sentinel is a slave and discover how other sentinel of it? In fact, is achieved through a publish-subscribe message inside, we look at the official explanation:

  Sentinel automatically discover and from the server

  Sentinel can be connected to a plurality of other Sentinel, can check each other's availability Sentinel each other, and exchange information.

  Each Sentinel You do not need to run to set the address of each other Sentinel, because Sentinel can automatically discover other being monitored by the Sentinel same primary server to publish and subscribe capabilities, this feature is through the channel  Sentinel : the Hello send information to implement the .

  Similarly, you do not have to manually list all from the primary server under the server, because the Sentinel can get all the information from the server by querying the master server.

  • Sentinel will each frequency of once every two seconds through a publish and subscribe capabilities to be used by all the main server and from the server it is monitoring the  Sentinel : Send a message hello channel, the information contained in the Sentinel IP address, port number, and run ID (runid).
  • Each Sentinel subscribe to all the primary server and from the server it is monitoring the  Sentinel : the 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, the list contains the Sentinel known, monitored with a primary server for all other Sentinel.
  • Sentinel transmitted information further comprises the complete master of the current configuration (configuration). If the primary server contains a Sentinel Configuration is older than the other sent Sentinel, Sentinel then this will immediately upgrade to the new configuration.
  • Before a new Sentinel added to monitor the primary server in the list above, Sentinel will check whether the list already contains Sentinel and you want to add Sentinel has the same run ID or the same address (including IP address and port number), and if then, Sentinel Sentinel will first remove the list of those who have run the same ID or the same address already, then add the new Sentinel.

 When we started automatically after the completion of Sentinel writing information and other slave nodes redis Sentinel node to its profile, i.e. sentinel profile changes, in the present embodiment is as follows:

port 26380
daemonize yes
dir "/root/redis/data"
logfile "26380.log"
sentinel myid 60ee52fc339d6713cf01429295333abc52af4c6b
sentinel monitor mymaster 127.0.0.1 7000 2
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 127.0.0.1 7001
sentinel known-slave mymaster 127.0.0.1 7002
sentinel known-sentinel mymaster 127.0.0.1 26381 06f16eb142ee0895dedd769d2d5072c7d682cc50
sentinel known-sentinel mymaster 127.0.0.1 26379 b0f4c698b611b92fb406f3a04815b0536baed055
sentinel current-epoch 0

  So far our Redis Sentinel model to build complete, conduct some verification, kill redis 7000 port, automatic failover look Sentinel transfer will be successful.

 

 

  master becomes the port number redis 7001, the function can be used normally, so sentinels for us to complete failure redis clusters of automatic transfer.

Guess you like

Origin www.cnblogs.com/hopeofthevillage/p/11499532.html