月光代碼園

記錄、分享、交流

导航

Redis学习笔记#12 Redis Cluster 集群

Redis Cluster的模型

 Redis Cluster 以hash slot的方式分片

There are 16384 hash slots in Redis Cluster, and to compute what is the hash slot of a given key, we simply take the CRC16 of the key modulo 16384.

开始创建3主3从的redis集群 

创建配置文件redis.conf

port 7000
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-node-timeout 5000
appendonly yes

分别使用7000-7005这六个端口,注意port和cluster-config-file修改为对应端口

分别启动这六个redis服务

 

 

./redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1

带密码的集群

./redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1 -a passwd123

若需要外网访问,把127.0.0.1改为外网地址

 

集群配置成功

 

进入集群控制台

 ./redis-cli -c -p 7000

 

 重定向到7002上的slot

验证完成!

 

为集群设置密码

每个节点redis.conf增加配置并重启服务

masterauth passwd123
requirepass passwd123

 用密码访问集群

./redis-cli -c -p 7000 -a passwd

spring boot配置

spring:

redis:
cluster:
nodes: 10.14.2.18:7000,10.14.2.18:7001,10.14.2.18:7002,10.14.2.18:7003,10.14.2.18:7004,10.14.2.18:7005
password: passwd123

------------------------------------------------

参考资料:

https://www.jianshu.com/p/c869feb5581d

posted on 2020-04-28 13:35  bangdikka  阅读(128)  评论(0编辑  收藏  举报