Redis Sentinel 物理结构
角色 | ip | port | 别名 |
---|---|---|---|
master | 127.0.0.1 | 6379 | 主节点 |
slave1 | 127.0.0.1 | 6380 | 从节点1 |
slave2 | 127.0.0.1 | 6381 | 从节点2 |
sentinel1 | 127.0.0.1 | 6382 | Sentinel节点1 |
sentinel2 | 127.0.0.1 | 6383 | Sentinel节点2 |
master节点
port 6379
daemonize yes
logfile "6379.log"
dbfilename dump.rdb
dir /usr/local/var/db/redis/
➜ bin ./redis-server myredisconf/redis-6379.conf&
# 校验是否启动成功
➜ bin ./redis-cli -h 127.0.0.1 -p 6379 ping
slave1节点
port 6380
daemonize yes
logfile "6380.log"
dbfilename dump.rdb
dir /usr/local/var/db/redis/
slaveof 127.0.0.1 6379
slave1节点
port 6381
daemonize yes
logfile "6381.log"
dbfilename dump.rdb
dir /usr/local/var/db/redis/
slaveof 127.0.0.1 6379
启动从节点
➜ bin ./redis-server myredisconf/redis-6380.conf&
➜ bin ./redis-server myredisconf/redis-6381.conf&
主节点配置信息
➜ bin ./redis-cli -h 127.0.0.1 -p 6379 info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=6380,state=online,offset=280,lag=1
slave1:ip=127.0.0.1,port=6381,state=online,offset=280,lag=1
master_replid:70d5bbe7ee9201d195fb8a743a686b12f35c1fea
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:280
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:280
从节点配置信息
➜ bin ./redis-cli -h 127.0.0.1 -p 6381 info replication
# Replication
role:slave
master_host:127.0.0.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_repl_offset:182
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:70d5bbe7ee9201d195fb8a743a686b12f35c1fea
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:182
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:182
哨兵节点配置
port 6382
daemonize yes
logfile "6382.log"
dir /usr/local/var/db/redis/
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 3000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
启动哨兵节点
➜ bin redis-sentinel myredisconf/redis-6382.conf&
哨兵配置信息
➜ bin ./redis-cli -h 127.0.0.1 -p 6382 info Sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=127.0.0.1:6379,slaves=2,sentinels=1