① 查看各个节点&槽位分布信息 192.168.163.132:6379> cluster nodes d401769f9a7b981b16fb27b5b8beecd9ee05f5c1 192.168.163.132:6381@16381 master - 0 1582013073869 0 connected 10923-16383 2d76972e12d954f2d08305f89790515ebef8e32c 192.168.163.132:6380@16380 master - 0 1582013072000 1 connected 1000 2000 5462-10922 97cd26d8506d3b5cd743581bc9dbc8ebf54e1b18 192.168.163.132:6379@16379 myself,master - 0 1582013072000 3 connected 0-999 1001-1999 2001-5461 1b6abbd86b5db73c0ec94fce479054553dc2cfb4 192.168.163.132:6382@16382 slave 97cd26d8506d3b5cd743581bc9dbc8ebf54e1b18 0 1582013072862 11 connected ② 查看需要迁移槽位的 key 192.168.163.132:6379> cluster keyslot b ( integer ) 3300 192.168.163.132:6379> cluster getkeysinslot 3300 10 1) "b" 说明:迁移3300槽到其他主节点,在迁移槽之前,需要把该槽位的keys全部迁移。 ③ 到目标节点执行导入操作 192.168.163.132:6380> cluster setslot 3300 importing 97cd26d8506d3b5cd743581bc9dbc8ebf54e1b18 OK 192.168.163.132:6380> cluster nodes ... 2d76972e12d954f2d08305f89790515ebef8e32c 192.168.163.132:6380@16380 myself,master - 0 1582013668000 1 connected 1000 2000 5462-10922 [3300-<-97cd26d8506d3b5cd743581bc9dbc8ebf54e1b18] ... ④ 到源节点进行迁移操作 192.168.163.132:6379> cluster setslot 3300 migrating 2d76972e12d954f2d08305f89790515ebef8e32c OK 192.168.163.132:6379> cluster nodes ... 97cd26d8506d3b5cd743581bc9dbc8ebf54e1b18 192.168.163.132:6379@16379 myself,master - 0 1582013709000 3 connected 0-999 1001-1999 2001-5461 [3300->-2d76972e12d954f2d08305f89790515ebef8e32c] ... 说明:此时处于迁移状态节点的槽都正常访问 ⑤ 在源节点迁移槽位中的 key 到目标节点:MIGRATE host port key destination-db timeout [COPY] [ REPLACE ] 192.168.163.132:6379> migrate 192.168.163.132 6380 b 0 5000 replace auth cc OK 说明:如果该槽位下有多个keys,重复执行⑤的操作,知道该槽位的keys被迁移完毕。 注意:此时处于迁移状态的 key 不可用(不能读和写),如果是大 key ,则应用可能出现超时,该slot下的其他 key 不受影响。即该slot上的 key 被迁移,只在迁移状态的 key 受影响,其他 key 正常(在目标节点执行restore指令到原节点删除 key 之间,原节点的主线程会处于阻塞状态,直到 key 被成功删除)。 ⑥ 最后设置槽位到指定节点,命令将会广播给集群其他节点,也可以在多个节点设置 192.168.163.132:6379> CLUSTER SETSLOT 3300 node 2d76972e12d954f2d08305f89790515ebef8e32c OK 192.168.163.132:6380> CLUSTER SETSLOT 3300 node 2d76972e12d954f2d08305f89790515ebef8e32c OK 192.168.163.132:6381> CLUSTER SETSLOT 3300 node 2d76972e12d954f2d08305f89790515ebef8e32c OK ⑦ 验证是否迁移成功: 192.168.163.132:6379> cluster nodes ... 2d76972e12d954f2d08305f89790515ebef8e32c 192.168.163.132:6380@16380 master - 0 1582014517000 12 connected 1000 2000 3300 5462-10922 ... ⑧ 验证数据是否迁移: 192.168.163.132:6379> get b -> Redirected to slot [3300] located at 192.168.163.132:6380 "bbbb" |
所有评论(0)