Redis 哨兵模式 带密码单机

Posted 1161588342

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis 哨兵模式 带密码单机相关的知识,希望对你有一定的参考价值。

语法 https://segmentfault.com/a/1190000002680804

 

启动3台redis

  更改从机的masterauth密码

 

执行redis-server redis.conf启动redis

执行redis-cli -p 6379 [6380,6381] 进入redis客户端查看info replication信息,

 

 

运行sentinel有两种方式:

redis-sentinel /path/to/sentinel.conf
redis-server   /path/to/sentinel.conf --sentinel

 

主从切换日志

10671:X 20 Jun 12:45:55.951 # +sdown master mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:55.951 # +odown master mymaster 127.0.0.1 6379 #quorum 1/1
10671:X 20 Jun 12:45:55.951 # +new-epoch 2
10671:X 20 Jun 12:45:55.951 # +try-failover master mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:55.954 # +vote-for-leader 0bc851c61ce22b98c9b3c7857f240721a5d6c9b5 2
10671:X 20 Jun 12:45:55.954 # +elected-leader master mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:55.954 # +failover-state-select-slave master mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:56.038 # +selected-slave slave 127.0.0.1:6381 127.0.0.1 6381 @ mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:56.038 * +failover-state-send-slaveof-noone slave 127.0.0.1:6381 127.0.0.1 6381 @ mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:56.128 * +failover-state-wait-promotion slave 127.0.0.1:6381 127.0.0.1 6381 @ mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:57.020 # +promoted-slave slave 127.0.0.1:6381 127.0.0.1 6381 @ mymaster 127.0.0.1 6379 选举6381作为新的主机
10671:X 20 Jun 12:45:57.020 # +failover-state-reconf-slaves master mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:57.080 * +slave-reconf-sent slave 127.0.0.1:6380 127.0.0.1 6380 @ mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:58.027 * +slave-reconf-inprog slave 127.0.0.1:6380 127.0.0.1 6380 @ mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:58.027 * +slave-reconf-done slave 127.0.0.1:6380 127.0.0.1 6380 @ mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:58.088 # +failover-end master mymaster 127.0.0.1 6379
10671:X 20 Jun 12:45:58.088 # +switch-master mymaster 127.0.0.1 6379 127.0.0.1 6381                   切换81为新的主机
10671:X 20 Jun 12:45:58.088 * +slave slave 127.0.0.1:6380 127.0.0.1 6380 @ mymaster 127.0.0.1 6381
10671:X 20 Jun 12:45:58.088 * +slave slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6381      
10671:X 20 Jun 12:46:01.162 # +sdown slave 127.0.0.1:6379 127.0.0.1 6379 @ mymaster 127.0.0.1 6381

 

以上是关于Redis 哨兵模式 带密码单机的主要内容,如果未能解决你的问题,请参考以下文章

springcloud集成redis(单机模式+哨兵模式)

SpringBoot连接redis哨兵模式

Redis学习之4种模式实践及机制解析(单机主从哨兵集群)

一文读懂Redis的四种模式,单机主从哨兵集群

一文读懂Redis的四种模式,单机主从哨兵集群

Redis技术探索「高可用架构模式」哨兵(sentinel)模式实现主从故障互切换模式详解