# 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