mv mkreleasehdr.sh redis-benchmark redis-sentinel redis-server redis-cli redis-check-aof redis-check-dump ../bin/
三、配置sentinel
daemonize yes
logfile "/app/sinova/redis/log/sentinel.log"
sentinel monitor mymaster 10.50.13.34 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1
四、启动redis
先启动master,然后再启动slave,命令相同,如下:
/app/sinova/redis/bin/redis-server /app/sinova/redis/conf/redis.conf
启动后查看主从状态:
redis-cli info Replication
# Replication
role:master
connected_slaves:3
slave0:ip=10.50.13.35,port=6379,state=online,offset=29,lag=0
slave1:ip=10.50.13.36,port=6379,state=online,offset=29,lag=0
slave2:ip=10.50.13.37,port=6379,state=online,offset=29,lag=0
master_repl_offset:29
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:28
五、启动sentinel
先启动master,然后再启动slave,命令相同,如下:
/app/sinova/redis/bin/redis-sentinel /app/sinova/redis/conf/sentinel.conf
在master上查看/app/sinova/redis/log/sentinel.log #slave下也有此日志,可以看到内容有变化
$ cat sentinel.log
_._
_.-``__ ‘‘-._
_.-`` `. `_. ‘‘-._ Redis 2.8.17 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ‘‘-._
( ‘ , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|‘` _.-‘| Port: 26379
| `-._ `._ / _.-‘ | PID: 16995
`-._ `-._ `-./ _.-‘ _.-‘
|`-._`-._ `-.__.-‘ _.-‘_.-‘|
| `-._`-._ _.-‘_.-‘ |
http://redis.io `-._ `-._`-.__.-‘_.-‘ _.-‘
|`-._`-._ `-.__.-‘ _.-‘_.-‘|
| `-._`-._ _.-‘_.-‘ |
`-._ `-._`-.__.-‘_.-‘ _.-‘
`-._ `-.__.-‘ _.-‘
`-._ _.-‘
`-.__.-‘
[16995] 15 Sep 15:30:11.226 # Sentinel runid is cac946f212073a0e7c353e058dc7c83c9c62a161
[16995] 15 Sep 15:30:11.226 # +monitor master mymaster 10.50.13.34 6379 quorum 2
[16995] 15 Sep 15:30:11.228 * +slave slave 10.50.13.35:6379 10.50.13.35 6379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:11.228 * +slave slave 10.50.13.36:6379 10.50.13.36 6379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:11.228 * +slave slave 10.50.13.37:6379 10.50.13.37 6379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:13.264 * +sentinel sentinel 10.50.13.35:26379 10.50.13.35 26379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:13.306 * +sentinel sentinel 10.50.13.37:26379 10.50.13.37 26379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:30:13.312 * +sentinel sentinel 10.50.13.36:26379 10.50.13.36 26379 @ mymaster 10.50.13.34 6379
六、测试
停掉master上的redis
$ redis-cli shutdown
查看日志:
[16995] 15 Sep 15:33:54.131 # +sdown master mymaster 10.50.13.34 6379
[16995] 15 Sep 15:33:54.139 # +new-epoch 1
[16995] 15 Sep 15:33:54.145 # +vote-for-leader c6e609a1978e5cdb68ead8983ba88568aa85180d 1
[16995] 15 Sep 15:33:54.215 # +odown master mymaster 10.50.13.34 6379 #quorum 4/2
[16995] 15 Sep 15:33:54.215 # Next failover delay: I will not start a failover before Tue Sep 15 15:35:54 2015
[16995] 15 Sep 15:33:55.339 # +config-update-from sentinel 10.50.13.36:26379 10.50.13.36 26379 @ mymaster 10.50.13.34 6379
[16995] 15 Sep 15:33:55.339 # +switch-master mymaster 10.50.13.34 6379 10.50.13.36 6379
[16995] 15 Sep 15:33:55.339 * +slave slave 10.50.13.37:6379 10.50.13.37 6379 @ mymaster 10.50.13.36 6379
[16995] 15 Sep 15:33:55.344 * +slave slave 10.50.13.35:6379 10.50.13.35 6379 @ mymaster 10.50.13.36 6379
[16995] 15 Sep 15:33:55.350 * +slave slave 10.50.13.34:6379 10.50.13.34 6379 @ mymaster 10.50.13.36 6379
可以看到新的master为10.50.13.36