当前位置:网站首页>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
边栏推荐
- 项目实战!手把手教你 Jmeter 性能测试
- Mysql database operation - stored procedure, view, transaction, index, database backup
- 2022 safety officer-c certificate examination question bank simulated examination platform operation
- Packet capturing and sorting out external Fiddler -- understanding the toolbar [1]
- "Everyday Mathematics" serial 53: February 21
- How to write concise code? (upper)
- 业内首个!可运行在移动设备端的视频画质主观体验MOS分评估模型!
- 【插件-statistic】统计代码行数和相关数据
- Windows 2003 64 bit system PHP running error: 1% is not a valid Win32 Application
- RichView TRVStyle
猜你喜欢
![[today in history] June 23: Turing's birthday; The birth of the founder of the Internet; Reddit goes online](/img/d5/4b3e622ab77bc546ca5d285ef67d8a.jpg)
[today in history] June 23: Turing's birthday; The birth of the founder of the Internet; Reddit goes online

基于流的深度生成模型

Flow based depth generation model

分布式事务—基于消息补偿的最终一致性方案(本地消息表、消息队列)

Tips for visiting the website: you are not authorized to view the recovery method of this page

无代码软件发展简史及未来趋势

Gateway microservice routing failed to load microservice static resources

Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队

2022 operation of simulated examination platform of special operation certificate examination question bank for safety management personnel of hazardous chemical business units

be fond of the new and tired of the old? Why do it companies prefer to spend 20K on recruiting rather than raise salaries to retain old employees
随机推荐
买股票通过券商经理的开户链接开户资金是否安全?想开户炒股
2022 electrician (elementary) recurrent training question bank and online simulation examination
2022安全员-C证考试题库模拟考试平台操作
2022危险化学品经营单位安全管理人员特种作业证考试题库模拟考试平台操作
微信小程序中生成二维码
为什么OpenCV计算的帧率是错误的?
Object类,以及__new__,__init__,__setattr__,__dict__
Apache, IIS6 and ii7 independent IP hosts screen and intercept spider crawling (applicable to VPS virtual machine servers)
[522. longest special sequence II]
Raspberry pie - environment settings and cross compilation
Gateway microservice routing failed to load microservice static resources
新手开哪家的证券账户是比较好?炒股开户安全吗
论文阅读:Generative Adversarial Transformers
ETCD数据库源码分析——集群间网络层服务端RaftHandler
You got 8K in the 3-year function test, but were overtaken by the new tester. In fact, you are pretending to work hard
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
您的物联网安全性是否足够强大?
[today in history] June 25: the father of notebook was born; Windows 98 release; First commercial use of generic product code
嵌入式软件开发中必备软件工具
RichView TRVStyle TextStyles
https://blog.csdn.net/zhangbaoxiang/article/details/107379622