当前位置:网站首页>Set up redis sentinel cluster (instance):

Set up redis sentinel cluster (instance):

2022-06-12 08:47:00 Wu Yu

The premise of setting up sentinel mode is to set up Redis Master slave copy :

Redis Master slave replication principle :

Redis Support master-slave synchronization . Data can be synchronized from the master server to any number of slaves , A slave server can be the master server associated with other slaves . This makes Redis Single-layer tree replication can be performed . The slave disk can write data intentionally or unintentionally . Due to the full implementation of the release / Subscribe mechanism , Enables trees to be synchronized anywhere from the database , Subscribe to a channel and receive a complete record of message publication from the master server . Synchronization helps with scalability and data redundancy for read operations .

 

Copy in full : And in the slave After the service receives the database file data , Save it and load it into memory .

Incremental replication : On the basis of full replication for the first time, during synchronization for the second time , Only the incremental places will be synchronized , And the slave does not have permission to modify data , The slave is mainly used to read data , The host is used to modify data .

Build master-slave architecture :

Prepare three servers :

Host server :192.168.181.5

Slave server : 192.168.181.4; Slave server : 192.168.181.6

The first is to install the same version of on three hosts Redis service .

  1. Configure the host server :

modify redis Configuration file for ,redis.conf . take bind 127.0.0.1 This line is annotated , Or specify ip Address . If you specify ip, Only this host can be connected , And the annotation is the link of the whole network segment .

2/ Start Daemons : daemonize yes

3/ Modify the module configuration as shown in the figure : Protected-mode It's to ban public access redis cache, To strengthen redis Safe . Shut down , The whole network segment can access .

 

4/ Set access password :

 

5/ Configure slave : The previous operations are basically the same as the primary server configuration .

6/ Configure the master server ip And port

 

Here, configure the password of the master server ,. Then test :

Add data to the host :

 

 

View data from the computer :

 

Be careful ; The slave can only be used to read data , Can't write data , Use set command . Will report a mistake .

So far, the master-slave replication configuration is completed ,

Sentinel mode

The technical method of master-slave switching is : When the primary server goes down , You need to manually switch one from the server to the primary server , This requires human intervention , Laborious and arduous , It will also make the service unavailable for a period of time ,, Sentinel mode : It is to solve this problem that .

Definition :

sentry (Sentinle) It's for monitoring redis In the cluster Master State tools , yes Redis High availability solutions for ,

sentinel Sentinel mode has been integrated into redis2.4 Later versions .sentinel The system can monitor one or more redis master service , And these master All of the services slave; When a master When the service is offline , The master Under the slave Upgrade to master Services replace offline master The service continues to process the request .

sentinel It can make Redis Implement master-slave replication , When a cluster of master After the failure ,sentinel A new one can be elected master For automatic replacement master The job of , Others in the cluster Redis The server automatically points to the new master Synchronous data ,. It is generally recommended that the cardinality be too , Prevent one sentinel Can't connect to master It leads to wrong switching

 

Sentinel mode build :

  Based on the master-slave replication above , Continue with the experiment :

Host server :192.168.181.5

Slave server : 192.168.181.4; Slave server : 192.168.181.6

  1. First, modify the sentry configuration file on the three nodes : sentinel.conf ( Because the configuration contents of the files on the three hosts are the same , therefore , have access to scp command , Copy the file remotely .),
  2. The contents of the document to be modified are shown in the following figure : ( there ip The address is your host address ,)

 

scp Command instance :

 

  1. On the host redis service , Use ./src/redis-server redis.conf: Pay attention to the starting sequence , Start the host first redis, Then start the slave's .
  2. Then start the sentinel service on the host , Use command : ./src/redis-server sentinel.conf --sentinel
  3. The following warnings may appear :
  4. Tips socket The number of connections is set too low , echo 1024 > /proc/sys/net/core/somaxconn
  5. If the service needs to be restarted after modification, there will be no warning prompt   Then restart the success page as follows :

 

Then start the slave services in turn .

There may be , After the Sentinels started , There is no response ., Special attention required :

The reason is that there is no password set for node authentication , That's mine redis Set the node communication password , Then it needs to be configured in the sentry .

 

The password here is the master-slave copy time , The password set for the host . To add the password after entering , The slave can link to the host normally . After modifying the configuration file , The entire service needs to be restarted .

Under the host page, you can see ,slave Two nodes of have been added :

 

Reopen a new host terminal window : Get into Redis client : Use the command shown in the following figure , You can view the current host information

 

You can also input the same command on the slave . View current status . So far, the installation and erection are completed , Test later :

test :

First test : Simulate host downtime , To test :

 

Then you can see the generated log file from the computer ; ( Because the front-end is started , The log will be displayed directly in the window )

As you can see from the picture below , After the previous host downtime , Through the election of sentinels , A new host 192.168.181.6( This figure is displayed on the 192.168.181.4 What's shown below )

 

here : see 192.168.181.6 Information in , The sending identity has been changed to the host , At the same time their sentinel.conf Host configuration in the configuration file ip It will also automatically program the current host ip Address .

 

Second test :

  Restore the host that was down in the previous mode to the online , You will find the connection between another slave and the current master , The log file will have new output .

 

And you can see that : Newly added slave sentinel.conf The documents have changed .:

 

. thus : Redis Sentinel mode , Configuration setup test succeeded .

Sentinel Several events in mode :

·       +reset-master : The master server has been reset .

·       +slave : A new slave server has been Sentinel Identify and relate .

·       +failover-state-reconf-slaves : The fail over state is switched to reconf-slaves state .

·       +failover-detected : the other one Sentinel Started a fail over operation , Or a slave server to a master server .

·       +slave-reconf-sent : The lead (leader) Of Sentinel Sent... To the instance [SLAVEOF](/commands/slaveof.html) command ,

Set up a new master server for the instance .

·       +slave-reconf-inprog : Instance is setting itself as a slave of the specified master server , But the corresponding synchronization process is still not complete .

·       +slave-reconf-done : The slave server has successfully completed the synchronization of the new master server .

·       -dup-sentinel : One or more... That monitor a given primary server Sentinel Has been removed due to recurrence —— When Sentinel

When the instance is restarted , This will happen .

·       +sentinel : A new server that monitors a given primary server Sentinel Has been identified and added .

·       +sdown : The given instance is now in a subjective offline state .

·       -sdown : The given instance is no longer in the subjective offline state .

·       +odown : The given instance is now in an objective offline state .

·       -odown : The given instance is no longer in the objective offline state .

·       +new-epoch : The current era (epoch) Has been updated .

·       +try-failover : A new fault migration operation is in progress , Waiting to be most Sentinel Choose

(waiting to be elected by the majority).

·       +elected-leader : Winning the election of the appointed era , It's ready for fault migration .

·       +failover-state-select-slave : The failover operation is now in select-slave state —— Sentinel Looking for upgrade to primary

Server's slave .

·       no-good-slave :Sentinel Operation failed to find a suitable slave server for upgrade .Sentinel We will try to find a suitable slave server to upgrade again after a period of time , Or simply give up performing a fail over operation .

·       selected-slave :Sentinel Successfully find a suitable upgrade from the server .

·       failover-state-send-slaveof-noone :Sentinel Upgrading specified from server to master , Wait for the upgrade to complete .

·       failover-end-for-timeout : Fail over aborted due to timeout , But eventually all the slave servers will start copying the new master servers (slaves will eventually be configured to replicate with the new master anyway).

·       failover-end : The fail over operation completed successfully . All slave servers are starting to replicate new master servers .

·       +switch-master : Configuration change , Of the main server IP And the address has changed . This is information that most external users care about .

·       +tilt : Get into tilt Pattern .

·       -tilt : sign out tilt Pattern .

原网站

版权声明
本文为[Wu Yu]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203010546357414.html