当前位置:网站首页>Redis cluster deployment based on redis6.2.4
Redis cluster deployment based on redis6.2.4
2022-07-25 16:57:00 【wwzroom】
be based on redis6.2.4 Of redis cluster Deploy
Experimental framework 
1. Modify profile enable cluster function
1. Modify hostname
hostnamectl set-hostname node1.magedu.org;exit
hostnamectl set-hostname node2.magedu.org;exit
hostnamectl set-hostname node3.magedu.org;exit
hostnamectl set-hostname node4.magedu.org;exit
hostnamectl set-hostname node5.magedu.org;exit
hostnamectl set-hostname node6.magedu.org;exit
2. install redis6.2.4
Script to achieve one click installation : See https://blog.csdn.net/aa896517050/article/details/125955201
3. Modify the configuration file ( All nodes )
sed -i.bak -e '/masterauth/a masterauth 123456' -e '/# cluster-enabled yes/a cluster-enabled yes' -e '/# cluster-config-file nodes-6379.conf/a cluster-config-file nodes-6379.conf' -e '/# cluster-require-full-coverage yes/c cluster-require-full-coverage no' /apps/redis/etc/redis.conf
4. Restart the service ( All nodes )
systemctl enable --now redis
[[email protected]:~]#
ps aux|grep redis
redis 5578 0.1 0.1 162500 2944 ? Ssl Jul24 0:06 /apps/redis/bin/redis-server 0.0.0.0:6379
root 5866 0.0 0.0 112808 968 pts/0 S+ 00:24 0:00 grep --color=auto redis
# Restart again
systemctl restart redis
[[email protected]:~]#
ps aux|grep redis
redis 6013 0.1 0.1 162500 3520 ? Ssl 00:57 0:00 /apps/redis/bin/redis-server 0.0.0.0:6379 [cluster] #cluster sign
root 6021 0.0 0.0 112808 968 pts/0 S+ 00:58 0:00 grep --color=auto redis
[[email protected]:~]#
redis-cli -a 123456
127.0.0.1:6379> info cluster
# Cluster
cluster_enabled:1
2. All nodes interact with each other meet
1. Check the connection
[[email protected]:~]#
redis-cli -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
fdec26daee7636c212283fd8b32c8088e54a6655 :[email protected] myself,master - 0 0 0 connected
# There is no connection with any one at this time ,6 Each node is independent .
2. On any node and all other nodes meet signal communication ( This time at node1 operation ,node1 It's the middleman , All connected )
[[email protected]:~]#
redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.17 6379
[[email protected]:~]#
ss -nt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
ESTAB 0 0 10.0.0.7:36605 10.0.0.17:16379
ESTAB 0 36 10.0.0.7:22 10.0.0.1:51254
ESTAB 0 0 10.0.0.7:16379 10.0.0.17:44342
# The cluster port is 16379、
[[email protected]:~]#
redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.27 6379
OK
[[email protected]:~]#
redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.37 6379
OK
[[email protected]:~]#
redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.47 6379
OK
[[email protected]:~]#
redis-cli -a 123456 --no-auth-warning cluster meet 10.0.0.57 6379
OK
# Check the connection
[[email protected]:~]#
redis-cli -a 123456 cluster info
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6 # Express 6 Connections have been established between nodes
cluster_size:0
cluster_current_epoch:5
cluster_my_epoch:0
cluster_stats_messages_ping_sent:468
cluster_stats_messages_pong_sent:475
cluster_stats_messages_meet_sent:6
cluster_stats_messages_sent:949
cluster_stats_messages_ping_received:475
cluster_stats_messages_pong_received:474
cluster_stats_messages_received:949
[[email protected]:~]#
redis-cli -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
4e456d304f1971c3fe776c21d8dd2c880dd29fd2 10.0.0.27:[email protected] master - 0 1658683099799 2 connected
008abaa9cf3b273f905a26838f675c1be17b8570 10.0.0.37:[email protected] master - 0 1658683097000 3 connected
c30419b368a783f4c4d9de948dcc7f3d44ee4797 10.0.0.17:[email protected] master - 0 1658683098000 1 connected
f941e86ede0fad0dfe70b5ee6ad0577e21cb0d98 10.0.0.47:[email protected] master - 0 1658683099000 4 connected
46b3deba6bdaf57e481cce86f4335963d555dcdc 10.0.0.57:[email protected] master - 0 1658683096000 5 connected
fdec26daee7636c212283fd8b32c8088e54a6655 10.0.0.7:[email protected] myself,master - 0 1658683098000 0 connected
3. Assign slots ( Script implementation )
[[email protected]:~]#
vim addslot.sh
#!/bin/bash
#****************************************************
#Date: 2022-07-25
#Author: wwzroom
#FileName: addslot.sh
#Description: The test script
#QQ: 896517050
#sh****************************************************
host=$1
port=$2
start=$3
end=$4
pass=123456
for slot in `seq ${
start} ${
end}`;do
echo slot:$slot
redis-cli -h ${host} -p $port -a ${pass} --no-auth-warning cluster addslots ${slot}
done
2. Add execute permission
[[email protected]:~]#
chmod +x addslot.sh
3. Assign slots
[[email protected]:~]#
./addslot.sh 10.0.0.7 6379 0 5461
[[email protected]:~]#
./addslot.sh 10.0.0.17 6379 5462 10922
[[email protected]:~]#
./addslot.sh 10.0.0.27 6379 10923 16383
# When allocating, if the first node is allocated incorrectly , When the second node is reallocated , It can't be allocated , It doesn't affect the experiment , If the first score is too much , There is no way to divide the back , Therefore, the recorded file can be deleted ,rm -rf /apps/redis/data/nodes-6379.conf, again meet, Redistribution .
# View allocation
[[email protected]:~]#
redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> cluster nodes
4e456d304f1971c3fe776c21d8dd2c880dd29fd2 10.0.0.27:[email protected] master - 0 1658684953613 2 connected 10923-16383
008abaa9cf3b273f905a26838f675c1be17b8570 10.0.0.37:[email protected] master - 0 1658684952000 3 connected
c30419b368a783f4c4d9de948dcc7f3d44ee4797 10.0.0.17:[email protected] master - 0 1658684953000 1 connected 5462-10922
f941e86ede0fad0dfe70b5ee6ad0577e21cb0d98 10.0.0.47:[email protected] master - 0 1658684953000 4 connected
46b3deba6bdaf57e481cce86f4335963d555dcdc 10.0.0.57:[email protected] master - 0 1658684952609 5 connected
fdec26daee7636c212283fd8b32c8088e54a6655 10.0.0.7:[email protected] myself,master - 0 1658684951000 0 connected 0-5461
4. Specify the master-slave relationship of each node
[[email protected]:~]#
redis-cli -h 10.0.0.37 -a 123456 --no-auth-warning cluster replicate fdec26daee7636c212283fd8b32c8088e54a6655 # The master node id, Set up here 37 by 07 The slave node ,id Number is 07 Of ,ID No. has the above nodes Information acquisition .
[[email protected]:~]#
redis-cli -h 10.0.0.47 -a 123456 --no-auth-warning cluster replicate c30419b368a783f4c4d9de948dcc7f3d44ee4797
[[email protected]:~]#
redis-cli -h 10.0.0.57 -a 123456 --no-auth-warning cluster replicate 4e456d304f1971c3fe776c21d8dd2c880dd29fd2
# Check the details
[[email protected]:~]#
redis-cli -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
4e456d304f1971c3fe776c21d8dd2c880dd29fd2 10.0.0.27:[email protected] master - 0 1658686186000 2 connected 10923-16383
008abaa9cf3b273f905a26838f675c1be17b8570 10.0.0.37:[email protected] slave fdec26daee7636c212283fd8b32c8088e54a6655 0 1658686187701 0 connected
c30419b368a783f4c4d9de948dcc7f3d44ee4797 10.0.0.17:[email protected] master - 0 1658686186693 1 connected 5462-10922
f941e86ede0fad0dfe70b5ee6ad0577e21cb0d98 10.0.0.47:[email protected] slave c30419b368a783f4c4d9de948dcc7f3d44ee4797 0 1658686185684 1 connected
46b3deba6bdaf57e481cce86f4335963d555dcdc 10.0.0.57:[email protected] slave 4e456d304f1971c3fe776c21d8dd2c880dd29fd2 0 1658686185000 2 connected
fdec26daee7636c212283fd8b32c8088e54a6655 10.0.0.7:[email protected] myself,master - 0 1658686185000 0 connected 0-5461
[[email protected]:~]#
redis-cli -a 123456 cluster info
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3 #3 Group cluster
cluster_current_epoch:5
cluster_my_epoch:0
cluster_stats_messages_ping_sent:3721
cluster_stats_messages_pong_sent:3753
cluster_stats_messages_meet_sent:6
cluster_stats_messages_sent:7480
cluster_stats_messages_ping_received:3753
cluster_stats_messages_pong_received:3727
cluster_stats_messages_received:7480
[[email protected]:~]#
redis-cli -a 123456 --no-auth-warning cluster slots
1) 1) (integer) 0
2) (integer) 5461
3) 1) "10.0.0.7"
2) (integer) 6379
3) "fdec26daee7636c212283fd8b32c8088e54a6655"
4) 1) "10.0.0.37"
2) (integer) 6379
3) "008abaa9cf3b273f905a26838f675c1be17b8570"
2) 1) (integer) 5462
2) (integer) 10922
3) 1) "10.0.0.17"
2) (integer) 6379
3) "c30419b368a783f4c4d9de948dcc7f3d44ee4797"
4) 1) "10.0.0.47"
2) (integer) 6379
3) "f941e86ede0fad0dfe70b5ee6ad0577e21cb0d98"
3) 1) (integer) 10923
2) (integer) 16383
3) 1) "10.0.0.27"
2) (integer) 6379
3) "4e456d304f1971c3fe776c21d8dd2c880dd29fd2"
4) 1) "10.0.0.57"
2) (integer) 6379
3) "46b3deba6bdaf57e481cce86f4335963d555dcdc"
5. Write data test
1. Connect any master node to write data , about key Value for hash operation ( And value irrelevant ), Then re allocate according to the card slot relationship , If not assigned to this node , You will be prompted to report an error (error) MOVED 7755 10.0.0.17:6379, Prompt to put in the specific slot .
[[email protected]:~]#
redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set class m44
(error) MOVED 7755 10.0.0.17:6379
127.0.0.1:6379>
2 Log in to the specified slot to write data , Can succeed , You cannot check the data at the slave node , Not enabled
[[email protected]:~]#
redis-cli -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set class m44
OK
# Data cannot be queried from the node , That is, read and write can only be provided by the master node , The slave node cannot provide services .
127.0.0.1:6379> keys class
1) "class"
127.0.0.1:6379> get class
(error) MOVED 7755 10.0.0.17:6379
3. Specify the options -c Indicates accessing in a cluster , There is no limit on the , Master or slave login can be used .
[[email protected]:~]#
redis-cli -c -a 123456 --no-auth-warning set name wang
OK
[[email protected]:~]#
redis-cli -c -a 123456 --no-auth-warning get name
"wang"
# Prompt to redirect to a specific node .
[[email protected]:~]#
redis-cli -a 123456 -c # Log in as a cluster
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> set age 20
-> Redirected to slot [741] located at 10.0.0.7:6379
OK
10.0.0.7:6379> get age
"20"
10.0.0.7:6379> set class M47
-> Redirected to slot [7755] located at 10.0.0.17:6379
OK
10.0.0.17:6379> get class
"M47"
边栏推荐
猜你喜欢

Automatic reply of wechat official account development message
![[knowledge atlas] practice -- Practice of question answering system based on medical knowledge atlas (Part3): rule-based problem classification](/img/4c/aeebbc9698f8d5c23ed6473c9aca34.png)
[knowledge atlas] practice -- Practice of question answering system based on medical knowledge atlas (Part3): rule-based problem classification

Bo Yun container cloud and Devops platform won the trusted cloud "technology best practice Award"

jenkins的文件参数,可以用来上传文件

谁动了我的内存,揭秘 OOM 崩溃下降 90% 的秘密

Fastadmin TP installation uses Baidu rich text editor ueeditor

Rainbond插件扩展:基于Mysql-Exporter监控Mysql

虚拟内存管理

After 20 years of agitation, the chip production capacity has started from zero to surpass that of the United States, which is another great achievement made in China

Various useful forms of London Silver K-line chart
随机推荐
Baidu rich text editor ueeditor single image upload cross domain
在华为昇腾Ascend910上复现swin_transformer
MySQL linked table query, common functions, aggregate functions
企业直播风起:目睹聚焦产品,微赞拥抱生态
中国芯片自给率大幅提升,导致外国芯片库存高企而损失惨重,美国芯片可谓捧起石头砸自己的脚...
Register service instances in ngmodule through dependency injection
QT ListView 列表显示组件笔记
第五章:流程控制
用秩讨论线性方程组的解/三个平面的位置关系
3D semantic segmentation - scribed supervised lidar semantic segmentation
152. Product maximum subarray
[mathematical modeling and drawing series tutorial] II. Drawing and optimization of line chart
Baidu rich text editor ueeditor image width 100% adaptive, mobile terminal
什么是链游系统开发?链游系统开发如何制作
Step by step introduction of sqlsugar based development framework (13) -- package the upload component based on elementplus, which is convenient for the project
What is the monthly salary of 10000 in China? The answer reveals the cruel truth of income
【目标检测】YOLOv5跑通VisDrone数据集
Frustrated Internet people desperately knock on the door of Web3
[book club issue 13] +ffmpeg video capture function
[redis] redis installation