当前位置:网站首页>Three ways of redis cluster
Three ways of redis cluster
2022-07-26 03:33:00 【Lin Feifan 1998】
Redis Three ways of clustering : Master slave copy , Sentinel mode ,Cluster colony .
Master slave copy

The basic principle
When a new slave server is created , The slave will send... To the master SYNC command , Received SYNC The main server after the command will conduct a BGSAVE command , During execution , All commands will be written to the buffer , When BGSAVE After the command is executed, it will generate RDB File sent to slave , Use this file from the server to load data into memory , After that, the primary server will Redis The format of the command protocol sends the command of the buffer to the slave server . After that, every time the master service executes a command, it will synchronize it with the slave server . Even if there are multiple slave servers sending to the master server SYNC command , The main server will only execute one BGSAVE command , You can process the next synchronization request . A master server can have multiple slave servers , And the slave server can also own the slave server , Thus forming a graphic structure , Replication doesn't block the primary server , Even if there are one or more synchronization requests , The master server can still handle command requests .
Persistence switch
When the master-slave replication mode is configured, you need to turn on the persistence function of the master server , If the persistence function of the primary server is turned off , Once the master server is restarted , All data from the server will be lost , Even if it is configured with Sentinel Pattern , If the main server automatically pulls up the process faster , So that Sentinel A new master server has not been selected in mode , The start of the main service will also cause the data loss of the sub server .
To configure
Configure a master-slave replication mode , Just use Slaveof Command is enough , stay conf Add to the configuration file or in redis Middle execution command .
1 |
|
Sentinel mode

The basic principle
Redis Of Sentinel The system is used to manage multiple Redis, Mainly implement the following three things :
monitor :Sentinel It will constantly check the running status of the master and slave servers
remind : When a Redis The server is down , It can be done by API Or other applications send notifications
Automatic failover : When a primary server doesn't work ,Sentinel A failure automatic migration will be carried out , A new master server will be selected from the slave server of the invalid master server , The remaining slave servers will automatically connect and copy the data of the selected new server .
Redis Of Sentinel The system is a distributed system , One or more... Can be configured in the system Sentinel.
start-up
Use redis-sentinel start-up
1 |
|
You can also use redis-server To start up
1 |
|
The above two methods can be started sentinel, start-up sentinel Configuration file must be specified , Otherwise it won't start :

To configure
One sentinel.conf The file needs at least one sentence of configuration :
1 |
|
Monitor an alias called mymaster The host , The address is 127.0.0.1, The port is 6379, It takes at least 2 individual sentinel agree! .
No matter how many are set sentinel Agree to judge the failure of a master server , Need multiple in the system Sentinel Support for failover , And only a few sentinel During normal operation , Is unable to fail over .
Fault migration
When one Sentinel When the primary server is found offline , It's called subjective offline , Only multiple Sentinel Found that the main service was offline , And communicate with each other through commands to determine when the main server is offline , It is called objective offline . Only when the main server is objectively offline , Will elect a leader Sentinel, After the election , There will be a new primary server voting , Choose a server to upgrade from the server to the main server . And send it to the selected slave server Slaveof no one command , Make it the main server , Through the function of publishing and subscribing , Broadcast the new configuration to others Sentinel updated , And send it to the offline master server Slaveof command , Let it replicate the new master server , When all slave servers have started replicating the new master server , The lead Sentinel Terminate this failover .
When one Redis The instance is reconfigured , Whether it's set up as a primary server 、 From the server 、 Or it can be set as the slave server of other master servers ,Sentinel Will send a... To the instance being reconfigured
CONFIG REWRITEcommand , This ensures that these configurations are persistent on the hard disk .
Cluster colony

Before master-slave , Sentinel mode is difficult to reproduce and expand , and Redis cluster The cluster has realized to Redis Horizontal expansion of , Start now N individual Redis node , Each node can have its own slave server , Store the data evenly here N On a node , Each node stores data 1/N.Redis cluster A cluster is one that can work in multiple Redis Facilities for data sharing between nodes ;Redis cluster The cluster adopts a decentralized configuration , That is node A Unable to deal with , The request will be forwarded to only nodes B To deal with .
Bond distribution model
Redis The key space in the cluster is divided into 16384 Slots . Each master node is responsible for 16384 Part of the middle slot ,Redis Use CRC16 Algorithm for slot allocation . To ensure high availability ,cluster Mode also introduces master-slave replication mode , A master node corresponds to one or more slave nodes , When the primary node goes down , Failover possible , Promote the child node to the primary node .
To configure cluster colony
Redis The cluster consists of multiple running in cluster mode (cluster mode) Under the Redis Examples consist of , The cluster mode of the instance needs to be enabled through configuration , The following is an example of a cluster configuration file with the least options :
1 2 3 4 5 |
|
cluster-enabled: Open cluster mode
cluster-config-file: Node profile name , There is no need to modify , It consists of Redis The cluster is created at startup , And automatically update when needed
cluster-node-timeout: Node loss time , When it exceeds this millisecond , The cluster will automatically switch between master and slave nodes .
At least three primary nodes are needed for the cluster to function properly , Each master node should be properly configured with one or more slave nodes .
Start cluster
Use redis-cli --cluster create The command merges the nodes into a cluster
1 |
|
--cluster-replicas 1 This refers to the number of slaves , Indicates that we want to create a slave node for each master node in the cluster .
To enter the cluster mode, you only need to use redis-cli -c command
1 |
|
No hub node , So enter the master node of any port number .
边栏推荐
- 大厂面试都面试些啥,看了不亏(一)
- Leetcode-169. most elements
- 离线数据仓库从0到1-阶段二软件安装
- Canvas -- draw text -- modification of pie chart
- Canvas - drawing pictures - dynamic drawing production
- Use VRRP technology to realize gateway equipment redundancy, with detailed configuration experiments
- Tf.constant usage
- A 4W word redis interview tutorial
- oracle 11g “密码延迟验证”特性
- "Xiao Deng's view" the value brought by Siem to enterprises (II)
猜你喜欢

Installation and operation of orb-slam2 under ROS

File upload error: current request is not a multipart request

离线数据仓库从0到1-阶段二软件安装

Bing(必应)搜索,为什么用户越来越多?

Istio三之VirtualService、Gateway、DestinationRule配置使用

Offline data warehouse from 0 to 1 - phase I resource purchase configuration

Idea2020.3.1 cannot be opened (double click cannot be opened), but it can be opened through idea.bat.

Canvas -- draw curve -- wall clock, pie chart, five pointed star

LoRa无线网关如何快速实现端到云的传输

Can UDP and TCP use the same port?
随机推荐
bond网络模式配置
【虚拟化】查看vCenter和ESXi主机的Log日志文件
NFT因无意义而美丽
【 Kotlin 中的类和对象实例】
6-40v input fixed 5V 3.3V output 1.1a current 23-5 package
Uncaught TypeError: $(...).onmouseenter is not a function js错误,解决办法:
Summary of basic knowledge of C language pointer (I)
[tensorflow & pytorch] image data enhancement API
[stl] priority queue priority_ queue
研发了 5 年的时序数据库,到底要解决什么问题?
[virtualization] view the log files of vCenter and esxi hosts
UE4 how to render statically? 5 steps to generate static rendering
Can UDP and TCP use the same port?
多商户商城系统功能拆解15讲-平台端会员标签
Visio: how do Gantt charts merge cells? Solution: overwrite cells
阿里二面:千万级数据量的表,快速查询如何进行?
Visio:甘特图如何合并单元格?解决方案:覆盖单元格
els 窗口设置、WM_CREATE、WM_PAINT
Derivation of linear regression principle
ELS register window class, create window class, display window