当前位置:网站首页>Introduction to redis master-slave, sentinel and cluster mode
Introduction to redis master-slave, sentinel and cluster mode
2022-07-03 15:11:00 【Miss, do you fix the light bulb】
First, let's receive Redis Persistence of :
RDB snapshot : By default ,Redis Save the memory database snapshot as named dump.rdb Binary , You can set his rules for the ninth day of junior high school as N Within seconds M Make a save action when making changes Column : “60 At least in seconds 1000 Keys changed ” On this condition , Save the data set automatically once : The configuration file reflects # save 60 1000
Here is a knowledge point : command bgsave, Is the copy on write mechanism , Write commands can still be processed when generating snapshot persistence , It is by the main thread fork Out of the child thread . That is, as mentioned earlier Redis Not single threaded .
AOF : RDB There is a drawback , When the service goes down , It will confirm the data that has not reached the persistence condition for a period of time recently . therefore AOF There is , He stipulates how long it will last , It is recommended to synchronize once per second , Even if there is a fault, there is no data for that second . In this way, the file will be larger , So when you resume using aof file , The degree of fragmentation will be slightly slower .Redis4.0 Mix persistence , First use RDB Snapshot recovery , Reuse AOF Supplement some missing data . Restart efficiency is greatly improved
One 、Redis Master slave architecture 
1. Why master-slave replication is needed ?
Although single Redis The concurrency of can reach 10 ten thousand , But there are always limitations , At this time, the master-slave mode is established , Can achieve read-write separation , One master Responsible for writing , Multiple slave nodes are responsible for reading , So as to improve the concurrency .
But with it comes another problem , Master slave replicates storm : When there are too many slave nodes , This will cause the master node to put too much pressure on the slave node to synchronize data , The solution is to synchronize the data between the slave node and the slave node .
If an instance master Hang up , We need to manually switch one from the server to the main server , It will also make the service unavailable for a period of time . In order to solve the problem that the master-slave mode cannot be highly available , He invented the sentinel mode 
Two 、 Sentinel high availability mode 
Sentinel mode is very special , He doesn't offer reading , Nor does it provide writing , Mainly for monitoring Redis Instance node . In order to save the immature master-slave architecture . Why do you say that? , It's simple , In the master-slave architecture , If the master node hangs up , No slave node can replace the master node .
sentinel Sentinels are special Redis service , In sentinel mode ,cline The end finds out for the first time Redis The primary node of , Follow up direct access Redis The primary node of , When the master node changes , The sentry was the first to perceive , And new Redis The master node notifies the client . For high availability ,sentinel It must be a cluster , When Redis The master node of is hung up , Everyone who finds it offline sentinel The city will begin to vote to select its own slave node as the master node to provide external services .
So far, it seems Redis High availability of is already perfect , But he has a fatal flaw , Even be despised by the master-slave architecture : In sentinel mode , Only Redis The main node of provides external services , The slave node does not provide read / write , It is only used as a spare tire on the master node , So in the case of high concurrency , Concurrency does not increase but decreases .
3. High availability cluster mode
1. As mentioned above, in sentinel mode , The main role of sentinel clusters can be attributed to automatic elections , But the concurrency is not good , Only Redis Of master The node provides external read-write services , The slave node is just the backup node waiting for the upper . Said so much , Can the slave node in the cluster mode provide external reading services , Thinking too much is actually the same , Just as a backup . It is called cluster mode , Because he has many master node , Form a cluster , So many master Provide external services together , Improve concurrency 
Official description :redis Cluster is a distributed server group composed of multiple master-slave nodes , It has replication 、 High availability and fragmentation features .Redis Clusters do not need sentinel sentry ∙ It can also complete the function of node removal and fail over . You need to set each node to cluster mode , There is no central node in this cluster mode , Scalable horizontally , According to official documents, it can be linearly extended to tens of thousands of nodes ( The official recommendation is no more than 1000 Nodes ).redis Cluster performance and high availability are better than the previous version of sentinel mode , And the cluster configuration is very simple .
Implementation principle of data distribution :Redis The cluster divides all data into 16384 Slots , Every node ( Master node ) Be responsible for some of them , When we are based on key When storing ,Redis according to CRC16 The algorithm gives a result , Then on 16384 Mod , So each of them key Will fall on 0-16383 Between , Then find the corresponding node interval .
Summarize the election mechanism : Cluster mode , each master They will communicate with each other , When the communication times out, it is considered offline , At this time, all the slave nodes corresponding to the offline master node start to grab the upper master node , Only when half of the cluster master nodes agree can the election be successful . From the perspective of saving resources, the division method considers that the main nodes of the group are set to an odd number . In sentinel mode sentinel Elections are the same mechanism .
边栏推荐
- 运维体系的构建
- .NET六大设计原则个人白话理解,有误请大神指正
- B2020 分糖果
- Global and Chinese markets of AC electromechanical relays 2022-2028: Research Report on technology, participants, trends, market size and share
- 官网MapReduce实例代码详细批注
- Global and Chinese markets for sterile packaging 2022-2028: Research Report on technology, participants, trends, market size and share
- What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
- Vs+qt multithreading implementation -- run and movetothread
- What is machine reading comprehension? What are the applications? Finally someone made it clear
- 视觉上位系统设计开发(halcon-winform)-5.相机
猜你喜欢
随机推荐
【Transform】【NLP】首次提出Transformer,Google Brain团队2017年论文《Attention is all you need》
运维体系的构建
Chapter 14 class part 1
Halcon与Winform学习第一节
[transformer] Introduction - the original author of Harvard NLP presented the annotated transformer in the form of line by line implementation in early 2018
【云原生训练营】模块七 Kubernetes 控制平面组件:调度器与控制器
Using Tengine to solve the session problem of load balancing
Functional modules and application scenarios covered by the productization of user portraits
[opengl] advanced chapter of texture - principle of flowmap
ASTC texture compression (adaptive scalable texture compression)
[ue4] material and shader permutation
Global and Chinese market of optical fiber connectors 2022-2028: Research Report on technology, participants, trends, market size and share
【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
官网MapReduce实例代码详细批注
视觉上位系统设计开发(halcon-winform)-2.全局变量设计
视觉上位系统设计开发(halcon-winform)
[ue4] Niagara's indirect draw
Unity hierarchical bounding box AABB tree
[engine development] in depth GPU and rendering optimization (basic)
第04章_逻辑架构





![[ue4] Niagara's indirect draw](/img/8a/576022b5d19e1d6422ff0135c50c93.jpg)

