Redis 超详细自动管理Cluster集群工具上手 redis-trib.rb (多图,手把手) (2)

​ 执行完这条命令后,输入yes,会看到以下信息:

$ redis-cli --cluster create 192.168.0.120:6379 192.168.0.140:6380 192.168.0.130:6379 192.168.0.120:6380 192.168.0.140:6379 192.168.0.130:6380 --cluster-replicas 1 # 主从相关 >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 192.168.0.140:6379 to 192.168.0.120:6379 Adding replica 192.168.0.130:6380 to 192.168.0.140:6380 Adding replica 192.168.0.120:6380 to 192.168.0.130:6379 M: c71b52f728ab58fedb6e05a525ce00b453fd2f6b 192.168.0.120:6379 slots:[0-5460] (5461 slots) master M: 6a627cedaa4576b1580806ae0094be59c32fa391 192.168.0.140:6380 slots:[5461-10922] (5462 slots) master M: 282358c2fb0c7c16ec60f2c4043b52a0eb91e19f 192.168.0.130:6379 slots:[10923-16383] (5461 slots) master S: d645d06708e1eddb126a6c3c4e38810c188d0906 192.168.0.120:6380 replicates 282358c2fb0c7c16ec60f2c4043b52a0eb91e19f S: 7a7392cb66bea30da401d2cb9768a42bbdefc5db 192.168.0.140:6379 replicates c71b52f728ab58fedb6e05a525ce00b453fd2f6b S: ff53e43f9404981a51d4e744de38004a5c22b090 192.168.0.130:6380 replicates 6a627cedaa4576b1580806ae0094be59c32fa391 # 询问是否保存配置?输入yes Can I set the above configuration? (type 'yes' to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join . # 分槽相关,全部自动进行,无需手动操作 >>> Performing Cluster Check (using node 192.168.0.120:6379) M: c71b52f728ab58fedb6e05a525ce00b453fd2f6b 192.168.0.120:6379 slots:[0-5460] (5461 slots) master 1 additional replica(s) M: 282358c2fb0c7c16ec60f2c4043b52a0eb91e19f 192.168.0.130:6379 slots:[10923-16383] (5461 slots) master 1 additional replica(s) M: 6a627cedaa4576b1580806ae0094be59c32fa391 192.168.0.140:6380 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: d645d06708e1eddb126a6c3c4e38810c188d0906 192.168.0.120:6380 slots: (0 slots) slave replicates 282358c2fb0c7c16ec60f2c4043b52a0eb91e19f S: 7a7392cb66bea30da401d2cb9768a42bbdefc5db 192.168.0.140:6379 slots: (0 slots) slave replicates c71b52f728ab58fedb6e05a525ce00b453fd2f6b S: ff53e43f9404981a51d4e744de38004a5c22b090 192.168.0.130:6380 slots: (0 slots) slave replicates 6a627cedaa4576b1580806ae0094be59c32fa391 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. $

​ 仔细观察上面的主从关系就可以看到异常,我的规划是所有的6379为主节点,而6380为从节点,显然他没有按照我的意思进行划分主从。

​ 这种情况还算好的,至少不同节点都是岔开的,怕就怕一台机器2个实例组成1主1从,如果是那样的结构主从就没有任何意义。

image-20210402113618358

主从校正

​ 由于上面自动部署时主从关系出现了问题,超乎了我们的预期(这可能是该工具的bug),所以我们要对其进行手动校正。

​ 1)登录node3:6380,让其作为node1:6379的从库,由于node3:6380是一个主库,要想变为从库必须先清空它的插槽,而后进行指定:

$ redis-cli -h node3 -p 6380 -c node3:6380> CLUSTER FLUSHSLOTS node3:6380> CLUSTER REPLICATE c71b52f728ab58fedb6e05a525ce00b453fd2f6b

image-20210402112159652

​ 2)登录node3:6379,让该库进行下线,此举是为了重新上线令其角色变为master:

$ redis-cli -h node3 -p 6379 -c node3:6379> CLUSTER RESET

image-20210402155206565

​ 3)登录node1:6379(其实任意集群中的一个都行)重新发现node3:6379,并且记录下缺失的插槽信息:

$ redis-cli -h node1 -p 6379 -c node1:6379> CLUSTER MEET 192.168.0.140 6379 node1:6379> CLUSTER NODES # 仅关注master最后这一部分信息,槽位 connected 10923-16383 connected 0-5460 # 已分配10923-16383、0-5460,缺失的插槽位为5461-10922

image-20210402155330248

​ 4)为node3:6379分配插槽:

$ redis-cli -h node3 -p 6379 cluster addslots {5461..10922}

image-20210402155400594

​ 5)登录node2:6380,让其对应node3:6379,即前者作为后者的从库

$ redis-cli -h node2 -p 6380 node2:6380> CLUSTER REPLICATE 7a7392cb66bea30da401d2cb9768a42bbdefc5db

image-20210402155436436

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwxxsw.html