当前位置:网站首页>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 .
边栏推荐
- Unity realizes rotation and Revolution
- Pourquoi l'ordinateur n'a - t - il pas de réseau après l'ouverture du Hotspot win10?
- HTC vive cosmos development - handle button event
- Meet in Bangkok for a romantic trip on Valentine's Day
- Singapore parent-child tour, these popular attractions must be arranged
- Window10 jar double click to run without response
- Create transfer generation point
- 【Paper】2020_ Research on defense and evaluation strategy of heterogeneous UAV formation_ Zuojiankai
- [fpga] implementation of IIC read / write EEPROM
- amd锐龙CPU A320系列主板如何安装win7
猜你喜欢

Connect to the database and run node JS running database shows that the database is missing

Solution to Autowired annotation warning

【Paper】2021_ Analysis of the Consensus Protocol of Heterogeneous Agents with Time-Delays

Unity lens making

【Paper】2017_ Distributed control for high-speed trains movements

Moore Manor diary I: realize the reclamation, sowing, watering and harvest in Moore Manor

Unreal 4 unavigationsystemv1 compilation error

【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey

Connect to the database and run node JS running database shows that the database is missing

深度学习------不同方法实现Inception-10
随机推荐
Unrealeengine4 - about uobject's giant pit that is automatically GC garbage collected
Solution to 293 problems in the week of Li Kou
SCM learning notes: interrupt learning
0 foundation starts self-study unit notes control direction becomes larger
Unreal 4 learning notes - Animated Montage
[UAV] gyroscope data analysis, taking Victor intelligent jy901b as an example
Create a simple battle game with photon pun
[control] multi agent system summary. 4. control agreement.
力扣292周赛题解
Oracle-数据的基本操作
HTC vive cosmos development - handle button event
Unit screenshot saved on the phone
What to do when the alicloud SSL certificate expires
Output directory of log files after unity3d packaging
Deeply understand the function calling process of C language
一条命令运行rancher
Why does the computer have no network after win10 is turned on?
Unity a* road finding force planning
Recommended cultural landmarks of these tourist attractions in Bangkok
Redis implements SMS login function (II) redis implements login function