Redis哨兵配置
阿新 • • 發佈:2018-06-24
not req HA img flush key XP load end
Sentinel(哨兵)是Redis 的高可用性解決方案:由一個或多個Sentinel 實例 組成的Sentinel 系統可以監視任意多個主服務器,以及這些主服務器屬下的所有從服務器,並在被監視的主服務器進入下線狀態時,自動將下線主服務器屬下的某個從服務器升級為新的主服務器。
192.168.56.11的redis配置如下
bind 0.0.0.0 protected-mode yes port 6379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes supervised no pidfile "/var/run/redis_6379.pid" loglevel notice logfile "" databases 16 always-show-logo yes stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename "dump.rdb" dir "/etc/redis" masterauth "123456" slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 requirepass "123456" lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no slave-lazy-flush no appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-use-rdb-preamble no lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes
192.168.56.12的redis配置是一樣的
啟動兩臺主機的redis
redis-server /etc/redis/6379.conf
在192.168.56.12的redis命令行執行命令設置主從
slaveof 192.168.56.11 6379
在11上面查看主從狀態
在12上面查看主從狀態
設置兩臺主機的哨兵配置/etc/redis/sentinel.conf
protected-mode no port 26379 daemonize yes logfile "/var/log/redis/sentinel.log" dir "/tmp" sentinel myid 3e945f7ff33d43dc4a451fa13297bd0bd3940338 sentinel monitor mymaster 192.168.56.11 6379 2 sentinel auth-pass mymaster 123456 sentinel config-epoch mymaster 4 sentinel leader-epoch mymaster 4
兩臺主機配置一樣
只需要設置監控的master對應的主機IP和端口,不要忘記需要設置加密的密碼
啟動哨兵
redis-sentinel /etc/redis/sentinel.conf
查看進程
關閉主的redis模擬master宕機同時查看哨兵日誌
登錄192.168.56.12查看主從狀態可以看到提升為master了從是空的
重新啟動11的redis
redis-server /etc/redis/6379.conf
查看日誌11成為12的從,12還是master
登錄11查看主從狀態
Redis哨兵配置