redis 流水笔记 十 集群伸缩 ?

集群伸缩本质:

槽 和 数据 在节点之间移动

--- 集群扩容 ?

    意义:  实现集群的扩容,2. 进行故障转移,更换硬盘主机等。

1、 新建一个配置文件,和集群的其他配置文件保持一致。

[root@hadoop05 cluster]# sed 's/8000/8006/g' redis-8000.conf > redis-8006.conf
[root@hadoop05 cluster]# sed 's/8000/8007/g' redis-8000.conf > redis-8007.conf

2、通过meet

  

127.0.0.1:8000> cluster meet 127.0.0.1 8006
OK
127.0.0.1:8000> cluster meet 127.0.0.1 8007
OK

3、设置主从节点

[root@hadoop05 bin]# ./redis-cli -p 8006 cluster replicate 5623991f7d23e0dc09f17e19688d3a65b91002f0
OK

4、使用reshard 进行 slot 和数据迁移。

[root@hadoop05 bin]# ./redis-cli --cluster reshard 127.0.0.1:8007
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 4096

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.
Source node #1: all

Ready to move 4096 slots.
  Source nodes:
    M: 30309728ad48df61e40d6f476740579e66398b02 127.0.0.1:8001
       slots:[5461-10922] (5462 slots) master
       1 additional replica(s)
    M: d238b4d6c4c54a614a57f0c6f99d07c296f9ff1b 127.0.0.1:8004
       slots:[0-5460] (5461 slots) master
       1 additional replica(s)
    M: ba807182f5cc573fc100d4d64ef9a4b1ecf0419f 127.0.0.1:8002
       slots:[10923-16383] (5461 slots) master
       1 additional replica(s)
  Destination node:
    M: 5623991f7d23e0dc09f17e19688d3a65b91002f0 127.0.0.1:8007
       slots: (0 slots) master
       1 additional replica(s)
  Resharding plan:
    Moving slot 5461 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5462 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5463 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5464 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5465 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5466 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5467 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5468 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5469 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5470 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5471 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5472 from 30309728ad48df61e40d6f476740579e66398b02
    Moving slot 5473 from 30309728ad48df61e40d6f476740579e66398b02

查看集群是否迁移OK?

127.0.0.1:8000> exit
[root@hadoop05 bin]# ./redis-cli  -p 8000 cluster nodes | grep master
5623991f7d23e0dc09f17e19688d3a65b91002f0 127.0.0.1:8007@18007 master - 0 1576503294000 8 connected 0-1364 5461-6826 10923-12287
30309728ad48df61e40d6f476740579e66398b02 127.0.0.1:8001@18001 master - 0 1576503295374 2 connected 6827-10922
d238b4d6c4c54a614a57f0c6f99d07c296f9ff1b 127.0.0.1:8004@18004 master - 0 1576503295000 7 connected 1365-5460
ba807182f5cc573fc100d4d64ef9a4b1ecf0419f 127.0.0.1:8002@18002 master - 0 1576503291000 3 connected 12288-16383

可以看到确实已经发生了迁移。

使用脚本关闭节点:

#!/bin/bash
ps -ef | grep redis-server | grep 800 | awk '{ print $2 }' | xargs kill
if [ $? = 0 ];then
  echo " execute success ! ";
fi
[root@hadoop05 bin]# ./stop-redis-cluster.sh 
 execute success ! 

[root@hadoop05 bin]# ps -ef | grep redis-server 
root      7788  3892  0 21:41 pts/0    00:00:00 grep --color=auto redis-server
发布了61 篇原创文章 · 获赞 1 · 访问量 657

猜你喜欢

转载自blog.csdn.net/u012842247/article/details/103570564
今日推荐