当前位置:网站首页>Redis configuration (III) -- master-slave replication

Redis configuration (III) -- master-slave replication

2022-06-12 06:19:00 leo_ messi94

Redis Master slave copy

What is it? ?

Master slave copy : After the host data is updated, according to the configuration and Policy , Automatic synchronization to the standby machine master/slaver Mechanism ,Master Write first ,Slave Mainly reading

use :

  • Read / write separation , Performance expansion
  • Rapid disaster recovery

 Insert picture description here

Configure temporary slave server :

 Insert picture description here
step :

  1. Set up three conf file , Port number 、 The file names are different
     Insert picture description here
     Insert picture description here
  2. Start with these profiles redis
     Insert picture description here
  3. View server status info replication, You can see that each server is the primary server
     Insert picture description here
  4. Set up a slave server called a server :slaveof ip port
    Set up 6380 and 6381 by 6379 From the server
     Insert picture description here
  5. see 6379:
     Insert picture description here

Configure permanent master-slave servers

Configure in profile :

# Master-Slave replication. Use slaveof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# 1) Redis replication is asynchronous, but you can configure a master to
# stop accepting writes if it appears to be not connected with at least
# a given number of slaves.
# 2) Redis slaves are able to perform a partial resynchronization with the
# master if the replication link is lost for a relatively small amount of
# time. You may want to configure the replication backlog size (see the next
# sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
# network partition slaves automatically try to reconnect to masters
# and resynchronize with them.
#
# slaveof <masterip> <masterport>

From the server, you can only read but not write

 Insert picture description here

One master and two slaves :

  1. A slave server goes down , Then the master server performs a write operation , At this point, reconnect the slave server and set the slave server of the master server ; Does the slave server still have the value written by the master server during this period ?
    answer : Yes , Whenever programming the slave server of the master server , Have all the data of the master server
  2. Whether the slave can write ?
    answer : Can not be
  3. host shutdown What happens after ?
    answer : The slave machine waits in place and waits for the host machine to work .
     Insert picture description here

The principle of replication

 Insert picture description here

It's passed down from generation to generation

 Insert picture description here

  1. Set again 6381 The primary server of :slaveof 127.0.0.1 6380
  2. 6379 The state of : and 6381 No contact
     Insert picture description here
  3. 6380 The state of : The Lord is 6379, There's another one 6381
     Insert picture description here
  4. problem :
    1. If at this time 6379 It's down. ,6380 Still can not be promoted to the primary server , Need to carry out slaveof no one Set up , Set it to not follow any servers
    2. If 6380 It's down. , Then there is no master-slave relationship

Sentinel mode :

 Insert picture description here

Configure sentinel mode

 Insert picture description here

Activate the sentry :

 Insert picture description here
 Insert picture description here

Fault problem in sentinel mode :

 Insert picture description here

Manual downtime 6379, View the sentinel server log :

selection 6380 For the new master server
 Insert picture description here
 Insert picture description here
see 6380 Details :
 Insert picture description here

Back online 6379, From the server

 Insert picture description here

The problem is : Replication delay  Insert picture description here

原网站

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