温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

redis自动主从切换

发布时间:2020-07-28 20:45:11 来源:网络 阅读:625 作者:wcy3781 栏目:数据库

127.0.0.1     7000     master

127.0.0.1     7001     slave

127.0.0.1     7002     slave

127.0.0.1     7003     slave

查看主上面连接的从


redis-cli -p 7000 info Replication


# Replication

role:master

connected_slaves:3

slave0:ip=127.0.0.1,port=7001,state=online,offset=2532,lag=0

slave1:ip=127.0.0.1,port=7002,state=online,offset=2532,lag=0

slave2:ip=127.0.0.1,port=7003,state=online,offset=2532,lag=1

master_repl_offset:2532

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:2

repl_backlog_histlen:2531

创建sentinel配置文件


vim /redis_test/7000/sentinel.conf


port 26379

sentinel monitor master 127.0.0.1 7000 2

sentinel down-after-milliseconds master 5000

sentinel failover-timeout master 60000

sentinel config-epoch master 12

vim /redis_test/7001/sentinel.conf


port 26479

sentinel monitor master 127.0.0.1 7000 2

sentinel down-after-milliseconds master 5000

sentinel failover-timeout master 60000

sentinel config-epoch master 12

vim /redis_test/7002/sentinel.conf


port 26579

sentinel monitor master 127.0.0.1 7000 2

sentinel down-after-milliseconds master 5000

sentinel failover-timeout master 60000

sentinel config-epoch master 12

启动sentinel

/usr/src/redis/src/redis-server /redis_database/7000/sentinel.conf --sentinel &

/usr/src/redis/src/redis-server /redis_database/7001/sentinel.conf --sentinel &

/usr/src/redis/src/redis-server /redis_database/7002/sentinel.conf --sentinel &

将主7000关掉


redis-cli -p 7000 shutdown


redis-cli -p 7002 info replication


# Replication

role:master

connected_slaves:2

slave0:ip=127.0.0.1,port=7001,state=online,offset=6345,lag=0

slave1:ip=127.0.0.1,port=7003,state=online,offset=6345,lag=0

master_repl_offset:6345

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:2

repl_backlog_histlen:6344


可以发现7002变成了新的主库


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI