Redis notes master slave copy (Windows 10)

Time:2021-6-17

preface

In order to avoid single point of failure, we need to deploy multiple copies of data replication on multiple different servers. Even if one server fails, other servers can continue to provide services

effect:

Data backup

Extended read performance(Read write separation)

Copy mode

Full replication

Partial replication

 

Implementation mode

 

1One master and two strokesABC)OneMasterTwoSlave

2(decentralization)A-B-CBIs the master nodeCIt is also a slave node(A(from node)

3(main node)downAfter drop, manually upgrade the slave node (master node)

4Sentinel mode (whether the background monitoring host fails, if it fails, the slave library will be automatically converted to the master library according to the number of votes)

 

One master and many followers

 

 

to configure:

Master: 6379 port
requirepass 123456

Slave1: Port 6380
port 6380
slaveof 127.0.0.1 6379
masterauth 123456

Slave2: port 6381
port 6381
slaveof 127.0.0.1 6379
masterauth 123456

 

start-up

openMaster

redis-server.exe redis.windows.conf

 

openslave1

 

 

openslave2

 

 

seemaster

 

 

test

 

Connect threeredis

 

 

 

 

 

 

towardsmasterWrite data

 

 

 

seeslave1

 

 

 

 

 

 

 

Possible problems

Start the service,127.0.0.1java.net.SocketTimeoutE xception:connect   time   Out timeout and Ping port
Solution: turn off the firewall

 

 

Sentinel modesentinel

Tasks of sentinel mode:

Monitoring(Monitoring):SentinelWill constantly check whether your master server and slave server allow normal.

Reminders(Notification): when a monitoredRedisWhen there is a problem with the server,SentinelCan passAPISend notifications to administrators or other applications.

Automatic fault migration(Automatic failover:

1)When a primary server fails to work properly,SentinelIt will start an automatic fault migration operation. It will upgrade one of the failed master servers to a new master server, and change other slave servers of the failed master server to copy the new master server;

2)When the client tries to connect to the failed primary server, the cluster will also return the address of the new primary server to the customer service. Yes, the cluster can use the new primary server instead of the failed server

 

New configuration sentinel.conf

Only port port is different in three redis configurations

#Different ports
#The port on which the sentinel service is currently running
port 26379
#The name of the main server mymaster for sentinel monitoring (can be customized), 1 ticket
sentinel monitor mymaster 127.0.0.1 6379 1
sentinel auth-pass mymaster 123456
#If mymaster does not respond within 10 seconds, it is considered that the master is down
sentinel down-after-milliseconds mymaster 10000
#If after 20 seconds, mysater still does not start, then start failover
sentinel failover-timeout mymaster 20000
#When performing a fail over, at most one slave server synchronizes the new master server at the same time. The smaller the number is, the longer it takes to complete the fail over
sentinel parallel-syncs mymaster 1
bind 127.0.0.1
protected-mode yes

 

 

Possible problems

redis   Master slave switch failed

 

[12248] 31 Mar 17:09:26.726 # +try-failover master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:09:26.728 # +vote-for-leader 2fe3a13e25190364c193e71b6d89257323d694ce 11
[12248] 31 Mar 17:09:26.728 # +elected-leader master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:09:26.728 # +failover-state-select-slave master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:09:26.803 # -failover-abort-no-good-slave master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:09:26.864 # Next failover delay: I will not start a failover before Tue Mar 31 17:10:17 2020
[12248] 31 Mar 17:10:17.170 # +new-epoch 12
[12248] 31 Mar 17:10:17.171 # +try-failover master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:10:17.179 # +vote-for-leader 2fe3a13e25190364c193e71b6d89257323d694ce 12
[12248] 31 Mar 17:10:17.179 # +elected-leader master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:10:17.181 # +failover-state-select-slave master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:10:17.265 # -failover-abort-no-good-slave master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:10:17.349 # Next failover delay: I will not start a failover before Tue Mar 31 17:11:07 2020
[12248] 31 Mar 17:11:07.279 # +new-epoch 13
[12248] 31 Mar 17:11:07.279 # +try-failover master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:11:07.284 # +vote-for-leader 2fe3a13e25190364c193e71b6d89257323d694ce 13
[12248] 31 Mar 17:11:07.285 # +elected-leader master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:11:07.288 # +failover-state-select-slave master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:11:07.351 # -failover-abort-no-good-slave master mymaster 127.0.0.1 6379
[12248] 31 Mar 17:11:07.443 # Next failover delay: I will not start a failover before Tue Mar 31 17:11:57 2020

View Code

 

The problem is: configuration error, reconfiguration

 

 

 

Activate three sentries respectively

 

redis-server.exe sentinel.conf --sentinel

 

test

Turn off Mster

 

see

 

Slave 2 (6381) upgraded to master

Restart the previous master (6379). At this time, the master is still the previous slave 2 (6381)

 

 

 

 

Configure source address

 

 

common problem

 

Read write separation

There is a delay in copying data (if the slave node is blocked)

The slave node may fail

 

Inconsistent master-slave configuration

for examplemaxmemoryInconsistency may cause data loss

For example, the data structure optimization parameters are inconsistent: resulting in inconsistent master-slave memory

 

Avoid full replication

The first full copy is inevitable, so fragmentation is inevitablemaxmemoryAt the same time, choose the low peak (night) to do full replication.

Insufficient copy backlog buffer

Increase replication buffer configurationrel_backlog_size

For example, if the average network outage time is60sThe average number of write commands per second generated by the master node(Specific agreement format)The number of bytes occupied is100KB, the average requirement for copying the backlog buffer is6MBTo be safe, you can set to12MBTo ensure that partial replication can be used in most disconnection cases.

 

Replication storm

masterNode restart,masterNode generates ardbFile, but send to all slave nodesrdbDocuments. yescpu, memory, and bandwidth all cause great pressure

 

 

 

 

reference resources: https://www.jianshu.com/p/4aa9591c3153

 

Recommended Today

“Self test” stay up late to summarize 50 Vue knowledge points, all of which will make you God!!!

preface Hello everyone, I’m Lin Sanxin. A lot of things have happened these days (I won’t say what’s specific). These things have scared me to treasure my collection these yearsVue knowledge pointsI took out my notes and tried my best to recall them. Finally, I realized these 50Knowledge points(let’s not be too vulgar. It’s not […]