redis cluster创建

redis cluster集群的创建可以用redis-trib.rb工具快速完成。这里主要是手动搭建一个集群的过程,简单介绍一下集群构建原理。

1 配置redis节点
redis cluster集群至由3个redis节点构成。在redis配置文件中开启cluster模式和相关参数,就可以启动一个空的集群节点。

cluster-enabled yes
cluster-config-file nodes-6379.conf  #不需写入要任何内容
cluster-node-timeout 15000           # 单位微妙

2 启动集群
启动一个redis cluster集群的两种方法:
1)通过redis作者Antirez提供的脚本创建redis cluster。
启动redis master/slave节点,通过脚本创建脚本或者扩容节点。

./redis-trib.rb create --replicas 1

原理:cluster meet
setting progressive configuration epoch for every nodes(这一步可以忽略)

redis-cli  -c  -p 6379  cluster set-config-epoch  1
redis-cli  -c  -p 6380  cluster set-config-epoch  2
redis-cli  -c  -p 6381  cluster set-config-epoch  3
redis-cli  -c  -p 6382  cluster set-config-epoch  4
However there is an exception to this rule, and it is when a new cluster is created from scratch. Redis Cluster config epoch collision resolution algorithm can deal with new nodes all configured with the same configuration at startup, but this process is slow and should be the exception, only to make sure that whatever happens, two more more nodes eventually always move away from the state of having the same configuration epoch.
So, using CONFIG SET-CONFIG-EPOCH, when a new cluster is created, we can assign a different progressive configuration epoch to each node before joining the cluster together.

meeting of nodes

redis-cli  -c  -p 6380  cluster meet 6379
redis-cli  -c  -p 6381  cluster meet 6379
redis-cli  -c  -p 6382  cluster meet 6379

3 assign slots to nodes
把分配16384个slots分配到redis节点上.add slots, must allocate all 16384 slots to all nodes.

for n in `seq 0     4095   `; do redis-cli -p  6379  cluster addslots $n;done
for n in `seq 4096  8191   `; do redis-cli -p  6380  cluster addslots $n;done
for n in `seq 8192  12287  `; do redis-cli -p  6381  cluster addslots $n;done
for n in `seq 12288 16383  `; do redis-cli -p  6382  cluster addslots $n;done




电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>