# Redis Sentinel模式搭建
架构模型图: ![这里写图片描述](https://img-blog.csdn.net/20180819042500283?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L25ld2JpZV85MDc0ODY4NTI=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)
###1、redis一主二从配置
redis7000.conf
port 7000
daemonize yes
protected-mode no
bind 192.168.1.108
pidfile /var/run/redis-7000.pid
logfile /opt/module/redis7000/data/"7000.log"
dir /opt/module/redis7000/data
slave-read-only yes
redis7001.conf
port 7001
daemonize yes
protected-mode no
bind 192.168.1.108
pidfile /var/run/redis-7001.pid
logfile /opt/module/redis7001/data/"7001.log"
dir /opt/module/redis7001/data
slave-read-only yes
slaveof 127.0.0.1 7000
redis7002.conf
port 7002
daemonize yes
protected-mode no
bind 192.168.1.108
pidfile /var/run/redis-7002.pid
logfile /opt/module/redis7002/data/"7002.log"
dir /opt/module/redis7002/data
slave-read-only yes
slaveof 127.0.0.1 7000
###2、三台Redis Sentinel 搭建
sentinel26379.conf
port 26379
daemonize yes
logfile /opt/module/redis-sentinel/data/"26379.log"
dir /opt/module/redis-sentinel/data
#sentinel通过主节点执行 info replication 命令来获取从节点信息
sentinel monitor mymaster 127.0.0.1 7000 2
#如果需要监视多套主从,就配置多个sentinel monitor mymaster2 127.0.0.1 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
启动命令:
redis-sentinel sentinel26379.conf
启动后配置文件:自动发现从节点
port 26379
daemonize yes
logfile "/opt/module/redis-sentinel/data/26379.log"
dir "/opt/module/redis-sentinel/data"
sentinel myid aa12fb6410798bb8fffe99fdbb1602d32c278c0c
sentinel deny-scripts-reconfig yes
sentinel monitor mymaster 127.0.0.1 7000 2
sentinel config-epoch mymaster 0
# Generated by CONFIG REWRITE
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 127.0.0.1 7001
sentinel known-slave mymaster 127.0.0.1 7002
sentinel current-epoch 0
多了从节点的配置信息。
其他两个sentinel配置文件:
sentinel26380.conf
port 26380
daemonize yes
logfile "/opt/module/redis-sentinel/data/26380.log"
dir "/opt/module/redis-sentinel/data"
sentinel monitor mymaster 127.0.0.1 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel26381.conf
port 26381
daemonize yes
logfile "/opt/module/redis-sentinel/data/26381.log"
dir "/opt/module/redis-sentinel/data"
sentinel monitor mymaster 127.0.0.1 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000