当前位置:网站首页>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 download and installation website
- One interview question and one joint index every day
- 【Paper】2019_ Distributed Cooperative Control of a High-speed Train
- Moore Manor diary I: realize the reclamation, sowing, watering and harvest in Moore Manor
- [fpga] implementation of IIC read / write EEPROM
- 【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey
- Unrealeengine4 - about uobject's giant pit that is automatically GC garbage collected
- Brew install NVM command not found solution
- Unity is associated with vs. there is a compiler problem when opening
- Unit screenshot saved on the phone
猜你喜欢
![[UAV] kinematic analysis from single propeller to four rotor UAV](/img/32/1a88b102f832ffbbc1a7e57798260a.jpg)
[UAV] kinematic analysis from single propeller to four rotor UAV

Window10 jar double click to run without response

SSL universal domain name certificate

力扣704. 二分查找

Unreal 4 learning notes - data storage using blueprints

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

harbor api 2.0查询

Malignant bug: 1252 of unit MySQL export

Unity script life cycle and execution sequence

Singapore must visit these scenic spots during the Spring Festival
随机推荐
Royal Albert Hall, a popular landmark in London
Unity enables simple music visualization
Implementation of one interview question one distributed lock every day
National Museum of Singapore - give you spiritual and physical satisfaction
【Paper】2006_ Time-Optimal Control of a Hovering Quad-Rotor Helicopter
Preorder traversal of Li Kou 589:n fork tree
How to repair expired SSL certificates?
Foreign SSL certificate
brew安装nvm报nvm command not found解决方案
力扣209. 长度最小的子数组
Thread safety and processing caused by multithreading
【Paper】2017_ Research on coordinated control method of underwater vehicle formation marine survey
力扣292周赛题解
[UAV] kinematic analysis from single propeller to four rotor UAV
Why does the computer have no network after win10 is turned on?
Winter vacation parent-child tour, these new york attractions are not only fun but also knowledge
One interview question every day to talk about the process of TCP connection and disconnection
Malignant bug: 1252 of unit MySQL export
Important knowledge points in unity3d
Connect to the database and run node JS running database shows that the database is missing