当前位置:网站首页>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
边栏推荐
- QEMU monitor usage
- 新手开哪家的证券账户是比较好?炒股开户安全吗
- Built in functions for MySQL database operations
- 微信小程序中生成二维码
- Apache——阿帕奇簡介
- 为什么OpenCV计算的帧率是错误的?
- 2022电工(初级)复训题库及在线模拟考试
- Tencent games released more than 40 products and projects, including 12 new games
- Notepad++--常用的插件
- Which securities platform is the best and safest for a novice to open a stock trading account
猜你喜欢

Inference optimization implementation of tensorrt model

ETCD数据库源码分析——集群间网络层服务端RaftHandler

What are the technologies to be mastered in the test? Database design for software testing

一位博士在华为的22年(干货满满)

__getitem__和__setitem__

CI & CD 不可不知!

基于流的深度生成模型

【Kotlin】在Android官方文档中对其语法的基本介绍和理解

2022电工(初级)复训题库及在线模拟考试

collections.defaultdict()的使用
随机推荐
视频编解码性能优化与实现
导致系统性能失败的十个原因
在excel文件上设置下拉选项
剑指 Offer 47. 礼物的最大价值(DP)
腾讯游戏发布40多款产品与项目 其中12款为新游戏
ARM Development Studio build编译报错
Dataloader参数collate_fn的使用
[issue 21] face to face experience of golang engineer recruited by Zhihu Society
windows 2003 64位系统php运行报错:1% 不是有效的 win32 应用程序
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
Mysql database operation - stored procedure, view, transaction, index, database backup
文件的相对路径写法
Heartless sword Chinese English bilingual poem 004 Sword
Simple elk configuration to realize production level log collection and query practice
剑指 Offer 49. 丑数(三指针法)
2022安全员-C证考试题库模拟考试平台操作
How to judge that the thread pool has completed all tasks?
国泰君安证券靠谱吗?开证券账户安全吗?
JDBC and MySQL databases
[today in history] June 18: JD was born; The online store platform Etsy was established; Facebook releases Libra white paper
https://blog.csdn.net/zhangbaoxiang/article/details/107379622