redis普通集群配置

使用集群,只需要将每个数据库节点的cluster-enable配置打开即可。每个集群中至少需要三个主数据库才能正常运行

集群配置

安装依赖环境ruby,注意ruby版本必须高于2.2

yum install ruby
yum install rubygems
gem install redis

修改配置文件:

  bind 192.168.0.107

配置端口:

port 6380

配置快照保存路径

dir /usr/local/redis-cluster/6380/

开启集群:

cluster-enabled yes

为节点设置不同的工作目录:

luster-config-file nodes-6380.conf
集群失效时间

cluster-node-timeout 15000

开启集群中的节点:

reids-service …/6380/redis.conf

将节点加入集群中

redis-trib.rb create --replicas 1 192.168.0.107:6380 192.168.0.107:6381 192.168.0.107:6382 192.168.0.107:6383 192.168.0.107:6384 192.168.0.107:6385

中途需要输入yes确定创建集群:

[root@buke107 src]# redis-trib.rb create --replicas 1 192.168.0.107:6380 192.168.0.107:6381 192.168.0.107:6382 192.168.0.107:6383 192.168.0.107:6384 192.168.0.107:6385 >>> Creating cluster Connecting to node 192.168.0.107:6380: OK Connecting to node 192.168.0.107:6381: OK Connecting to node 192.168.0.107:6382: OK Connecting to node 192.168.0.107:6383: OK Connecting to node 192.168.0.107:6384: OK Connecting to node 192.168.0.107:6385: OK >>> Performing hash slots allocation on 6 nodes… Using 3 masters: 192.168.0.107:6380 192.168.0.107:6381 192.168.0.107:6382 Adding replica 192.168.0.107:6383 to 192.168.0.107:6380 Adding replica 192.168.0.107:6384 to 192.168.0.107:6381 Adding replica 192.168.0.107:6385 to 192.168.0.107:6382 M: 5cd3ed3a84ead41a765abd3781b98950d452c958 192.168.0.107:6380 slots:0-5460 (5461 slots) master M: 90b4b326d579f9b5e181e3df95578bceba29b204 192.168.0.107:6381 slots:5461-10922 (5462 slots) master M: 868456121fa4e6c8e7abe235a88b51d354a944b5 192.168.0.107:6382 slots:10923-16383 (5461 slots) master S: b8e047aeacb9398c3f58f96d0602efbbea2078e2 192.168.0.107:6383 replicates 5cd3ed3a84ead41a765abd3781b98950d452c958 S: 68cf66359318b26df16ebf95ba0c00d9f6b2c63e 192.168.0.107:6384 replicates 90b4b326d579f9b5e181e3df95578bceba29b204 S: d6d01fd8f1e5b9f8fc0c748e08248a358da3638d 192.168.0.107:6385 replicates 868456121fa4e6c8e7abe235a88b51d354a944b5 Can I set the above configuration? (type ‘yes’ to accept): yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join… >>> Performing Cluster Check (using node 192.168.0.107:6380) M: 5cd3ed3a84ead41a765abd3781b98950d452c958 192.168.0.107:6380 slots:0-5460 (5461 slots) master M: 90b4b326d579f9b5e181e3df95578bceba29b204 192.168.0.107:6381 slots:5461-10922 (5462 slots) master M: 868456121fa4e6c8e7abe235a88b51d354a944b5 192.168.0.107:6382 slots:10923-16383 (5461 slots) master M: b8e047aeacb9398c3f58f96d0602efbbea2078e2 192.168.0.107:6383 slots: (0 slots) master replicates 5cd3ed3a84ead41a765abd3781b98950d452c958 M: 68cf66359318b26df16ebf95ba0c00d9f6b2c63e 192.168.0.107:6384 slots: (0 slots) master replicates 90b4b326d579f9b5e181e3df95578bceba29b204 M: d6d01fd8f1e5b9f8fc0c748e08248a358da3638d 192.168.0.107:6385 slots: (0 slots) master replicates 868456121fa4e6c8e7abe235a88b51d354a944b5 [OK] All nodes agree about slots configuration. >>> Check for open slots… >>> Check slots coverage… [OK] All 16384 slots covered.

进入任何一个集群中的节点:

redis-cli -c -h 192.168.0.107 -p 6381

查看集群中的节点:

[root@buke107 src]# redis-cli -c -h 192.168.0.107 -p 6381
192.168.0.107:6381> cluster nodes 868456121fa4e6c8e7abe235a88b51d354a944b5 192.168.0.107:6382 master - 0
1523609792598 3 connected 10923-16383
d6d01fd8f1e5b9f8fc0c748e08248a358da3638d 192.168.0.107:6385 slave
868456121fa4e6c8e7abe235a88b51d354a944b5 0 1523609795616 6 connected
5cd3ed3a84ead41a765abd3781b98950d452c958 192.168.0.107:6380 master - 0
1523609794610 1 connected 0-5460
b8e047aeacb9398c3f58f96d0602efbbea2078e2 192.168.0.107:6383 slave
5cd3ed3a84ead41a765abd3781b98950d452c958 0 1523609797629 1 connected
68cf66359318b26df16ebf95ba0c00d9f6b2c63e 192.168.0.107:6384 slave
90b4b326d579f9b5e181e3df95578bceba29b204 0 1523609796622 5 connected
90b4b326d579f9b5e181e3df95578bceba29b204 192.168.0.107:6381
myself,master - 0 0 2 connected 5461-10922

如上图所示,已经建立起三主三从的集群。

增加集群节点

cluster meet ip port
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值