当前位置:网站首页>redis-6. Redis master-slave replication, cap, Paxos, cluster sharding cluster 01
redis-6. Redis master-slave replication, cap, Paxos, cluster sharding cluster 01
2022-06-13 07:13:00 【Floating across the sea】
redis
redis stand-alone
stay redis stand-alone , A single node , Problems with single instances
- A single point of failure ( The physical machine hung up )
- Limited capacity
- Under great pressure
Solution
AKF
Yes XYZ Three axes , Only one can happen , Multiple dimensions can occur together
AKF Cubes are also called scala cube, It's in 《The Art of Scalability》 First proposed in a Book , It aims to provide a systematic expansion idea .AKF The system expansion is divided into the following three dimensions :
X Axis : Directly and horizontally copy the application process to expand the system .
Y Axis : Split the functions to expand the system .
Z Axis : Expand the system based on user information .
No matter what redis,mysql still kafka Can be extended based on this concept
adopt akf To solve the problem will extend to other problems
problem 1 Data consistency issues
programme 1: All nodes are blocked , Until all numbers are consistent , But this situation will lead to redis Reduced availability of , More than one side is to solve the availability problem
programme 2: Tolerate the possibility of data loss , Return directly to the host redis ok, Insert standby asynchronously redis, This situation must tolerate data loss
programme 3: How to guarantee not to lose , The middle price can be inserted kafka, Achieve final consistency of data . There are many possibilities : Before reaching final consistency , Inconsistent data may be obtained
problem 2 If the Lord redis Hang up , Make the whole service unavailable
The main equipment : The client does not participate in the business , Only as a standby machine
Master-slave : Master slave copy , You can retrieve data from the library ( Emphasize the concept )
Generally, it is highly available to the primary user HA, If the Lord redis Hang up , We can do it manually To prepare 1redis Top up , As a host , Let prepare 2redis Continue to be an assistant ,
But ah , brothers , We are fucking programmers , Every time this kind of fault occurs, it is not troublesome , It will be very low And there is still time to recover , This is when the monitoring program appears , But a monitoring program will also hang up , Therefore, the monitor itself should also be a cluster that has become more and more .
Multiple monitors : Multiple monitors are waiting for a master , If redis Hang up , Monitor to find him , Because there are network delays , How to judge by multiple monitors redis Did you hang up or not ? Like monitor 1 Sending hung up , monitor 2 Sending hung up , monitor 3 No, I didn't listen , How to deal with this situation ? Strong consistency cannot be used at this time , Only some machines need to give the result judgment , that ! How many are there in one part ?
The three monitors produce different results , Create competition . There will be a problem : Network partition ( Split brain ), Different clients get different data , External performance is data inconsistency .
If 2 A monitor said redis Hang up ,1 A monitor said redis Still alive , this 2 The forces monitored are 2. The force is 1 There is no decision-making power for monitoring . At this time, the external performance is not an ambiguous state .
therefore , When the faction reaches n/2+1, That is, half way through , You can solve your mental problems . Therefore, the cluster generally uses an odd number of servers .
Why is it an odd number ?
We use it 3 Taiwan and 4 Taiwan comparison , They are only allowed to hang one . but 4 Table ratio 3 It's easier to hang one , and 4 The price is higher . So the first 4 There is no need for a platform .
CAP
A term is used to explain :
Master-slave : The client can access the master You can also access the backup
The main equipment : The client will only access the primary The standby machine is used to replace the main hook
CAP: Uniformity Usability Partition tolerance Two at most Not all of them
Master slave copy
Redis Use default asynchronous replication , It is characterized by low latency and high performance , It's the vast majority Redis The natural replication pattern of use cases . however , from Redis The server asynchronously confirms its slave master Redis The amount of data received by the server in a cycle .
Conditions are limited , I started three on one host redis
5.0 Previous master-slave replication operations
127.0.0.1:16379> help SLAVEOF
SLAVEOF host port
summary: Make the server a replica of another instance, or promote it as master. Deprecated starting with Redis 5. Use REPLICAOF instead.
since: 1.0.0
group: server
5.0 Subsequent master-slave replication operations
127.0.0.1:16379> help REPLICAOF
REPLICAOF host port
summary: Make the server a replica of another instance, or promote it as master.
since: 5.0.0
group: server
I'm here at this time redis16380 Set the main database above
REPLICAOF 127.0.0.1 16379
Report errors ! Thought I was 16379 Added above password . Therefore, it is impossible to link
To configure... Here 16380.conf On the configuration 6379 Password
Repeat the previous link operation
16379.log
16380.log
127.0.0.1:16379> set k1 zjj
OK
By default 16380 Is read-only
127.0.0.1:16380> get k1
"zjj"
127.0.0.1:16380> set k1 aaa
(error) READONLY You can't write against a read only replica.
I'm going to modify 16381 follow 16379, At this time, verify all the above problems , In the case of following ,redis Followers will flushall My own library
127.0.0.1:16381> set k2 aaa
OK
127.0.0.1:16381> get k2
"aaa"
127.0.0.1:16381>
127.0.0.1:16381> REPLICAOF 127.0.0.1 16379
OK
127.0.0.1:16381>
127.0.0.1:16381> get k1
"zjj"
127.0.0.1:16381> get k2
(nil)
At this time I shutdown 16381
127.0.0.1:16381> SHUTDOWN
16379 newspaper 16381 The link doesn't go up , At this time, we will redis 16381 Restart up , that 16379 How to synchronize your data
stay redis 16381 Continue writing in case of hang up 16379
127.0.0.1:16379> set k2 aaa
OK
127.0.0.1:16379> set k3 bbb
OK
Restart 16381 redis-server ./6381.conf --replicaof 127.0.0.1 6379
After reboot , It will still synchronize the increment during the period of suspension .
127.0.0.1:16381> keys *
1) "k1"
2) "k3"
3) "k2"
- masterauth < master-password >
Set the password
- replica-serve-stale-data yes
When in the process of synchronization , Or slave and master The connection between them has been broken ,replica Can I still provide read requests ?
By default ,replica You can't provide a request , Go straight back to error, But when the following configuration is turned on , The old data can be used to respond to the request .
- replica-read-only yes
By default ,slave Is read-only , Prevent misoperation from writing bad data , But if you have to be writable , It can also be opened through the following configuration .
- repl-diskless-sync no
about master End :
The following configuration can be enabled , After opening master Will no longer be generated rdb file , Directly encode the memory data and send it to replica
- repl-backlog-size 1mb
Incremental replication
Is the buffer configured as large as possible ?
If the configuration is too large , such as 10G, The actual data in memory may only be 100M, When replica and master The connection between them has been broken long enough , then replica It's reconnected master, Sent a offset To come over , And then it started 10G The transmission of commands ,
In fact, if it is full synchronization at this time , You may only need 100M The transmission of the data of . According to this situation , The buffer should not be too large .
- min-replicas-to-write 3
- min-replicas-max-lag 10
If replica and master The connection between is broken ,master How does it work ? It's indifference ?
By default ,replica and master After disconnection ,master I don't do anything , It's just a replica, after all ,master Don't care . But it can be configured through the above , Give Way master care about .
This configuration is represented in 10 At least... In seconds 3 individual replica On-line , and master The connection is normal , otherwise master Write operations from the client are not accepted ,master During this time it became read-only , This will allow replica As much as possible and master The gap between the two countries has narrowed . But it also affects master Normal request for .
Detailed Links :https://blog.51cto.com/happytree007/2586641
Sentinel sentry
Redis Of Sentinel The system is used to manage multiple Redis The server (instance), The system performs the following three tasks :
- monitor (Monitoring): Sentinel Constantly check whether your master and slave servers are working properly .
- remind (Notification): When someone is being monitored Redis When there's a problem with the server , Sentinel Can pass API Send notifications to administrators or other applications .
- Automatic failover (Automatic failover): When a primary server doesn't work , Sentinel An automatic failover operation will start , It will upgrade one of the failed master servers from the server to the new master server , And let the other slave servers of the failed master server copy the new master server ; When a client tries to connect to a failed primary server , The cluster will also return the address of the new primary server to the client , So that the cluster can use the new master server instead of the failed server .
at present Sentinel System is Redis Of unstable Part of a branch , You must go to Redis Project Github page Clone a copy of unstable The score is , Then compile to get Sentinel System .
Sentinel The program can be compiled in src Found in the document , It's a name for redis-sentinel The program .
You can also use the methods described in the next section , Give Way redis-server The program runs in Sentinel In mode .
in addition , A new version of Sentinel It's already included in Redis 2.8.0 Release file of version .
redis The installation directory src It can be found below
Take a look at our system default program directory
[[email protected] redis] redis-sentinel 26379.conf
port 26379
## At present Sentinel Node monitoring 127.0.0.1:6379 This master node , 1 Represents the minimum required to determine that the master node failed 2 individual Sentinel Node node agreement
sentinel monitor mymaster 127.0.0.1 16379 2
# sentinel author-pass Define the password for the service ,mymaster It's the service name ,123456 yes Redis Server password
# sentinel auth-pass <master-name> <password>
sentinel auth-pass mymaster 123456
## Every Sentinel Nodes are scheduled PING Command to judge Redis Data nodes and the rest Sentinel Whether the node is reachable , If exceeded 10000 MS and no reply , It is unreachable
sentinel down-after-milliseconds mymaster 10000
You can refer to :https://www.jianshu.com/p/06ab9daf921d
redis-sentinel 26379.conf
redis-sentinel 26380.conf
redis-sentinel 26381.conf
take salve The library is promoted to the main library
slaveof no one
127.0.0.1:16379> SHUTDOWN
here 26379,26380 Listen for service changes ( Be careful , Wait for the network or heartbeat 1 About seconds )
This moment reminds me
边栏推荐
- mysql中时间字段 比较时间大小
- It's called the next generation monitoring system. Let's see how awesome it is
- 【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真
- Issues related to C # delegation and events
- [Tencent Alibaba's most comprehensive collection of test questions] (four sides: three rounds of technology +1 round of HR)
- 10 Honest Facts I Want To Share With All Junior Developers
- 对绘制丘岭密度图ridge plot的详细说明、重叠核密度估计曲线overlapping densities、FacetGrid对象、函数sns.kdeplot、函数FacetGrid.map
- 测试开发程序员,你还在迷茫吗?不能把自己定义为码农......
- SDN basic overview
- TXT_ File encryption and compression
猜你喜欢
Tidb dashboard modify port
基于FPGA的ds18b20温度传感器使用
Table access among Oracle database users
First day of learning MySQL Basics
Through the function seaborn cubehelix_ Palette build order palette
【微弱瞬态信号检测】混沌背景下微弱瞬态信号的SVM检测方法的matlab仿真
微隔离(MSG)
Periodontitis investigation (ongoing)
Department store center supply chain management system
WWDC2022最大的亮点: MetalFX
随机推荐
Lightning breakpoint continuation
Powerdispatcher reverse generation of Oracle data model
Quick sort
Interview questions must be asked - Optimization of large table Pagination
[Collection des questions d'examen les plus complètes de Tencent Ali] (quatre côtés: 3 tours de technologie + 1 tour de RH)
Byte (nine)
Tidb statistics
[cloud native | kubernetes] kubernetes configuration
Ticdc introduction
面试必刷算法TOP101之单调栈 TOP31
Upper computer development (code debugging of firmware download software)
RT-Thread 模拟器 simulator LVGL控件:button 按钮事件
Br backup test
Detailed Mr Atlas of hip joint (Reprinted)
关于c#委托、事件相关问题
Raspberry school advanced development - "writing of IO port driver code" includes bus address, physical \u virtual address and bcm2835 chip manual knowledge
【马尔科夫链-蒙特卡罗】马尔科夫链-蒙特卡罗方法对先验分布进行抽样
简单了解C语言基本语
Ansible PlayBook的中清单变量优先级分析及清单变量如何分离总结
百货中心供应链管理系统