Redis集群模式

8月 1, 2018 |

集群模式启动redis-server
redis-server --port 7000 --cluster-enabled yes --cluster-config-file /etc/customized_conf/nodes_7000.conf \
--cluster-node-timeout 5000 --appendonly yes --protected-mode yes --bind 192.168.14.164
--安装执行redis-trib.rb的ruby包
yum install gem; gem install redis;[如果提示ruby版本低,源码安装ruby,同时yum install zlib-devel , yum install openssl-devel , 然后进入ruby的ext/zlib 执行"ruby ./extconf.rb;make; make install" 再进入ext/openssl 执行"ruby ./extconf.rb;make; make install" , 最后gem install redis]

创建集群‘--replicas 1’表示副本数为1
redis-trib.rb create --replicas 1 192.168.14.160:7000 192.168.14.160:8000 \
192.168.14.161:7000 192.168.14.161:8000 192.168.14.164:7000 192.168.14.164:8000

重新分片
redis-trib.rb reshard 192.168.14.160:7000
redis-trib.rb reshard --from old_master_node_id --to new_master_node_id --slots 1000 --yes 192.168.14.160:7000

手动触发段错误
redis-cli -p 7002 debug segfault

手动触发failover
redis-cli -p 7002 CLUSTER FAILOVER --从服务器上执行

向集群添加新的空主节点
redis-trib.rb add-node ip:port(to_add) ip:port(in cluster)
添加一个从节点
redis-trib.rb add-node --slave --master-id master_node_id ip:port(to_add) ip:port(in cluster)
将node_id所表示的节点从集群剔除
redis-trib.rb del-node 192.168.14.160:8000 node_id

Posted in: redis

Comments are closed.