redis问题

1. 设置集群时

  ./redis-trib.rb create --replicas n 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:8000 127.0.0.1:8001  

  --replicas n  代表一个主对应几个从    前面设置主节点,后面设置从节点

2. 集群模式启动

  redis-cli -c -h host -p port    -c代表打开集群模式

  cluster nodes

  cluster info

3. 集群的slot槽  2^14

  ./redis-trib.rb实现了把槽平分给每个主节点

  ./redis-trib.rb add-node 127.0.0.1:7007  127.0.0.1:7001  //添加主节点  7007为添加的节点  7001为存在的节点

  ./redis-trib.rb add-node --slave --master-id 主节点id 需要添加的从节点 已经存在的节点    //添加从节点

  ./redis-trib.rb del-node 节点 id  //删除节点,需要删除槽点

  ./redis-trib.rb reshard 节点  //分配槽点

  添加节点时需要删除 node.conf rdm aof 然后重启该redis服务

# 可以指定任意一个节点(M/S均可)  
./redis-trib.rb reshard 127.0.0.1:7382  
# 指定移动多少个 slot(哈希槽)  
How many slots do you want to move (from 1 to 16384)? 250  
# 指定接收的节点  
What is the receiving node ID? 0e910bc1ae0c16d1f6e754b2759cbb23897a0c6e  
# 指定取 slot(哈希槽)的节点   
# 第一种ALL,除接收节点外,其他节点平均分配取slot  
# 第二种 指定节点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:538274656289381c0e488e95aaf6cd30731457eb  
Source node #2:done  

  

4. 集群主节点是单数

  过半崩溃(需要保证一半以上可以用)  

  4 --> 一半为2  最少需3个可用节点  1台可崩溃  

  3 --> 一半为1.5 最少需2个可用节点  1台可崩溃

  5 --> 一半为2.5 最少需3个可用节点  2台可崩溃

  

猜你喜欢

转载自www.cnblogs.com/cyx-garen/p/9051476.html
今日推荐