当前位置:网站首页>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.conf
1. 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.conf
for 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.sh
adopt 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 6378
Take 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
边栏推荐
- 【小程序】使用font-awesome字体图标的解决文案(图文)
- Redis搭建集群【简单】
- 【PaddleDetection】ModuleNotFoundError: No module named ‘paddle‘
- 读书,使人内心宁静
- Question bank and answers of special operation certificate for R1 quick opening pressure vessel operation in 2022
- Why are so many people keen on big factories because of the great pressure and competition?
- Apache, IIS6 and ii7 independent IP hosts screen and intercept spider crawling (applicable to VPS virtual machine servers)
- 2022电工(初级)复训题库及在线模拟考试
- [today in history] June 19: iPhone 3GS launched; Pascal was born; Anti terrorist elite begins testing
- [games] Parkour
猜你喜欢
[today in history] June 19: iPhone 3GS launched; Pascal was born; Anti terrorist elite begins testing
暴雨去哪儿?天气预报不准谁的锅?
栈的基本操作(C语言实现)
PPT制作小技巧
2022年R1快開門式壓力容器操作特種作業證考試題庫及答案
Feign远程调用fallback回调失败,无效果
Mixed programming of C language and assembly language in stm32
【插件-statistic】统计代码行数和相关数据
Simple file transfer protocol TFTP
Brief history and future trend of codeless software
随机推荐
A16z:元宇宙解锁游戏基础设施中的新机遇
More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!
[issue 21] face to face experience of golang engineer recruited by Zhihu Society
2022 operation of simulated examination platform of special operation certificate examination question bank for safety management personnel of hazardous chemical business units
Gateway微服务路由使微服务静态资源加载失败
Embedded DSP audio development
Agileplm exception resolution session
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
ARM Development Studio build编译报错
[games] Parkour
简单ELK配置实现生产级别的日志采集和查询实践
PHP 代码 微信、公众号、企业微信 发送表情符号 [U+1F449]
元宇宙标准论坛成立
Yes, it's about water
Usage details of staticlayout
Is it safe to buy stocks and open an account through the account opening link of the broker manager? Want to open an account for stock trading
Severe Tire Damage:世界上第一个在互联网上直播的摇滚乐队
Summary of software testing tools in 2021 - fuzzy testing tools
如何编写简洁代码?(上)
[today in history] June 19: iPhone 3GS launched; Pascal was born; Anti terrorist elite begins testing