Redis version: 2.8.17
Server Planning:10.50.13.34 (6379 Master) 10.50.13.35 (6379 slave) 10.50.13.36 (6379 slave) 10.50.13.37 (6379 slave)
I. Installation of RedisTar zxf redis-2.8.17.tar.gzcd redis-2.8.17makemake installmv redis-2.8.17/app/sinova/rediscd/app/sinova/redismkdir { BIN,CONF,RDB,LOG}MV redis.conf sentinel.conf conffind-maxdepth 1-type f-deletecd SRCMV mkreleasehdr.sh Redis-benchmark Redis-sentinel redis-server redis-cli redis-check-aof redis-check-dump. /bin/
Second, configure RedisThe redis.conf configuration file modifies the following:
Master configuration:daemonize YesPidfile/app/sinova/redis/redis.pidLogfile/app/sinova/redis/log/redis.logDir/app/sinova/redis/rdb
Slave configuration:
daemonize YesPidfile/app/sinova/redis/redis.pidLogfile/app/sinova/redis/log/redis.logDir/app/sinova/redis/rdbslaveof 10.50.13.34 6379
Third, configure Sentineldaemonize Yeslogfile "/app/sinova/redis/log/sentinel.log" Sentinel Monitor MyMaster 10.50.13.34 6379 2Sentinel Down-after-milliseconds MyMaster 30000Sentinel Failover-timeout MyMaster 60000Sentinel Parallel-syncs MyMaster 1
Four, start Redis
start Master First, and then start slave with the same command as the following:
/app/sinova/redis/bin/redis-server/app/sinova/redis/conf/redis.conf
View master and slave status after startup: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
v. Launch Sentinel
start Master First, and then start slave with the same command as the following:
/app/sinova/redis/bin/redis-sentinel/app/sinova/redis/conf/sentinel.conf
View the/app/sinova/redis/log/sentinel.log #slave下也有此日志 on master and see what's changed$ cat Sentinel.log
_._
_.-' __ '-._
_.-`` `. `_. "-._ Redis 2.8.17 (00000000/0)
.-`` .-```. ' \ \ _.,_ '-._
(',.-' | ',) Running in Sentinel Mode
| '-._ '-...-' __...-. '-._| ' ' _.-' | port:26379
| '-._ '. _/_.-' | pid:16995
'-._ '-._ '-./_.-' _.-'
| '-._ '-._ '-.__.-' _.-' _.-' |
| '-._ '-._ _.-' _.-' | Http://redis.io
'-._ '-._ '-.__.-' _.-' _.-'
| '-._ '-._ '-.__.-' _.-' _.-' |
| '-._ '-._ _.-' _.-' |
'-._ '-._ '-.__.-' _.-' _.-'
'-._ '-.__.-' _.-'
'-._ _.-'
'-.__.-'
[16995] Sep 15:30:11.226 # Sentinel Runid is cac946f212073a0e7c353e058dc7c83c9c62a161
[16995] Sep 15:30:11.226 # +monitor Master MyMaster 10.50.13.34 6379 Quorum 2
[16995] Sep 15:30:11.228 * +slave slave 10.50.13.35:6379 10.50.13.35 6379 @ mymaster 10.50.13.34 6379
[16995] Sep 15:30:11.228 * +slave slave 10.50.13.36:6379 10.50.13.36 6379 @ mymaster 10.50.13.34 6379
[16995] Sep 15:30:11.228 * +slave slave 10.50.13.37:6379 10.50.13.37 6379 @ mymaster 10.50.13.34 6379
[16995] Sep 15:30:13.264 * +sentinel Sentinel 10.50.13.35:26379 10.50.13.35 26379 @ mymaster 10.50.13.34 6379
[16995] Sep 15:30:13.306 * +sentinel Sentinel 10.50.13.37:26379 10.50.13.37 26379 @ mymaster 10.50.13.34 6379
[16995] Sep 15:30:13.312 * +sentinel Sentinel 10.50.13.36:26379 10.50.13.36 26379 @ mymaster 10.50.13.34 6379
VI. Testing
shut down Redis on master
$ redis-cli Shutdown View log: [16995] Sep 15:33:54.131 # +sdown master mymaster 10.50.13.34 6379[16995] Sep 15:33:54.139 # +new-epoch 1 [16995] Sep 15:33:54.145 # +vote-for-leader c6e609a1978e5cdb68ead8983ba88568aa85180d 1[16995] Sep 15:33:54.215 # +od Own master MyMaster 10.50.13.34 6379 #quorum 4/2[16995] Sep 15:33:54.215 # Next failover delay:i would not start a fail Over before Tue Sep 15:35:54 2015[16995] Sep 15:33:55.339 # +config-update-from Sentinel 10.50.13.36:26379 10.50.13. 26379 @ mymaster 10.50.13.34 6379[16995] Sep 15:33:55.339 # +switch-master MyMaster 10.50.13.34 6379 10.50.13.36 637 9[16995] Sep 15:33:55.339 * +slave slave 10.50.13.37:6379 10.50.13.37 6379 @ mymaster 10.50.13.36 6379[16995] Sep 15 : 33:55.344 * +slave slave 10.50.13.35:6379 10.50.13.35 6379 @ mymaster 10.50.13.36 6379[16995] Sep 15:33:55.350 * +slav e slave 10.50.13.34:6379 10.50.13.34 6379 @ mymaster 10.50.13.36 6379
you can see the new master as 10.50.13.36When the original master recovers, it joins the slave: View sentinel.log:[16995] Sep 15:40:33.897 #-sdown slave 10.50.13.34:6379 10.50.13.34 6379 @ my Master 10.50.13.36 6379 Sentinel automatically modifies the configuration of redis.conf and sentinel.conf during the implementation of failover.
Redis Sentinel Implementation Failover