当前位置:网站首页>Redis cluster setup [simple]
Redis cluster setup [simple]
2022-06-28 03:20:00 【Doc_ ACwhite】
Why build redis colony ?
Redis It's a memory database , That is to say, the capacity of data storage cannot exceed the memory size of the host . The memory of an ordinary host server is generally dozens of G, But we need to store large amounts of data ( Like hundreds of G The data of ) What do I do ?
stay 3.0 Before the release , The usual approach is to get a key Of hashcode, then mod, However, this approach can not support dynamic scalability requirements very well , Once a node is added or deleted , Will result in key Cannot be in redis Hit in the middle .
redis3.0 It is supported above version cluster【 namely colony 】, It's using hash slot(hash Slot ). He can put more redis Instances are integrated , Form a cluster , That is, the data is distributed to multiple machines in the cluster . But how to disperse , One Key Can only be assigned to one machine , When we query the data , The data may exist on any machine in the cluster , And how to query ?
By sending to the node CLUSTER ADDSLOTS command , One or more slots can be assigned to a node :
for example

Redis Cluster It is a centerless structure , Each node stores data and the status of the entire cluster . Each node will save the information of other nodes , Know which slots other nodes are responsible for . And it will send heartbeat information with other nodes regularly , Be able to timely sense abnormal nodes in the cluster .
When the client sends a command related to the database key to any node in the cluster , The node receiving the command calculates which slot the database key to process belongs to (CRC16(key) & 16383), And check that the slot is assigned to yourself :
· If the slot where the key is located is just assigned to the current node , Then the node executes the command directly .
· If the slot where the key is located is not assigned to the current node , Then the node will return one to the client MOVED error , Direct the client to (redirect) To the correct node , And again send the command that you wanted to execute before .MOVED The wrong format is :
MOVED:

How to build redis colony ?
build redis colony , First you have to build redis Cluster node 【 At least 6 Nodes 】
Less than six nodes :
Here bloggers use 1 Servers have been operated 【ps: Understand the principle 】
The early stage of the work :
download redis The package
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
unpack
tar -zxvf redis-6.0.6.tar.gz
Don't forget after unzipping make and make install
cd Enter the redis Directory execution make

cd Get into src Execute... In directory make install command 
modify redis.conf Configuration of
vim redis.conf1. modify port The port number is 6378

2. take cluster-enabled The comment opens

3. take cluster-config The comment opens , And modify it to the port number 6378

4. open cluster-node-timeout Notes

Now? ls once , You can see that the file exists redis-6378

Now you have just configured a node , To be patient
We start copying nodes 6378-6373 And give them permission : as follows
chmod 777 redis-6373
After the modification cd Get into redis-6378-redis-6373 Medium redis.conf in , Follow the above process to modify the configuration , By the way, delete the dump.rdb file
rm dump.rdb

The node configuration is complete
Treasure people can pass ./src/redis-server redis.conf To test , Turn on redis node
./src/redis-server redis.conffor example :
| redis The default is to start the foreground , So you can't do anything else when you start , as follows |

Bloggers are lazy here , Do not want to start nodes one by one , So bloggers will redis Change to background start , I made one directly .sh The program starts the node with one click |
1. modify redis Start for background :
open redis.conf take daemonize Change it to yes

2. Create a... In the home directory start-all.sh
Get into start-all.sh Edit after
cd redis-6373
./src/redis-server redis.conf
cd ..
cd redis-6374
./src/redis-server redis.conf
cd ..
cd redis-6375
./src/redis-server redis.conf
cd ..
cd redis-6376
./src/redis-server redis.conf
cd ..
cd redis-6377
./src/redis-server redis.conf
cd ..
cd redis-6378
./src/redis-server redis.conf
cd ..:wq Exit after saving
![]()
perform .sh file , One click to open all nodes
./start-all.shadopt ps aux | grep redis Inquire about redis The startup status of the node
ps aux | grep redis
see ,6 Nodes have been opened , Next, the cluster function will be officially started
Get into redis-6378 Of documents src Under the table of contents
Carry out orders :【ps: If the cluster is built by multiple servers , Password may be required take 127.0.0.1 Change to the corresponding host domain name If its server redis There is a password be Add... After the cluster statement below -a redis password , for example : -a 123456】
./redis-cli --cluster create 127.0.0.1:6378 127.0.0.1:6377 127.0.0.1:6376 127.0.0.1:6375 127.0.0.1:6374 127.0.0.1:6373 --cluster-replicas 1
look,(/≧▽≦)/ In this way, a common redis Clustered
And then choose 6378 This port is the primary node
redis-cli -c -p 6378Take one set sentence -> OK

thus , We simply finished redis Clustered 3 Lord 3 From the construction of
Learn here , Bloggers might as well give you more information about sentinel mode :
Characteristics of master-slave mode
(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 .
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 .
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 .
Subjective downline of nodes 【 prejudice , minority 】
ps: Modified from
https://blog.csdn.net/qq_32182461/article/details/82556295
The nodes will execute regularly ping/pong Message to prove the connectivity between nodes , If the node sends to node two ping After the news came pong news , Then node one will update the last communication time with node two , If you don't receive pong news , Then the link between node one and node two will be broken , After that, node one executes again ping news , If the last communication time with node 2 exceeds the specified time , Then node 2 will be marked as subjective offline by node 1 .
Objective offline of nodes 【 A multitude of wills , By half of the votes 】
ps: The following figures are taken from
https://blog.csdn.net/See_Csdn_/article/details/115902857
Sentinels monitor , By half of the votes , I think this node is abnormal , Let him go offline

Then let the slave node server2 Replace as master node , and server1 Perform exception repair , After that , Back online
边栏推荐
- 暴雨去哪儿?天气预报不准谁的锅?
- 嵌入式DSP音频开发
- 【活动早知道】LiveVideoStack近期活动一览
- 基于流的深度生成模型
- 论文阅读:Generative Adversarial Transformers
- RichView TRVStyle ParaStyles
- s32ds跳转到DefaultISR
- [today in history] June 24: Netease was established; The first consumer electronics exhibition was held; The first webcast in the world
- 【小游戏】跑酷
- 访问网站提示:您未被授权查看该页恢复办法
猜你喜欢

Why are so many people keen on big factories because of the great pressure and competition?

音视频技术开发周刊 | 251

R1 Quick Open Pressure Vessel Operation Special Operation Certificate Examination Library and Answers in 2022

2022安全员-C证考试题库模拟考试平台操作

In the digital era, enterprises must do well in user information security

被校园暴力,性格内向的马斯克凄惨而励志的童年

剑指 Offer 53 - I. 在排序数组中查找数字 I(改进二分)

2-5 basic configuration -win2003 add attack surface

文件的相对路径写法

Flow based depth generation model
随机推荐
Apache - Introduction à Apache
Artifact for converting pcap to JSON file: joy (installation)
A16z: metauniverse unlocks new opportunities in game infrastructure
空闲中断无法清除
[plug in -statistical] statistics the number of code lines and related data
一位博士在华为的22年(干货满满)
Is online stock investment exchange group safe? Is it reliable to open an account for free?
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
Gateway微服務路由使微服務靜態資源加載失敗
新手开哪家的证券账户是比较好?炒股开户安全吗
Single page application (SPA) hash route and historical API route
How to write concise code? (upper)
adb双击POWER键指令
Arduino esp8266 web LED control
分布式事务TCC浅析
What are the technologies to be mastered in the test? Database design for software testing
Feign远程调用fallback回调失败,无效果
CI & CD 不可不知!
Le routage des microservices de la passerelle a échoué au chargement des ressources statiques des microservices
[games] Parkour
https://blog.csdn.net/zhangbaoxiang/article/details/107379622