Foreword
In order to avoid a single point of failure, we need to deploy multiple copies of data on multiple different servers, even if one server fails the other server can still continue to provide services
effect:
data backup
Extended read performance ( separate read and write )
Copy mode :
Copy the whole amount
Copy section
Method to realize
1 , a main flutter two A ( B , C ) a Master two Slave
2 , passing the torch (to the center) the ABC , B both master node ( C master node), but also from the node ( A from node)
3 , become masters (master down after off manually upgrade from the master node node)
4 , Sentinel mode (background monitoring whether the host fault, if fault according to the number of votes automatically convert the main library from the library)
A master multi-slave
Configuration:
Master: 6379 Port requirepass 123456 slave1: 6380 Port Port 6380 slaveof 127.0 . 0.1 6379 masterauth 123456 Slave2: 6381 Port Port 6381 slaveof 127.0 . 0.1 6379 masterauth 123456
start up
Open Master
redis-server.exe redis.windows.conf
Open slave1
Open slave2
View master
test
Connecting three redis
To master writing data
View slave1
Problems that may arise
Start the service, 127.0.0.1java.net.SocketTimeoutException: Connect OUT Time-outs and ping nowhere port
Solution: turn off the firewall
Sentinel mode sentinel
Sentinel mode tasks:
Monitoring ( Monitoring ): Sentinel constantly check your master server and from the server whether to allow normal.
Remind ( the Notification ): When the monitored a Redis server problem, Sentinel by API to send notifications to the administrator or other applications.
Automatic failover ( Automatic failover ) :
( 1 ) When a primary server is not working properly, Sentinel will automatically start a failover operation, he will be one of the primary server failure from a server to a new primary server, and let the failure of the primary server from the server instead of the other copy the new primary server;
( 2 ) the client attempts to connect when the primary server fails, the cluster will return to address the new primary server to the customer end, it is a cluster can be used instead of the new master server failure
New Configuration sentinel.conf
Only three redis port port configuration is not the same
The difference between different ports # # Sentinel service running current port Port 26379 # sentry monitor the primary server mymaster name (can be customized), 1 ticket Sentinel Monitor mymaster 127.0 . 0.1 6379 1 Sentinel auth -pass mymaster 123456 in the # 10s mymaster no response, it considers that the master is down Sentinel Down the -after-milliseconds mymaster 10000 # If after 20 seconds, mysater still did not start over, start failover Sentinel failover -timeout mymaster 20000 # when a failover, a maximum of one from the server at the same time new the primary synchronization server, the smaller the number, time required to complete failover longer Sentinel Parallel -syncs mymaster . 1 the bind 127.0 . 0.1 protected -mode Yes
Problems that may arise
From master handover failure redis
[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
The question is: configuration error Reconfigure
Respectively start three sentinels
redis-server.exe sentinel.conf --sentinel
test
Close mster
View
slave2 (6381) was promoted to master
master (6379) before re-opened, this time master or before slave2 (6381)
common problem
Separate read and write
Copy data there is a delay (from node if blocking occurs)
From node failure may occur
Master slave configuration is inconsistent
For example maxmemory inconsistent, may result in loss of data
Optimization parameters such as data inconsistency: a main cause inconsistencies from memory
To avoid the full amount of replication
The first full-volume copy inevitable, so slice maxmemory reduced while selecting at low peak (nighttime), do the whole amount of copy.
Copy the backlog insufficient buffer
Increasing the copy buffer configuration rel_backlog_size
For example, if the average network outage time is 60s , and the master node in an average per second write command ( specific protocol format ) the number of bytes occupied is 100KB , the average demand replication backlog buffer to 6MB , insurance purposes, you can set as 12MB , to ensure that the vast majority of cases can be broken using partial replication.
Copy storm
master node restart, master node generates a rdb file, but to give all sent from node rdb file. For the CPU , memory, bandwidth is a lot of pressure
Reference: https: //www.jianshu.com/p/4aa9591c3153