欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Redis集群搭建与简单使用

程序员文章站 2022-07-05 21:54:50
...

参考链接:
(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)命令行执行集群命令后的成功信息:

[[email protected] 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.
相关标签: redis