当前位置:网站首页>Redis cluster concept
Redis cluster concept
2022-06-30 04:55:00 【xmh-sxh-1314】
1.1 The concept of cluster
The so-called cluster , By adding the number of servers , Provide the same service , So that the server can achieve a stable 、 Efficient state .
1.1.1 Use redis The need for clustering
problem : We've already deployed redis, And can start a redis, Read and write data , Why study redis colony ?
answer :(1) Single redis There is instability . When redis The service is down , There is no service available .
(2) Single redis My reading and writing ability is limited .
summary :redis Clustering is to strengthen redis The ability to read and write .
1.1.2 How to learn redis colony
-- explain :(1)redis In the cluster , every last redis Call it a node .
(2)redis In the cluster , There are two types of nodes : Master node (master)、 From the node (slave).
(3)redis colony , Is based on redis Master slave replication implementation .
therefore , Study redis colony , It's about learning redis The master starts with copying the model .
1 redis Master slave copy
1.1 Concept
Master slave replication model , There are many. redis node .
among , There is and only one master node Master. From the node Slave There can be multiple .
As long as the network connection is normal ,Master Will always synchronize their data updates to Slaves, Keep the master and slave in sync .
1.1 characteristic
(1) Master node Master Can be read 、 Can write .
(2) From the node Slave read-only .(read-only)
therefore , The master-slave model can improve the ability of reading , It eases the ability of writing to a certain extent . Because the only way to write is Master A node , All read operations can be handed over to the slave node , In disguise, it improves the ability of writing .
1.1 Configuration based implementation
1.1.1 demand
Master node
6380
From the node ( Two )
6381、6382
1.1.2 Configuration steps
(1) stay /usr/local Under the table of contents , Create a /redis/master-slave Catalog
[[email protected] local]# mkdir -p redis/master-slave
(2) stay master-slave Under the table of contents , Create three subdirectories 6380、6381、6382
[[email protected] master-slave]# mkdir 6380 6381 6382
(3) Copy in turn redis Extract... From the directory redis.conf The configuration file , Into these three subdirectories .
[[email protected] master-slave]# cp /root/redis-3.2.9/redis.conf ./6380/
[[email protected] master-slave]# cp /root/redis-3.2.9/redis.conf ./6381/
[[email protected] master-slave]# cp /root/redis-3.2.9/redis.conf ./6382/
(4) Get into 6380 Catalog , modify redis.conf, take port Change the port to 6380 that will do .
[[email protected] master-slave]# cd ./6380
[[email protected] 6380]# vim redis.conf
(5) Get into 6381 Catalog , modify redis.conf, take port Port changed to 6381, At the same time, specify to turn on master-slave replication .
[[email protected] 6380]# cd ../6381
[[email protected] 6381]# vim redis.conf
(6) Get into 6382 Catalog , modify redis.conf, take port Port changed to 6382, At the same time, specify to turn on master-slave replication .
[[email protected] 6380]# cd ../6382
[[email protected] 6381]# vim redis.conf
1.1.1 test
(1) Open three xshell window , In every window , Start a redis node . View log output .( Don't start in background mode , Can't see the log , Is not intuitive )
[[email protected] master-slave]# cd 6380 && redis-server ./redis.conf
[[email protected] master-slave]# cd 6381 && redis-server ./redis.conf
[[email protected] master-slave]# cd 6382 && redis-server ./redis.conf
(2) Open three more xshell window , In every window , Log on to a redis node
[[email protected] ~]# redis-cli -p 6380
[[email protected] ~]# redis-cli -p 6381
[[email protected] ~]# redis-cli -p 6382
(3) At the main node 6380 On , Read and write , Successful operation
[[email protected] ~]# redis-cli -p 6380
127.0.0.1:6380> set user:name zs
OK
127.0.0.1:6380> get user:name
"zs"
127.0.0.1:6380>
(4) At the slave node 6381 On
Read operation executed successfully , And succeed from 6380 The data is synchronized on the Internet
[[email protected] ~]# redis-cli -p 6381
127.0.0.1:6381> get user:name
"zs"
Write operation failed .( From the node , Only read , Can't write )
127.0.0.1:6381> set user:age 18
(error) READONLY You can't write against a read only slave.
1 Sentinel Sentinel mode
1.1 The defect of master-slave mode
When the primary node goes down , There are no writable nodes in the whole cluster .
Since all the data of the master node is backed up from the slave node , When the primary node goes down , If you can turn a slave node into a master node , Is it possible to solve this problem ?
answer : Yes , This is Sentinel The role of a sentry .
1.2 The task of the 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's going to vote , Upgrade one of the slave servers to a 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 .
1.2.1 monitor (Monitoring)
(1)Sentinel Can monitor any number of Master And the Master Under the Slaves.( That is, multiple master-slave modes )
(2) Under the same sentry 、 Different master-slave models , They are independent of each other .
(3)Sentinel Will keep checking Master and Slaves If there is something wrong .
1.2.2 Automatic failover (Automatic failover)
1.2.2.1 Sentinel The Internet
Monitor the same Master Of Sentinel Will automatically connect , Make up a distributed Sentinel The Internet , Communicate with each other and exchange information about the monitored server . The following figure , Three monitors s1 Of Sentinel, Automatically compose Sentinel Network structure .
doubt : Why use sentinel What about the Internet ?
answer : When there is only one sentinel When , If this sentinel Hang up , Then automatic failover is not possible .
stay sentinel In the network , As long as there is one more sentinel Alive , You can failover .
1.1.1.1 The process of fail over
(1) vote ( The principle of half )
When any one Sentinel Find out what's being monitored Master When offline , Will inform others Sentinel The meeting , To vote for Master Are you offline ( More than half , therefore sentinel Usually with an odd number ).
(2) The election
When Sentinel determine Master After offline , Will be in all Slaves in , Elect a new node , Upgrade to Master node .
Other Slaves node , To the slave node of this node .
(1) vote (2) The election
(3) primary Master Back online
When the original Master After the node is online again , Automatically change to current Master The slave node of the node .
(3) primary master Back online
1.1 Sentinel mode deployment
1.1.1 demand
Premise : There is already a running master-slave mode .
in addition , Configure three Sentinel example , Monitor the same Master node .
1.1.2 To configure Sentinel
(1) stay /usr/local Under the table of contents , establish /redis/sentinels/ Catalog
[[email protected] local]# mkdir -p redis/sentinels
(2) stay /sentinels Under the table of contents , To create s1、s2、s3 In three subdirectories
[[email protected] sentinels]# mkdir s1 s2 s3
(3) Copy in turn redis Extract... From the directory sentinel.conf file , Into these three subdirectories
[[email protected] sentinels]# cp /root/redis-3.2.9/sentinel.conf ./s1/
[[email protected] sentinels]# cp /root/redis-3.2.9/sentinel.conf ./s2/
[[email protected] sentinels]# cp /root/redis-3.2.9/sentinel.conf ./s3/
(4) Modify in turn s1、s2、s3 In subdirectories sentinel.conf file , Modify the port , And specify the master node to monitor .( The slave node does not need to specify ,sentinel Will automatically identify )
S1 The sentries are as follows :
S2 The sentries are as follows :
S3 The sentries are as follows :
(5) Open three more xshell window , In every window , Start a sentinel instance , And watch the log output
[[email protected] sentinels]# redis-sentinel ./s1/sentinel.conf
[[email protected] sentinels]# redis-sentinel ./s2/sentinel.conf
[[email protected] sentinels]# redis-sentinel ./s3/sentinel.conf
Core log output :
1.1.3 test
(1) Shut down first 6380 node . Find out , It does reassign a master node
(2) Back online 6380 node . Find out ,6380 The node becomes the slave of the new master .
边栏推荐
- [UGV] schematic diagram of UGV version 32
- Collective system
- Winter vacation parent-child tour, these new york attractions are not only fun but also knowledge
- The golden deer, a scenic spot in London -- a sailing museum that tells vivid sailing stories
- Create transfer generation point
- 【Paper】2015_ Coordinated cruise control for high-speed train movements based on a multi-agent model
- MySQL查询小工具(一)json格式的字符串字段中,替换json数组中对象的某个属性值
- Solution to the 292 week match of Li Kou
- 力扣977. 有序数组的平方
- MySQL query gadget (I) replace a property value of the object in the JSON array in the JSON format string field
猜你喜欢
Harbor API 2.0 query
一条命令运行rancher
力扣59. 螺旋矩阵 II
為什麼win10開熱點後電腦沒有網絡?
Some books you should not miss when you are new to the workplace
Software digital signature certificate
【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey
PBR material: basic principle and simple fabrication
图的一些表示方式、邻居和度的介绍
Marvel fan welfare: Singapore Madame Tussauds Wax Museum Marvel 4D experience Museum
随机推荐
Singapore must visit these scenic spots during the Spring Festival
力扣27. 移除元素
[fpga] implementation of IIC read / write EEPROM
One interview question and one joint index every day
【Paper】2021_ Observer-Based Controllers for Incrementally Quadratic Nonlinear Systems With Disturbanc
The difference between get and post requests
Important knowledge points in unity3d
[control] multi agent system summary. 1. system model. 2. control objectives. 3. model transformation.
MySQL query gadget (I) replace a property value of the object in the JSON array in the JSON format string field
【Paper】2020_ Research on defense and evaluation strategy of heterogeneous UAV formation_ Zuojiankai
[UAV] kinematic analysis from single propeller to four rotor UAV
Implementation of one interview question one distributed lock every day
Arsenal Stadium Tour - take you to the front and back of Arsenal Stadium
Connect to the database and run node JS running database shows that the database is missing
Unrealeengine4 - about uobject's giant pit that is automatically GC garbage collected
Force buckle 59 Spiral matrix II
Unity automatic pathfinding
為什麼win10開熱點後電腦沒有網絡?
Introduction to some representations, neighbors and degrees of Graphs
EasyRecovery数据恢复软件 恢复了我两年前的照片视频数据