沃梦达 / 编程技术 / 数据库 / 正文

redis集群搭建及问题的决方法(二)

一、准备好有三个主节点的集群127.0.0.1:8000 cluster nodes8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000 myself,master - 0 0 1 connected 0-54606f4a31fc322725fc4ed453a588f344fed4f261bf 10....

一、准备好有三个主节点的集群
127.0.0.1:8000> cluster nodes
8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000 myself,master - 0 0 1 connected 0-5460
6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001 master - 0 1538582282356 2 connected 5461-10922
da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002 master - 0 1538582283359 3 connected 10923-16383
测试了下,可以按key值转发到对应的槽道节点存放
127.0.0.1:8000> set name lihua
-> Redirected to slot [5798] located at 10.211.55.5:8001
OK
10.211.55.5:8001>

二、动态添加主节点
[root@cenos01 src]# ./redis-trib.rb add-node 10.211.55.5:8003 10.211.55.5:8000

Adding node 10.211.55.5:8003 to cluster 10.211.55.5:8000
Performing Cluster Check (using node 10.211.55.5:8000)
M: 8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000
slots:0-5460 (5461 slots) master
0 additional replica(s)
M: 6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001
slots:5461-10922 (5462 slots) master
0 additional replica(s)
M: da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002
slots:10923-16383 (5461 slots) master
0 additional replica(s)
[OK] All nodes agree about slots configuration.

Check for open slots…
Check slots coverage…
[OK] All 16384 slots covered.

Send CLUSTER MEET to node 10.211.55.5:8003 to make it join the cluster.
[OK] New node added correctly.

注意:8003是新节点,8000是集群中的任意一个节点

三、添加成功后,查询集群节点信息,但此时还没有槽道
10.211.55.5:8001> cluster nodes
da23623c6e915de5256bb2252cd1057d4f29e558 10.211.55.5:8003 master - 0 1538583102565 0 connected
6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001 myself,master - 0 0 2 connected 5461-10922
8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000 master - 0 1538583103571 1 connected 0-5460
da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002 master - 0 1538583104576 3 connected 10923-16383
10.211.55.5:8001>

四、动态添加从节点
把8004作为8001的从节点加入到集群中
–slave 指定当前节点以从节点角色添加到集群中
–master-id 后面跟随主节点的masterid值,cluster nodes可以查看
[root@cenos01 src]# ./redis-trib.rb add-node --slave --master-id 6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8004 10.211.55.5:8000

五、添加完成后检查结果:

10.211.55.5:8001> cluster nodes
da23623c6e915de5256bb2252cd1057d4f29e558 10.211.55.5:8003 master - 0 1538583619331 0 connected
3f3049540ba60e30080847e78ccf832f94961da2 10.211.55.5:8004 slave 6f4a31fc322725fc4ed453a588f344fed4f261bf 0 1538583620339 2 connected
6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001 myself,master - 0 0 2 connected 5461-10922
8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000 master - 0 1538583622352 1 connected 0-5460
da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002 master - 0 1538583621346 3 connected 10923-16383

以上就是redis集群的搭建过程。

为新添加的节点分配槽道信息见本人的下一篇博文

本文标题为:redis集群搭建及问题的决方法(二)

基础教程推荐