美文网首页
哨兵集群实践

哨兵集群实践

作者: sknfie | 来源:发表于2020-08-03 20:40 被阅读0次

    概述

    光说不练假把式,现在就开始部署哨兵集群,以及如何基于哨兵进行故障转移。

    哨兵配置

    • 哨兵默认用的是26379端口
    • 默认不能跟其他机器的指定端口连通
    • 只能通过本地访问
    1. 创建两个目录:配置文件目录
    mkdir /etc/sentinal
    mkdir -p /var/sentinal/5000
    [redis-4.0.11]# cp sentinel.conf /etc/sentinal/5000.conf
    
    1. 配置文件:/etc/sentinel/5000.conf
    port 5000
    bind 172.30.0.11
    protected-mode no
    daemonize yes
    logfile "/var/log/redis/5000.log"
    dir /var/sentinal/5000
    sentinel monitor mymaster 172.30.0.11 6379 2
    sentinel down-after-milliseconds mymaster 30000
    sentinel failover-timeout mymaster 60000
    sentinel parallel-syncs mymaster 1
    sentinel auth-pass mymaster pass1234
    
    port 5000
    bind 172.30.0.4
    protected-mode no
    daemonize yes
    logfile "/var/log/redis/5000.log"
    dir /var/sentinal/5000
    sentinel monitor mymaster 172.30.0.11 6379 2
    sentinel down-after-milliseconds mymaster 30000
    sentinel failover-timeout mymaster 60000
    sentinel parallel-syncs mymaster 1
    
    port 5000
    bind 172.30.0.10
    protected-mode no
    daemonize yes
    logfile "/var/log/redis/5000.log"
    dir /var/sentinal/5000
    sentinel monitor mymaster 172.30.0.11 6379 2
    sentinel down-after-milliseconds mymaster 30000
    sentinel failover-timeout mymaster 60000
    sentinel parallel-syncs mymaster 1
    

    启动哨兵进程

    在三台机器上分别启动三个哨兵进程,用来组成一个集群,并且观察日志的输出:

    redis-sentinel /etc/sentinal/5000.conf
    redis-server /etc/sentinal/5000.conf --sentinel
    

    日志展示信息:

    • 每个哨兵都能监控到redis master
    • 每个哨兵能够自动发现其他的slave
    • 哨兵之间通过pub/sub消息发布和订阅channel消息系统和机制会自动进行发现

    检查哨兵状态

    redis-cli -h 172.30.0.11 -p 5000
    sentinel master mymaster
    SENTINEL slaves mymaster
    SENTINEL sentinels mymaster
    SENTINEL get-master-addr-by-name mymaster
    

    相关文章

      网友评论

          本文标题:哨兵集群实践

          本文链接:https://www.haomeiwen.com/subject/cdukrktx.html