9.Redis 3.0.0 Cluster Redis集群的其他操作

安装部分参考 http://sgq0085.iteye.com/blog/2198597

一.对集群进行重新分片 redis-trib.rb reshard

对集群中共有的16384 slot(哈希槽)重新分片,是Redis集群维护的基础,添加和删除节点都涉及到该部分内容;

1.查看节点状态,slot(哈希槽)状态和节点ID并记录下节点ID

./redis-trib.rb check 127.0.0.1:6379

2.发起重新分配 slot(哈希槽)请求

# 可以指定任意一个节点(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

二.添加Master节点 redis-trib.rb add-node

1.第一步添加一个空节点

参考http://sgq0085.iteye.com/blog/2198597

(1)启用新的端口添加配置文件

cp redis.conf /etc/redis/6383.conf

(2)根据端口号创建本地数据库存放路径

mkdir /var/redis/6383

(3)启动节点

redis-server /etc/redis/6383.conf 

2.加入空节点到集群

add-node  将一个节点添加到集群里面, 第一个是新节点ip:port, 第二个是任意一个已存在节点ip:port

./redis-trib.rb add-node 127.0.0.1:6383 127.0.0.1:6380

3.给新节点分配slot(哈希槽)

How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID? 04e7c3cbea818d16bbc76080234ef6a2205f4199
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

(6)检查节点状态

./redis-trib.rb check 127.0.0.1:6383

三.添加slave节点 cluster replicate

1.添加并启动一个新节点

2.加入空节点到集群

./redis-trib.rb add-node 127.0.0.1:7383 127.0.0.1:6383
./redis-trib.rb check 127.0.0.1:7383
 

3.将该节点设置为其它Master节点的slave从节点

(1)连接该节点

redis-cli -h 127.0.0.1 -p 7383
 

(2)设置master

cluster replicate 对应master的node-id

cluster replicate 04e7c3cbea818d16bbc76080234ef6a2205f4199
 在线添加slave 时,需要dump整个master进程,并传递到slave,再由 slave加载rdb文件到内存,rdb传输过程中Master可能无法提供服务,整个过程消耗大量io,小心操作.

四.删除一个Slave节点 redis-trib.rb del-node

#redis-trib del-node ip:port '<node-id>'  
./redis-trib.rb del-node 127.0.0.1:7383 '7e5ee6d373563d97825a69caee95e6f0e4ed591d' 
 

五.删除一个Master节点

1.将要删除的节点通过 redis-trib.rb reshard ,将slot(哈希槽)全部分配给其它节点

./redis-trib.rb reshard 127.0.0.1:6383
./redis-trib.rb check 127.0.0.1:6380

2.删除空节点

./redis-trib.rb del-node 127.0.0.1:6383 '04e7c3cbea818d16bbc76080234ef6a2205f4199'
 

猜你喜欢

转载自sgq0085.iteye.com/blog/2199277