背景:

Redis Cluster 在5.0之后取消了ruby脚本 redis-trib.rb的支持(手动命令行添加集群的方式不变),集合到redis-cli里,避免了再安装ruby的相关环境。直接使用redis-clit的参数--cluster 来取代。为方便自己后面查询就说明下如何使用该命令进行Cluster的创建和管理,关于Cluster的相关说明可以查看官网或则Redis Cluster部署、管理和测试

环境:

系统版本:Ubuntu 14.04
Redis版本:5.0.
机器IP:192.168.163.132

说明:redis-cli --cluster help

redis-cli --cluster help
Cluster Manager Commands:
create host1:port1 ... hostN:portN #创建集群
--cluster-replicas <arg> #从节点个数
check host:port #检查集群
--cluster-search-multiple-owners #检查是否有槽同时被分配给了多个节点
info host:port #查看集群状态
fix host:port #修复集群
--cluster-search-multiple-owners #修复槽的重复分配问题
reshard host:port #指定集群的任意一节点进行迁移slot,重新分slots
--cluster-from <arg> #需要从哪些源节点上迁移slot,可从多个源节点完成迁移,以逗号隔开,传递的是节点的node id,还可以直接传递--from all,这样源节点就是集群的所有节点,不传递该参数的话,则会在迁移过程中提示用户输入
--cluster-to <arg> #slot需要迁移的目的节点的node id,目的节点只能填写一个,不传递该参数的话,则会在迁移过程中提示用户输入
--cluster-slots <arg> #需要迁移的slot数量,不传递该参数的话,则会在迁移过程中提示用户输入。
--cluster-yes #指定迁移时的确认输入
--cluster-timeout <arg> #设置migrate命令的超时时间
--cluster-pipeline <arg> #定义cluster getkeysinslot命令一次取出的key数量,不传的话使用默认值为10
--cluster-replace #是否直接replace到目标节点
rebalance host:port #指定集群的任意一节点进行平衡集群节点slot数量 
--cluster-weight <node1=w1...nodeN=wN> #指定集群节点的权重
--cluster-use-empty-masters #设置可以让没有分配slot的主节点参与,默认不允许
--cluster-timeout <arg> #设置migrate命令的超时时间
--cluster-simulate #模拟rebalance操作,不会真正执行迁移操作
--cluster-pipeline <arg> #定义cluster getkeysinslot命令一次取出的key数量,默认值为10
--cluster-threshold <arg> #迁移的slot阈值超过threshold,执行rebalance操作
--cluster-replace #是否直接replace到目标节点
add-node new_host:new_port existing_host:existing_port #添加节点,把新节点加入到指定的集群,默认添加主节点
--cluster-slave #新节点作为从节点,默认随机一个主节点
--cluster-master-id <arg> #给新节点指定主节点
del-node host:port node_id #删除给定的一个节点,成功后关闭该节点服务
call host:port command arg arg .. arg #在集群的所有节点执行相关命令
set-timeout host:port milliseconds #设置cluster-node-timeout
import host:port #将外部redis数据导入集群
--cluster-from <arg> #将指定实例的数据导入到集群
--cluster-copy #migrate时指定copy
--cluster-replace #migrate时指定replace
help For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster.

注意:Redis Cluster最低要求是3个主节点,如果需要集群需要认证,则在最后加入 -a xx 即可。

① 创建集群主节点

redis-cli --cluster create 192.168.163.132: 192.168.163.132: 192.168.163.132:
>>> Performing hash slots allocation on  nodes...
Master[] -> Slots -
Master[] -> Slots -
Master[] -> Slots -
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
Can I set the above configuration? (type 'yes' to accept): yes #slot分配
>>> 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.163.132:)
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.

② 创建集群主从节点

/redis-cli --cluster create 192.168.163.132: 192.168.163.132: 192.168.163.132: 192.168.163.132: 192.168.163.132: 192.168.163.132: --cluster-replicas 

说明:--cluster-replicas 参数为数字,1表示每个主节点需要1个从节点。

>>> Performing hash slots allocation on  nodes...
Master[] -> Slots -
Master[] -> Slots -
Master[] -> Slots -
Adding replica 192.168.163.132: to 192.168.163.132:
Adding replica 192.168.163.132: to 192.168.163.132:
Adding replica 192.168.163.132: to 192.168.163.132:
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
S: 3a1d04983ab6c4ae853f9602dd922d4ebadc4dbf 192.168.163.132:
replicates 56005b9413cbf225783906307a2631109e753f8f
S: 0c21b6cee354594a23f4d5abf0d01b48bdc96d55 192.168.163.132:
replicates 117457eab5071954faab5e81c3170600d5192270
S: f6a6957421b80409106cb36be3c7ba41f3b603ff 192.168.163.132:
replicates 815da8448f5d5a304df0353ca10d8f9b77016b28
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.163.132:)
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
S: 3a1d04983ab6c4ae853f9602dd922d4ebadc4dbf 192.168.163.132:
slots: ( slots) slave
replicates 56005b9413cbf225783906307a2631109e753f8f
S: 0c21b6cee354594a23f4d5abf0d01b48bdc96d55 192.168.163.132:
slots: ( slots) slave
replicates 117457eab5071954faab5e81c3170600d5192270
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
S: f6a6957421b80409106cb36be3c7ba41f3b603ff 192.168.163.132:
slots: ( slots) slave
replicates 815da8448f5d5a304df0353ca10d8f9b77016b28
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.

通过该方式创建的带有从节点的机器不能够自己手动指定主节点,所以如果需要指定的话,需要自己手动指定,先使用①或③创建好主节点后,再通过④来处理。

③ 添加集群主节点

redis-cli --cluster add-node 192.168.163.132: 192.168.163.132: 

说明:为一个指定集群添加节点,需要先连到该集群的任意一个节点IP(192.168.163.132:6379),再把新节点加入。该2个参数的顺序有要求:新加入的节点放前

>>> Adding node 192.168.163.132: to cluster 192.168.163.132:
>>> Performing Cluster Check (using node 192.168.163.132:)
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Send CLUSTER MEET to node 192.168.163.132: to make it join the cluster.
[OK] New node added correctly.

④ 添加集群从节点

redis-cli --cluster add-node 192.168.163.132: 192.168.163.132: --cluster-slave --cluster-master-id 117457eab5071954faab5e81c3170600d5192270

说明:把6382节点加入到6379节点的集群中,并且当做node_id为 117457eab5071954faab5e81c3170600d5192270 的从节点。如果不指定 --cluster-master-id 会随机分配到任意一个主节点。

>>> Adding node 192.168.163.132: to cluster 192.168.163.132:
>>> Performing Cluster Check (using node 192.168.163.132:)
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Send CLUSTER MEET to node 192.168.163.132: to make it join the cluster.
Waiting for the cluster to join
..
>>> Configure node as replica of 192.168.163.132:.

⑤ 删除节点

redis-cli --cluster del-node 192.168.163.132: f6a6957421b80409106cb36be3c7ba41f3b603ff

说明:指定IP、端口和node_id 来删除一个节点,从节点可以直接删除,主节点不能直接删除,删除之后,该节点会被shutdown。

删除从节点:
redis-cli --cluster del-node 192.168.163.132: f6a6957421b80409106cb36be3c7ba41f3b603ff
>>> Removing node f6a6957421b80409106cb36be3c7ba41f3b603ff from cluster 192.168.163.132:
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node. 删除主节点:
redis-cli --cluster del-node 192.168.163.132: 815da8448f5d5a304df0353ca10d8f9b77016b28
>>> Removing node 815da8448f5d5a304df0353ca10d8f9b77016b28 from cluster 192.168.163.132:
[ERR] Node 192.168.163.132: is not empty! Reshard data away and try again.

注意:当被删除掉的节点重新起来之后不能自动加入集群,但其和主的复制还是正常的,也可以通过该节点看到集群信息(通过其他正常节点已经看不到该被del-node节点的信息)。

如果想要再次加入集群,则需要先在该节点执行cluster reset,再用add-node进行添加,进行增量同步复制。

到此,目前整个集群的状态如下:

192.168.163.132:> cluster nodes
815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:@ master - connected -
0c21b6cee354594a23f4d5abf0d01b48bdc96d55 192.168.163.132:@ slave 56005b9413cbf225783906307a2631109e753f8f connected
3a1d04983ab6c4ae853f9602dd922d4ebadc4dbf 192.168.163.132:@ slave 815da8448f5d5a304df0353ca10d8f9b77016b28 connected
117457eab5071954faab5e81c3170600d5192270 192.168.163.132:@ myself,master - connected -
56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:@ master - connected -
f6a6957421b80409106cb36be3c7ba41f3b603ff 192.168.163.132:@ slave 117457eab5071954faab5e81c3170600d5192270 connected

⑥ 检查集群

redis-cli --cluster check 192.168.163.132: --cluster-search-multiple-owners

说明:任意连接一个集群节点,进行集群状态检查

redis-cli --cluster check 192.168.163.132: --cluster-search-multiple-owners
192.168.163.132: (815da844...) -> keys | slots | slaves.
192.168.163.132: (56005b94...) -> keys | slots | slaves.
192.168.163.132: (117457ea...) -> keys | slots | slaves.
[OK] keys in masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.163.132:)
S: f6a6957421b80409106cb36be3c7ba41f3b603ff 192.168.163.132:
slots: ( slots) slave
replicates 117457eab5071954faab5e81c3170600d5192270
S: 0c21b6cee354594a23f4d5abf0d01b48bdc96d55 192.168.163.132:
slots: ( slots) slave
replicates 56005b9413cbf225783906307a2631109e753f8f
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
S: 3a1d04983ab6c4ae853f9602dd922d4ebadc4dbf 192.168.163.132:
slots: ( slots) slave
replicates 815da8448f5d5a304df0353ca10d8f9b77016b28
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Check for multiple slot owners...

⑦ 集群信息查看

redis-cli --cluster info 192.168.163.132:

说明:检查key、slots、从节点个数的分配情况

/redis-cli --cluster info 192.168.163.132:
192.168.163.132: (815da844...) -> keys | slots | slaves.
192.168.163.132: (56005b94...) -> keys | slots | slaves.
192.168.163.132: (117457ea...) -> keys | slots | slaves.
[OK] keys in masters.
0.00 keys per slot on average.

⑧ 修复集群

redis-cli --cluster fix 192.168.163.132: --cluster-search-multiple-owners

说明:修复集群和槽的重复分配问题

redis-cli --cluster fix 192.168.163.132: --cluster-search-multiple-owners
192.168.163.132: (815da844...) -> keys | slots | slaves.
192.168.163.132: (56005b94...) -> keys | slots | slaves.
192.168.163.132: (117457ea...) -> keys | slots | slaves.
[OK] keys in masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.163.132:)
S: f6a6957421b80409106cb36be3c7ba41f3b603ff 192.168.163.132:
slots: ( slots) slave
replicates 117457eab5071954faab5e81c3170600d5192270
S: 0c21b6cee354594a23f4d5abf0d01b48bdc96d55 192.168.163.132:
slots: ( slots) slave
replicates 56005b9413cbf225783906307a2631109e753f8f
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
S: 3a1d04983ab6c4ae853f9602dd922d4ebadc4dbf 192.168.163.132:
slots: ( slots) slave
replicates 815da8448f5d5a304df0353ca10d8f9b77016b28
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Check for multiple slot owners...

⑨ 设置集群的超时时间

redis-cli --cluster set-timeout 192.168.163.132: 

说明:连接到集群的任意一节点来设置集群的超时时间参数cluster-node-timeout

redis-cli --cluster set-timeout 192.168.163.132:
>>> Reconfiguring node timeout in every cluster node...
*** New timeout set for 192.168.163.132:
*** New timeout set for 192.168.163.132:
*** New timeout set for 192.168.163.132:
*** New timeout set for 192.168.163.132:
*** New timeout set for 192.168.163.132:
*** New timeout set for 192.168.163.132:
>>> New node timeout set. OK, ERR.

⑩ 集群中执行相关命令

redis-cli --cluster call 192.168.163.132: config set requirepass cc
redis-cli -a cc --cluster call 192.168.163.132: config set masterauth cc
redis-cli -a cc --cluster call 192.168.163.132: config rewrite

说明:连接到集群的任意一节点来对整个集群的所有节点进行设置。

redis-cli --cluster call 192.168.163.132: config set cluster-node-timeout
>>> Calling config set cluster-node-timeout
192.168.163.132:: OK
192.168.163.132:: OK
192.168.163.132:: OK
192.168.163.132:: OK
192.168.163.132:: OK
192.168.163.132:: OK
...
...

到此,相关集群的基本操作已经介绍完,现在说明集群迁移的相关操作。

迁移相关

① 在线迁移slot :在线把集群的一些slot从集群原来slot节点迁移到新的节点,即可以完成集群的在线横向扩容和缩容。有2种方式进行迁移

一是根据提示来进行操作:

直接连接到集群的任意一节点
redis-cli -a cc --cluster reshard 192.168.163.132:

信息如下:

redis-cli -a cc --cluster reshard 192.168.163.132:
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.163.132:)
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
S: 0c21b6cee354594a23f4d5abf0d01b48bdc96d55 192.168.163.132:
slots: ( slots) slave
replicates 56005b9413cbf225783906307a2631109e753f8f
S: 3a1d04983ab6c4ae853f9602dd922d4ebadc4dbf 192.168.163.132:
slots: ( slots) slave
replicates 815da8448f5d5a304df0353ca10d8f9b77016b28
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
S: f6a6957421b80409106cb36be3c7ba41f3b603ff 192.168.163.132:
slots: ( slots) slave
replicates 117457eab5071954faab5e81c3170600d5192270
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
How many slots do you want to move (from to )?
What is the receiving node ID? 815da8448f5d5a304df0353ca10d8f9b77016b28
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 #: 117457eab5071954faab5e81c3170600d5192270
Source node #: done Ready to move slots.
Source nodes:
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
Destination node:
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
Resharding plan:
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot from 192.168.163.132: to 192.168.163.132::

二是根据参数进行操作:

redis-cli -a cc --cluster reshard 192.168.163.132: --cluster-from 117457eab5071954faab5e81c3170600d5192270 --cluster-to 815da8448f5d5a304df0353ca10d8f9b77016b28 --cluster-slots  --cluster-yes --cluster-timeout  --cluster-pipeline  --cluster-replace

说明:连接到集群的任意一节点来对指定节点指定数量的slot进行迁移到指定的节点。

>>> Performing Cluster Check (using node 192.168.163.132:)
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-],[-] ( slots) master
additional replica(s)
S: 0c21b6cee354594a23f4d5abf0d01b48bdc96d55 192.168.163.132:
slots: ( slots) slave
replicates 56005b9413cbf225783906307a2631109e753f8f
S: 3a1d04983ab6c4ae853f9602dd922d4ebadc4dbf 192.168.163.132:
slots: ( slots) slave
replicates 815da8448f5d5a304df0353ca10d8f9b77016b28
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
S: f6a6957421b80409106cb36be3c7ba41f3b603ff 192.168.163.132:
slots: ( slots) slave
replicates 117457eab5071954faab5e81c3170600d5192270
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered. Ready to move slots.
Source nodes:
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-] ( slots) master
additional replica(s)
Destination node:
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[-],[-] ( slots) master
additional replica(s)
Resharding plan:
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 117457eab5071954faab5e81c3170600d5192270
Moving slot from 192.168.163.132: to 192.168.163.132::
Moving slot from 192.168.163.132: to 192.168.163.132::
Moving slot from 192.168.163.132: to 192.168.163.132::
Moving slot from 192.168.163.132: to 192.168.163.132::
Moving slot from 192.168.163.132: to 192.168.163.132::
Moving slot from 192.168.163.132: to 192.168.163.132::
Moving slot from 192.168.163.132: to 192.168.163.132::
Moving slot from 192.168.163.132: to 192.168.163.132::
Moving slot from 192.168.163.132: to 192.168.163.132::
Moving slot from 192.168.163.132: to 192.168.163.132::

② 平衡(rebalance)slot 

1)平衡集群中各个节点的slot数量

redis-cli -a cc --cluster rebalance 192.168.163.132:
>>> Performing Cluster Check (using node 192.168.163.132:)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Rebalancing across nodes. Total weight = 3.00
Moving slots from 192.168.163.132: to 192.168.163.132:
##########################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
Moving slots from 192.168.163.132: to 192.168.163.132:
####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################

2)根据集群中各个节点设置的权重等平衡slot数量(不执行,只模拟)

redis-cli -a cc --cluster rebalance --cluster-weight 117457eab5071954faab5e81c3170600d5192270= 815da8448f5d5a304df0353ca10d8f9b77016b28= 56005b9413cbf225783906307a2631109e753f8f= --cluster-simulate 192.168.163.132:

③ 导入集群

redis-cli --cluster import 192.168.163.132: --cluster-from 192.168.163.132: --cluster-replace

说明:外部Redis实例(9021)导入到集群中的任意一节点。

>>> Importing data from 192.168.163.132: to cluster 192.168.163.132:
>>> Performing Cluster Check (using node 192.168.163.132:)
M: 117457eab5071954faab5e81c3170600d5192270 192.168.163.132:
slots:[-],[-] ( slots) master
additional replica(s)
M: 815da8448f5d5a304df0353ca10d8f9b77016b28 192.168.163.132:
slots:[],[-] ( slots) master
additional replica(s)
S: 0c21b6cee354594a23f4d5abf0d01b48bdc96d55 192.168.163.132:
slots: ( slots) slave
replicates 56005b9413cbf225783906307a2631109e753f8f
S: 3a1d04983ab6c4ae853f9602dd922d4ebadc4dbf 192.168.163.132:
slots: ( slots) slave
replicates 815da8448f5d5a304df0353ca10d8f9b77016b28
M: 56005b9413cbf225783906307a2631109e753f8f 192.168.163.132:
slots:[-],[-] ( slots) master
additional replica(s)
S: f6a6957421b80409106cb36be3c7ba41f3b603ff 192.168.163.132:
slots: ( slots) slave
replicates 117457eab5071954faab5e81c3170600d5192270
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
*** Importing keys from DB
Migrating to 192.168.163.132:: OK
Migrating to 192.168.163.132:: OK
...
...

注意:测试下来发现参数--cluster-replace没有用,如果集群中已经包含了某个key,在导入的时候会失败,不会覆盖,只有清空集群key才能导入。

*** Importing  keys from DB
Migrating to 192.168.163.132:: Source 192.168.163.132: replied with error:
ERR Target instance replied with error: BUSYKEY Target key name already exists

并且发现如果集群设置了密码,也会导入失败,需要设置集群密码为空才能进行导入(call)。通过monitor(9021)的时候发现,在migrate的时候需要密码进行auth认证。

总结:

Redis Cluster 通过redis-cli --cluster来创建和管理集群的方式和 redis-trib.rb脚本绝大部分都是一样的,所以对于比较熟悉 redis-trib.rb 脚本的,使用--cluster也非常顺手。

Redis 5.0 redis-cli --cluster help说明的更多相关文章

  1. redis 5.0 CLUSTERDOWN The cluster is down

    安装 redis 集群,设置值报错,错误信息:redis 5.0  CLUSTERDOWN The cluster is down. 这个是由于安装错误导致的,需要重新进行 修复一下. 命令如下: [ ...

  2. springboot2.1.3 + redisTemplate + Lock 操作 redis 3.0.5

    近期在整合springboot + redis 的功能,本来想用原生的jedit api,最后想想有点 low,搜了一把,boot已经提供给我们操作的方法,那就是 使用 redisTemplate 或 ...

  3. springBoot2.0+redis+fastJson+自定义注解实现方法上添加过期时间

    springBoot2.0集成redis实例 一.首先引入项目依赖的maven jar包,主要包括 spring-boot-starter-data-redis包,这个再springBoot2.0之前 ...

  4. Redis 4.0+安装及配置

    系统环境:CentOS 7.3 官方下载最新版:https://redis.io/download:或直接终端下载解析安装: $ wget http://download.redis.io/relea ...

  5. docker安装redis 5.0.7并挂载外部配置和数据

    环境 CentOS Linux release 7.7.1908 (Core) 拉取redis 5.0.7 镜像 docker pull redis:5.0.7 创建挂载目录 mkdir -p /ho ...

  6. Redis 3.0 Cluster集群配置

    Redis 3.0 Cluster集群配置 安装环境依赖 安装gcc:yum install gcc 安装zlib:yum install zib 安装ruby:yum install ruby 安装 ...

  7. spring boot:使用redis cluster集群作为分布式session(redis 6.0.5/spring boot 2.3.1)

    一,为什么要使用分布式session? HpptSession默认使用内存来管理Session,如果将应用横向扩展将会出现Session共享问题, 所以我们在创建web集群时,把session保存到r ...

  8. Redis 3.0.5 集群的命令、使用、维护

    cluster命令 CLUSTER INFO 打印集群的信息 CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息. //节点 CLUSTER MEET < ...

  9. Redis 5.0.0 releases notes

    Redis 5.0 release notes ======================= ---------------------------------------------------- ...

  10. 【转载】Redis 4.0 自动内存碎片整理(Active Defrag)源码分析

    click原文链接原文链接:https://blog.csdn.net/zouhuajianclever/article/details/90669409阅读本文前建议先阅读此篇博客: Redis源码 ...

随机推荐

  1. 学测试,看视频?NONONO,除非这种情况

    001 前言 : 很久没周末写文章了,一个是要睡懒觉.另外一个是,周末写了大家也没有心思看(加班1周了,好不容易周末,你又让我学习 ?先睡个懒觉再说,去TM的学习). 然而,今天早早的5点就起床了,处 ...

  2. Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days)

    Leetcode之二分法专题-1011. 在 D 天内送达包裹的能力(Capacity To Ship Packages Within D Days) 传送带上的包裹必须在 D 天内从一个港口运送到另 ...

  3. 解决 java Could not resolve resource location pattern [classpath:sql/*.xml] 的问题

    时间过的真快,转眼间已经有2年了.2年里发生了太多的事,有些事依稀还记得,但更多的已经忘记.忘记了那些烦恼与忧愁,以为自己会快乐,才发现一切并不是以自己的意志为转移.终于在迷途中迷失了自己, 再也回不 ...

  4. iOS仿写下厨房

    把之前简书的博客搬到博客园了,还是放在一个地方看着舒服. 先看一下做的效果,是不是还不错?(可以看一下早餐那块的轮播,上面盖着一个都是点点的图片,但是它不是和轮播一起滚动的,是盖在轮播上面的,需要在那 ...

  5. 2019-07-26-hexo博客图片问题

    本人的解决方案 *** 将hexo的主页配置文件中的_config.yml里的post_asset_folder设置为true. 在git bash里运行npm install hexo-asset- ...

  6. Oil Deposits UVA - 572

    The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSu ...

  7. 面向对象程序设计(Java) 第1周学习指导及要求

    面向对象程序设计(Java)第1周学习指导及要求 (2019.8.30-2019.9.2)   学习目标 了解课程上课方式及老师教学要求,掌握课程学习必要的软件工具: 理解JVM.JRE与JDK等概念 ...

  8. Java 添加Word文本框

    在Word中,文本框是指一种可移动.可调节大小的文字或图形容器.我们可以向文本框中添加文字.图片.表格等对象,下面,将通过Java编程来实现添加以上对象到Word文本框. 使用工具:Free Spir ...

  9. 使用Spring Boot和RxJava的构建响应式REST API

    我不打算解释什么是响应式编程,也不解释为什么要使用它.我希望你已经在其他地方了解过,如果没有,你可以使用Google去搜索它.在本文中,我将告诉您如何使用专门针对Spring Boot和RxJava的 ...

  10. java 中for循环中断的办法

    /* 中断for循环的办法: 1.break ***2.return是结束方法的,不是结束循环的. 3.标签的方法. 格式: 表签名:语句 运行结果:D:\test\day0413>java T ...