redis版本:2.8.17
服务器规划:
10.50.13.34(6379 master)
10.50.13.35(6379 slave)
10.50.13.36(6379 slave)
10.50.13.37(6379 slave)
一、安装redis
tar zxf redis-2.8.17.tar.gz
cd redis-2.8.17
make
make install
mv redis-2.8.17 /app/sinova/redis
cd /app/sinova/redis
mkdir bin conf rdb log
mv redis.conf sentinel.conf conf
find -maxdepth 1 -type f -delete
cd src
mv mkreleasehdr.sh redis-benchmark redis-sentinel redis-server redis-cli redis-check-aof redis-check-dump ../bin/
二、配置redis
redis.conf配置文件修改如下内容:
master配置:
daemonize yes
pidfile /app/sinova/redis/redis.pid
logfile /app/sinova/redis/log/redis.log
dir /app/sinova/redis/rdb
slave配置:
daemonize yes
pidfile /app/sinova/redis/redis.pid
logfile /app/sinova/redis/log/redis.log
dir /app/sinova/redis/rdb
slaveof 10.50.13.34 6379
三、配置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
原来的master恢复后,会加入slave的行列:
查看sentinel.log:
[16995] 15 Sep 15:40:33.897 # -sdown slave 10.50.13.34:6379 10.50.13.34 6379 @ mymaster 10.50.13.36 6379
Sentinel在实现Failover过程中,会自动修改redis.conf和sentinel.conf的配置。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/109330.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...