Redis sentinel 集群方案

    Redis sentinel 集群方案——部署
公司新项目需要使用redis集群,综合考虑了一些方案,最后选择了Redis sentinel,
先在虚拟机部署测试环境如下:

sentinel 2台
redis 实例 3个

部分配置如下,采用的默认配置,记得开启认证及最大内存限制,即使是测试环境也要开启认证,
好的习惯是安全生产第一步。

  • ip:192.168.162.130
redis-6380:
bind 192.168.162.128
protected-mode yes
port 6380
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/var/run/redis_6380.pid"
loglevel notice
logfile "/var/log/redis_6380.log"
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"
maxmemory 50M
appendonly no
appendfilename "appendonly.aof"

redis-6381:
bind 192.168.162.128
protected-mode yes
port 6381
tcp-backlog 511
timeout 0
slaveof 192.168.162.128 6380
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
maxmemory 50M

sentinel1.conf
daemonize yes
port 26379
dir "/tmp"
sentinel monitor mymaster 192.168.162.128 6380 2
sentinel down-after-milliseconds mymaster 6000
sentinel failover-timeout mymaster 60000
sentinel auth-pass mymaster 123456
sentinel parallel-syncs mymaster 1
logfile "/var/log/sentinel1.log"
protected-mode no
启动后sentinel 会自动修改配置文件,修改后如下
[root@linux-node1 redis]# cat sentinel1.conf 
daemonize yes
port 26379
dir "/tmp"
sentinel myid b777f8a0c7f7cf219804a3f140535a58ed067b96
sentinel monitor mymaster 192.168.162.128 6380 2
sentinel down-after-milliseconds mymaster 6000
sentinel failover-timeout mymaster 60000
sentinel auth-pass mymaster 123456
logfile "/var/log/sentinel1.log"
protected-mode no
# Generated by CONFIG REWRITE
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 192.168.162.130 6380
sentinel known-slave mymaster 192.168.162.128 6381
sentinel known-sentinel mymaster 192.168.162.130 26379 94680c01a0112bb24d7cc131bd37b388da00b087
sentinel current-epoch 0





================我是分割线================
  • ip:192.168.162.130
redis-6380:
bind 192.168.162.130
protected-mode yes
port 6380
slaveof 192.168.162.128 6380
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"
maxmemory 50M


sentinel1.conf
daemonize yes
port 26379
dir "/tmp"
sentinel monitor mymaster 192.168.162.128 6380 2
sentinel down-after-milliseconds mymaster 6000
sentinel failover-timeout mymaster 60000
sentinel auth-pass mymaster 123456
sentinel parallel-syncs mymaster 1
logfile "/var/log/sentinel1.log"
protected-mode no
启动后被自动修改为:
[root@linux-node2 redis]# cat sentinel1.conf 
daemonize yes
port 26379
dir "/tmp"
sentinel myid 94680c01a0112bb24d7cc131bd37b388da00b087
sentinel monitor mymaster 192.168.162.128 6380 2
sentinel down-after-milliseconds mymaster 6000
sentinel failover-timeout mymaster 60000
sentinel auth-pass mymaster 123456
logfile "/var/log/sentinel1.log"
protected-mode no
# Generated by CONFIG REWRITE
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 192.168.162.130 6380
sentinel known-slave mymaster 192.168.162.128 6381
sentinel known-sentinel mymaster 192.168.162.128 26379 b777f8a0c7f7cf219804a3f140535a58ed067b96
sentinel current-epoch 0

================我是分割线================

注意事项:
  1. 如果多台机器redis实例端口有相同的如我都有6380端口, bind地址不要写成127.0.0.1,指定为本机ip,sentinel进行管理时会修改配置文件,将其他机器的相同端口的bing ip 修改为127.0.0.1(如果前面写了127,此处将是个坑)。
  2. redis、sentinel需要开启认证。
  3. 已经挂断的实例如果是master的话,再次启动时记得修改配置文件,将slaveof指向当前的master,并注意同步rdb或者aof文件。
  4. 启动宕掉的实例时不要用这种方式启动/usr/local/bin/redis-server /etc/redis/6380.conf --slaveof 192.168.162.128 6381 ,如果这种方式启动的话,配置会被修改为127.0.0.1
  5. 多sentinel 时记得protected-mode no ,否则多哨兵无法通知对方进行决策Sdown、Odown。






posted @ 2017-02-13 11:38  JasonQ.Meng  阅读(208)  评论(0编辑  收藏  举报