Redis-Cluster实战--7.Redis-Cluster水平扩容(ruby实现版)

 

转载请注明出处哈:http://carlosfu.iteye.com/blog/2240426


   

一、目的

Redis-Cluster是Redis的分布式解决方案,Redis Cluster提供了在线扩容(添加分片)功能,有效扩展存储能力和读写能力。

 

水平扩容思路如下:

1. 启动新的Redis实例。

2. 集群中的机器meet上述Redis实例,将其加入集群。

3. 由于新的实例没有指派槽,所以要将部分其他实例上面的槽迁移至新的实例。

 

 

二、具体实现:(已建立好的集群参考http://carlosfu.iteye.com/blog/2242578

 

1.  启动新的Redis实例,端口是8007

sed 's/8000/8007/g' redis-8000.conf > redis-8007.conf
redis-server /opt/soft/redis/conf/redis-8007.conf

  

2.  将8007加入集群

redis-cli -c -p 8000 cluster meet 127.0.0.1 8007

    上述两步,已经在之前文档里面详细介绍过了,这里就不在赘述了。

 

 

3. 重新分片:(redis作者提供了redis-trib.rb工具支持在线扩容功能)

redis-trib.rb reshard 127.0.0.1:8007
#根据提示选择要迁移的slot(ps:这里选择500)
How many slots do you want to move (from 1 to 16384)? 500
#选择要接受这些slot的node-id
What is the receiving node ID? f51e26b5d5ff74f85341f06f28f125b7254e61bf
#选择slot来源:
#all表示从所有的master重新分配,
#或者数据要提取slot的master节点id,最后用done结束
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
#打印被移动的slot后,输入yes开始移动slot以及对应的数据.
#Do you want to proceed with the proposed reshard plan (yes/no)? yes
#结束

 

 

集群状态:

127.0.0.1:8000> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:8
cluster_size:5
cluster_current_epoch:7
cluster_my_epoch:1
cluster_stats_messages_sent:193766
cluster_stats_messages_received:193765 

 

猜你喜欢

转载自carlosfu.iteye.com/blog/2243051
今日推荐