图片来源尚硅谷,仅供学习交流
继主从复制,若主机down则,需要一个哨兵来选举出新的master
类似于ensp中 DR,BDR 的选举
首先先创建sentinel.conf
sentinel monitor mymaster 127.0.0.1 6380 1
在新的服务器上启动哨兵
redis-sentinel sentinel.conf
首先修改配置文件
“redis6379.conf” 7L, 181C
include /myredis/redis.conf
pidfile "/var/run/redis_6379.pid"
port 6379
dbfilename "dump6379.rdb"
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000
开启 79 80 81 89 90 81 六个端口组成集群
将集群中合体
不能加127.0.0.1 只能加实际ip
[root@bogon src]# redis-cli --cluster create --cluster-replicas 1
192.168.33.131:6379 192.168.33.131:6380 192.168.33.131:6381
192.168.33.131:6389 192.168.33.131:6390 192.168.33.131:6391
注:此时不能运行哨兵模式,否则会开启失败
主从会自动选好
M: 9a5cad91efb3ba3b303c3652db9126a1ddb20b8e 192.168.33.131:6379
slots:[0-5460] (5461 slots) master
M: 8e681df773ce955600638cc2cbd1286c742f8ecd 192.168.33.131:6380
slots:[5461-10922] (5462 slots) master
M: 0f5b705aed8be7cabd48ceb494736ce348b97229 192.168.33.131:6381
slots:[10923-16383] (5461 slots) master
S: 560ed84d23690453e8904013a439524a48bf59df 192.168.33.131:6389
replicates 9a5cad91efb3ba3b303c3652db9126a1ddb20b8e
S: d7483bbede65ab6659b97e8a745fc32a63628809 192.168.33.131:6390
replicates 8e681df773ce955600638cc2cbd1286c742f8ecd
S: 86e92cd429e77fff4c6c5bf2b113012510f2faac 192.168.33.131:6391
replicates 0f5b705aed8be7cabd48ceb494736ce348b97229
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.33.131:6390 to 192.168.33.131:6379
Adding replica 192.168.33.131:6391 to 192.168.33.131:6380
Adding replica 192.168.33.131:6389 to 192.168.33.131:6381
合体成功
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered
随机进入6379 80 71 都可
查看node节点情况
127.0.0.1:6379> CLUSTER NODES
8e681df773ce955600638cc2cbd1286c742f8ecd 192.168.33.131:6380@16380 master - 0 1663592790000 2 connected 5461-10922
0f5b705aed8be7cabd48ceb494736ce348b97229 192.168.33.131:6381@16381 master - 0 1663592791824 3 connected 10923-16383
560ed84d23690453e8904013a439524a48bf59df 192.168.33.131:6389@16389 slave 8e681df773ce955600638cc2cbd1286c742f8ecd 0 1663592791000 2 connected
86e92cd429e77fff4c6c5bf2b113012510f2faac 192.168.33.131:6391@16391 slave 9a5cad91efb3ba3b303c3652db9126a1ddb20b8e 0 1663592792842 1 connected
9a5cad91efb3ba3b303c3652db9126a1ddb20b8e 192.168.33.131:6379@16379 myself,master - 0 1663592792000 1 connected 0-5460
d7483bbede65ab6659b97e8a745fc32a63628809 192.168.33.131:6390@16390 slave 0f5b705aed8be7cabd48ceb494736ce348b97229 0 1663592790000 3 connected
上文中 all 16384 为插槽