Redis集群搭建与简单使用

参考链接:
(1)Redis集群搭建与简单使用:
http://www.cnblogs.com/wuxl360/p/5920330.html
(2)redis requires Ruby version >= 2.2.2问题
https://www.cnblogs.com/carryping/p/7447823.html
(3)redis4.0.2集群配置(安装rvm报错
http://blog.csdn.net/gw85047034/article/details/78689885
(4)精】搭建redis cluster集群,JedisCluster带密码访问【解决当中各种坑】!
http://blog.csdn.net/localhost01/article/details/71436801

集群注意事项:
(1)为保证远程可访问,这里的ip尽量使用公网ip,且创建集群时可先关闭防火墙,否则可以出现一直join……的现象。
(2)redis集群至少需要3个主节点,每个主节点有一个从节点总共6个节点
(3)replicas指定为1表示每个主节点有一个从节点
(4)如果出现[ERR] Sorry, can’t connect to node错误:
1.ruby 和rubygem 版本太低(版本不匹配),安装新版本。查看gem版本和redis版本(redis-cli -v可查看redis版本),redis-4.0.1和ruby 2.3.4p301版本匹配
2.查看reids配置文件,bind绑定的允许连接的ip是否正确。
3.是否redis配置文件还是使用了密码,使用了密码也可能导致这个错误。
(5)如果出现[ERR] Node 127.0.0.1:7005 is not empty. Either the node already knows other nodes (check with CLUSTER NODES)
or contains some key in database 0:
表示集群时,之前的redis已有数据,那么登录到7005的redis中,执行FLUSHALL即可
(6)如果出现ERR Slot 0 is already busy (Redis::CommandError):
用redis-cli登录到每个节点执行flushall和cluster reset即可2.6进入集群:./redis-cli -c -p 7001 -h 123.123.123.123(-c即-cluster 表示进入集群模式,不加表示进入单机redis)
(7)检查集群是否成功:进入集群后(连接集群中的任意一个redis),命令行键入cluster info,显示cluster_state:ok,表示成功

(8)jedis 2.9.0之后的版本才实现了集群密码验证,如下:

<dependency>  
    <groupId>redis.clients</groupId>  
    <artifactId>jedis</artifactId>  
    <version>2.9.0</version>  //2.9.0才支持cluster密码认证,之前版本的jedisCluster.auth("密码")方法里面什么都没有实现,仅仅抛一个JedisClusterException("No way to dispatch this command to Redis Cluster.")  
</dependency> 

(9)命令行执行集群命令后的成功信息:

[root@localhost kencery]# redis_cluster/redis-trib.rb  create  --replicas  1 192.168.2.111:7001 192.168.2.111:7002 192.168.2.111:7003 192.168.2.111:7004 192.168.2.111:7005 192.168.2.111:7006

>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.2.111:7001
192.168.2.111:7002
192.168.2.111:7003
Adding replica 192.168.2.111:7004 to 192.168.2.111:7001
Adding replica 192.168.2.111:7005 to 192.168.2.111:7002
Adding replica 192.168.2.111:7006 to 192.168.2.111:7003
M: 78888a354ca518b027ef7bf992967add04252c83 192.168.2.111:7001
   slots:0-5460 (5461 slots) master
M: 88ac4ec275390fc736b122850f7ec5721fcdbbb9 192.168.2.111:7002
   slots:5461-10922 (5462 slots) master
M: aaca3e458698aee68bc952e7e21aea2e13fcab0e 192.168.2.111:7003
   slots:10923-16383 (5461 slots) master
S: a1e3adde879baba6e20b6ac8705dfc6ad437aee6 192.168.2.111:7004
   replicates 78888a354ca518b027ef7bf992967add04252c83
S: c38032ee6c2cd28b5ef1384b77e469d6df050dfa 192.168.2.111:7005
   replicates 88ac4ec275390fc736b122850f7ec5721fcdbbb9
S: 54d1eb2e6f8615a407ceec112a841b4c42a8440e 192.168.2.111:7006
   replicates aaca3e458698aee68bc952e7e21aea2e13fcab0e
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.2.111:7001)
M: 78888a354ca518b027ef7bf992967add04252c83 192.168.2.111:7001
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: aaca3e458698aee68bc952e7e21aea2e13fcab0e 192.168.2.111:7003
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: 54d1eb2e6f8615a407ceec112a841b4c42a8440e 192.168.2.111:7006
   slots: (0 slots) slave
   replicates aaca3e458698aee68bc952e7e21aea2e13fcab0e
S: c38032ee6c2cd28b5ef1384b77e469d6df050dfa 192.168.2.111:7005
   slots: (0 slots) slave
   replicates 88ac4ec275390fc736b122850f7ec5721fcdbbb9
M: 88ac4ec275390fc736b122850f7ec5721fcdbbb9 192.168.2.111:7002
   slots:5461-10922 (5462 slots) master
   1 additional replica(s)
S: a1e3adde879baba6e20b6ac8705dfc6ad437aee6 192.168.2.111:7004
   slots: (0 slots) slave
   replicates 78888a354ca518b027ef7bf992967add04252c83
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值