Redis study concluded (f) - Redis cluster telescopic

In the last chapter we talked about how to create a cluster, today we realize stretch under cluster.

Add Nodes

Operating procedures

1. Start node
2. The node is added to the cluster
3. The data portion of the slot to migrate from the original node to a new node

practice

1) prepare and launch two new nodes

[root@VM_0_15_centos config]# sed 's/7000/7006/g' redis-7000.conf > redis-7006.conf
[root@VM_0_15_centos config]# sed 's/7000/7007/g' redis-7000.conf > redis-7007.conf
[root@VM_0_15_centos config]# cd ..
[root@VM_0_15_centos redis4]# ./redis-server config/redis-7006.conf
[root@VM_0_15_centos redis4]# ./redis-server config/redis-7007.conf
[root@VM_0_15_centos redis4]# ps -ef | grep redis
root     10788     1  0 14:20 ?        00:00:00 ./redis-server *:7006 [cluster]
root     10793     1  0 14:20 ?        00:00:00 ./redis-server *:7007 [cluster]
root     10817  1362  0 14:21 pts/0    00:00:00 grep --color=auto redis
root     29570     1  0 10:15 ?        00:00:11 ./redis-server *:7000 [cluster]
root     29575     1  0 10:15 ?        00:00:10 ./redis-server *:7001 [cluster]
root     29581     1  0 10:15 ?        00:00:12 ./redis-server *:7002 [cluster]
root     29587     1  0 10:15 ?        00:00:12 ./redis-server *:7003 [cluster]
root     29593     1  0 10:15 ?        00:00:11 ./redis-server *:7004 [cluster]
root     29599     1  0 10:15 ?        00:00:11 ./redis-server *:7005 [cluster]

2) will join the cluster nodes

There are two ways you can add:

  • Native Command
  • redis-trib tool

Native Command

# 进入任一集群节点
[root@VM_0_15_centos redis4]# ./redis-cli -p 7000
# 将新增加的节点加入到集群中来
127.0.0.1:7000> cluster meet 127.0.0.1 7006
OK
127.0.0.1:7000> cluster meet 127.0.0.1 7007
OK

redis-trib tool

redis-trib.rb add-node 127.0.0.1:6387 127.0.0.1:7006
redis-trib.rb add-node 127.0.0.1:6388 127.0.0.1:7007

The beginning of a new node is the master node status, but due to the slots are not responsible, we can not accept any read or write operation. For subsequent operation of the new node are generally two options:

◆ for it to achieve data migration and expansion slots

◆ As other node failover from the primary node is responsible

3) slots and data migration, the migration section of the tank port 7000 to port 7006

# redis-trib.rb 执行槽重分片命令
[root@VM_0_15_centos redis4]# ./redis-trib.rb reshard 127.0.0.1:7000
>>> Performing Cluster Check (using node 127.0.0.1:7000)
M: 5de648cc0cc7c503169638bbe3a56fc3f4c3aa72 127.0.0.1:7000
   slots:666-5460 (4795 slots) master
   0 additional replica(s)
M: 90ab3e9992a4b0f6abddc75d03fce63099b4fb38 127.0.0.1:7003
   slots:6128-10922 (4795 slots) master
   1 additional replica(s)
M: 65cc70270ae44c1c8ca29bb09c609b5b5c878eef 127.0.0.1:7007
   slots: (0 slots) master
   0 additional replica(s)
S: 892668ae60f407be5094a667f3532e760b867e64 127.0.0.1:7005
   slots: (0 slots) slave
   replicates 90ab3e9992a4b0f6abddc75d03fce63099b4fb38
M: 1e3ec7626adcb2662700aa0ca9933d60232847a6 127.0.0.1:7002
   slots:11589-16383 (4795 slots) master
   1 additional replica(s)
M: 03274e13cb092f92a51a05a5eaca3a7a5618c356 127.0.0.1:7006
   slots:0-665,5461-6127,10923-11588 (1999 slots) master
   0 additional replica(s)
S: 5a2bbf95047bdf9719ca60152cf91e48e8a956bd 127.0.0.1:7004
   slots: (0 slots) slave
   replicates 1e3ec7626adcb2662700aa0ca9933d60232847a6
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
# 需要迁移的槽数量,这里选择2000
How many slots do you want to move (from 1 to 16384)? 2000
# 选择要迁移到的目标节点,这里选择 7006 端口对应的节点
What is the receiving node ID? 03274e13cb092f92a51a05a5eaca3a7a5618c356
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
# 输入源节点的ID,这里选择全部 all
Source node #1: all
# 数据迁移之前会打印出所有的槽从源节点到目标节点的计划,确认计划无误后输入 yes 执行迁移工作,计划执行完成之后reshard命令自动退出。
Do you want to proceed with the proposed reshard plan (yes/no)? yes

4) The port 70007 to port 7006 from the server

[root@VM_0_15_centos redis4]# ./redis-cli -h 127.0.0.1 -p 7000 cluster nodes
90ab3e9992a4b0f6abddc75d03fce63099b4fb38 127.0.0.1:7003@17003 master - 0 1542955379299 2 connected 6794-10922
65cc70270ae44c1c8ca29bb09c609b5b5c878eef 127.0.0.1:7007@17007 master - 0 1542955376000 0 connected
892668ae60f407be5094a667f3532e760b867e64 127.0.0.1:7005@17005 slave 90ab3e9992a4b0f6abddc75d03fce63099b4fb38 0 1542955376000 6 connected
1e3ec7626adcb2662700aa0ca9933d60232847a6 127.0.0.1:7002@17002 master - 0 1542955376294 3 connected 12255-16383
03274e13cb092f92a51a05a5eaca3a7a5618c356 127.0.0.1:7006@17006 master - 0 1542955378298 7 connected 0-1332 5461-6793 10923-12254
5a2bbf95047bdf9719ca60152cf91e48e8a956bd 127.0.0.1:7004@17004 slave 1e3ec7626adcb2662700aa0ca9933d60232847a6 0 1542955377296 4 connected
5de648cc0cc7c503169638bbe3a56fc3f4c3aa72 127.0.0.1:7000@17000 myself,master - 0 1542955377000 1 connected 1333-5460
[root@VM_0_15_centos redis4]# ./redis-cli -h 127.0.0.1 -p 7007 cluster replicate 03274e13cb092f92a51a05a5eaca3a7a5618c356
OK

Delete Node

Operating procedures

Delete nodes with increased node process is just the opposite:

1. The tank migrate data from the current node to another node
2. Let the other node forget the current node
3. The node service stops

practice

1) migration groove

View node information

[root@VM_0_15_centos redis4]# ./redis-cli -h 127.0.0.1 -p 7000 cluster nodes
90ab3e9992a4b0f6abddc75d03fce63099b4fb38 127.0.0.1:7003@17003 master - 0 1542955959000 2 connected 6794-10922
65cc70270ae44c1c8ca29bb09c609b5b5c878eef 127.0.0.1:7007@17007 slave 03274e13cb092f92a51a05a5eaca3a7a5618c356 0 1542955961405 7 connected
892668ae60f407be5094a667f3532e760b867e64 127.0.0.1:7005@17005 slave 90ab3e9992a4b0f6abddc75d03fce63099b4fb38 0 1542955960404 6 connected
1e3ec7626adcb2662700aa0ca9933d60232847a6 127.0.0.1:7002@17002 master - 0 1542955959402 3 connected 12255-16383
03274e13cb092f92a51a05a5eaca3a7a5618c356 127.0.0.1:7006@17006 master - 0 1542955958400 7 connected 0-1332 5461-6793 10923-12254
5a2bbf95047bdf9719ca60152cf91e48e8a956bd 127.0.0.1:7004@17004 slave 1e3ec7626adcb2662700aa0ca9933d60232847a6 0 1542955958000 4 connected
5de648cc0cc7c503169638bbe3a56fc3f4c3aa72 127.0.0.1:7000@17000 myself,master - 0 1542955959000 1 connected 1333-5460

Three grooves can be seen on the scope of the node 7006 0-1332 5461-6793 10923-12254

# 从 7006 节点迁移 1333 槽到 7000 节点
[root@VM_0_15_centos redis4]# ./redis-trib.rb reshard --from 03274e13cb092f92a51a05a5eaca3a7a5618c356 --to 5de648cc0cc7c503169638bbe3a56fc3f4c3aa72 --slots 1333 127.0.0.1:7006
# 确认迁移
Do you want to proceed with the proposed reshard plan (yes/no)? yes

In the view the next node information

[root@VM_0_15_centos redis4]# ./redis-cli -h 127.0.0.1 -p 7000 cluster nodes
03274e13cb092f92a51a05a5eaca3a7a5618c356 127.0.0.1:7006@17006 master - 0 1542956707000 7 connected 5461-6793 10923-12254

7006 node can only see 5461-6793and 10923-12254, in turn migrate

[root@VM_0_15_centos redis4]# ./redis-trib.rb reshard --from 03274e13cb092f92a51a05a5eaca3a7a5618c356 --to 5de648cc0cc7c503169638bbe3a56fc3f4c3aa72 --slots 1333 127.0.0.1:7006
[root@VM_0_15_centos redis4]# ./redis-trib.rb reshard --from 03274e13cb092f92a51a05a5eaca3a7a5618c356 --to 5de648cc0cc7c503169638bbe3a56fc3f4c3aa72 --slots 1 127.0.0.1:7006

View node information:

[root@VM_0_15_centos redis4]# ./redis-cli -h 127.0.0.1 -p 7000 cluster nodes
03274e13cb092f92a51a05a5eaca3a7a5618c356 127.0.0.1:7006@17006 master - 0 1542956939273 7 connected

It has no groove a.

2) Forget node

# 先下从节点 7007 端口
[root@VM_0_15_centos redis4]# ./redis-trib.rb del-node 127.0.0.1:7000 65cc70270ae44c1c8ca29bb09c609b5b5c878eef
>>> Removing node 65cc70270ae44c1c8ca29bb09c609b5b5c878eef from cluster 127.0.0.1:7000
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
# 再下主节点 7006 端口
[root@VM_0_15_centos redis4]# ./redis-trib.rb del-node 127.0.0.1:7000 03274e13cb092f92a51a05a5eaca3a7a5618c356
>>> Removing node 03274e13cb092f92a51a05a5eaca3a7a5618c356 from cluster 127.0.0.1:7000
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
# 查看节点情况
[root@VM_0_15_centos redis4]# ./redis-cli -h 127.0.0.1 -p 7000 cluster nodes
90ab3e9992a4b0f6abddc75d03fce63099b4fb38 127.0.0.1:7003@17003 master - 0 1542957326994 2 connected 6794-10922
892668ae60f407be5094a667f3532e760b867e64 127.0.0.1:7005@17005 slave 90ab3e9992a4b0f6abddc75d03fce63099b4fb38 0 1542957325992 6 connected
1e3ec7626adcb2662700aa0ca9933d60232847a6 127.0.0.1:7002@17002 master - 0 1542957327995 3 connected 12255-16383
5a2bbf95047bdf9719ca60152cf91e48e8a956bd 127.0.0.1:7004@17004 slave 1e3ec7626adcb2662700aa0ca9933d60232847a6 0 1542957325000 4 connected
5de648cc0cc7c503169638bbe3a56fc3f4c3aa72 127.0.0.1:7000@17000 myself,master - 0 1542957326000 8 connected 0-6793 10923-12254

View Redis process

[root@VM_0_15_centos redis4]# ps -ef | grep redis
root      9326  1362  0 15:17 pts/0    00:00:00 grep --color=auto redis
root     29570     1  0 10:15 ?        00:00:17 ./redis-server *:7000 [cluster]
root     29575     1  0 10:15 ?        00:00:12 ./redis-server *:7001 [cluster]
root     29581     1  0 10:15 ?        00:00:17 ./redis-server *:7002 [cluster]
root     29587     1  0 10:15 ?        00:00:17 ./redis-server *:7003 [cluster]
root     29593     1  0 10:15 ?        00:00:14 ./redis-server *:7004 [cluster]
root     29599     1  0 10:15 ?        00:00:14 ./redis-server *:7005 [cluster]

You can see the 7006 and 7007 service port has stopped

Guess you like

Origin www.cnblogs.com/markLogZhu/p/11418927.html