当前位置:网站首页>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 .
边栏推荐
- cpu飙升排查方法
- Tencent internship interview sorting
- Global and Chinese markets for ionization equipment 2022-2028: Research Report on technology, participants, trends, market size and share
- 【云原生训练营】模块八 Kubernetes 生命周期管理和服务发现
- [graphics] real shading in Unreal Engine 4
- 4-29——4.32
- Neon global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese market of postal automation systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Class part2
- Basic SQL tutorial
猜你喜欢
![[ue4] material and shader permutation](/img/8f/7743ac378490fcd7b9ecc5b4c2ef2a.jpg)
[ue4] material and shader permutation

Incluxdb2 buckets create database

高并发下之redis锁优化实战

Solve the problem that pushgateway data will be overwritten by multiple push

视觉上位系统设计开发(halcon-winform)-3.图像控件

Kubernetes帶你從頭到尾捋一遍

4-29——4.32

Yolov5 series (I) -- network visualization tool netron

Dataframe returns the whole row according to the value

el-switch 赋值后状态不变化
随机推荐
[Yu Yue education] scientific computing and MATLAB language reference materials of Central South University
开启 Chrome 和 Edge 浏览器多线程下载
TPS61170QDRVRQ1
【Transform】【实践】使用Pytorch的torch.nn.MultiheadAttention来实现self-attention
Puppet自动化运维排错案例
基于SVN分支开发模式流程浅析
复合类型(自定义类型)
视觉上位系统设计开发(halcon-winform)-5.相机
Global and Chinese market of air cargo logistics 2022-2028: Research Report on technology, participants, trends, market size and share
B2020 points candy
Tencent internship interview sorting
Didi off the shelf! Data security is national security
Global and Chinese market of iron free motors 2022-2028: Research Report on technology, participants, trends, market size and share
App全局异常捕获
What is one hot encoding? In pytoch, there are two ways to turn label into one hot coding
Nppexec get process return code
Global and Chinese markets of AC electromechanical relays 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode the smallest number of the rotation array of the offer of the sword (11)
Use of Tex editor
Center and drag linked global and Chinese markets 2022-2028: Research Report on technology, participants, trends, market size and share