呼唤集群
并发量 ops
数据量 大数据
数据分布
顺序分区和哈希分区
哈希分布
节点取余分区 --------建议多倍扩容比较好,数据迁移量少
一致性哈希分区 --------token环,只影响邻近节点,对其他节点影响小(节点多时候建议)
虚拟槽分区 --------前两者是客户端分片,后者是redis-cluster,服务端管理节点、槽、数据
搭建集群
Redis Cluster架构
节点 cluster-enabled yes 开启节点
meet 节点间通讯,所有节点共享信息
指派槽 16384个slot默认
复制 主从复制,高可用,分片从而实现故障自动转移
第一步:开启节点
port 7000
daemonize yes
bind 0.0.0.0
dir “/opt/moudels/redis/data”
logfile “7000.log”
dbfilename “dump-7000.rdb”
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-require-full-coverage no
第二步:meet
[root@redis01 redis]# redis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 70001
第三步:分布槽
[root@redis01 redis]# redis-cli -h 127.0.0.1 -p 7000 cluster addslots{0...5461}
[root@redis01 redis]# redis-cli -h 127.0.0.1 -p 7001 cluster addslots{5462...10992}
[root@redis01 redis]# redis-cli -h 127.0.0.1 -p 7002 cluster addslots{10992...16383}
第四步:设置主从
[root@redis01 redis]# redis-cli -h 127.0.0.1 -p 7003 cluster replicate ${node-id-7000}
[root@redis01 redis]# redis-cli -h 127.0.0.1 -p 7004 cluster replicate ${node-id-7001}
[root@redis01 redis]# redis-cli -h 127.0.0.1 -p 7005 cluster replicate ${node-id-7002}
集群伸缩
扩容集群
准备新节点
加入集群
127.0.0.1>cluster meet 127.0.0.1 6385 加入
[root@redis01 config]# redis-trib.rb add-node 127.0.0.1:8006 127.0.0.1:8000 --slave --master-id 有meet的作用
迁移槽和数据
缩容
先下从节点再下主节点
客户端路由
moved重定向
>cluster keysolt php 返回键所在的槽号
ask重定向
smart客户端
故障发现:通过ping/pong消息实现故障发现,不需要sentinal
开发运维常见问题
因而不建议使用从节点。集群模式下不建议使用读写分离