zoukankan      html  css  js  c++  java
  • 【redis】哨兵模式

    主  redis      192.168.2.194 6379
    从1 redis      192.168.2.221 6379
    从2 redis      192.168.2.222 6379
    哨兵1 192.168.2.194 26379
    哨兵2 192.168.2.221 26379
    哨兵3 192.168.2.222 26379
    

    redis配置文件

    注意有密码的情况下

    主redis

    requirepass redis
    masterauth  redis  作用是:当作为从角色再切主角色的时候需要密码
    

    从redis

    slaveof ip port
    masterauth redis
    

    哨兵配置

    port 26379
    daemonize yes              #守护进程
    bind 192.168.2.221         
    protected-mode no
    pidfile "/var/run/sentinel.pid"
    logfile "/var/log/sentinel.log"
    dir "/usr/local/redis/data/sentinel"
    sentinel deny-scripts-reconfig yes
    sentinel monitor mymaster 192.168.2.222 6379 2    #配置主节点信息,mymaster为别名 后面为ip port 2为推举数
    sentinel down-after-milliseconds mymaster 10000
    sentinel failover-timeout mymaster 15000
    

    启动顺序

    主>从>哨兵

    遇到的坑

    1. Next failover delay: I will not start a failover before
    配置完成之后再停掉主机点,哨兵日志中循环提示这个,不切换,原因是因为在redis配置文件中没有配置masterauth,导致salve跟master无法切换
    同时还导致一个问题是在主节点查看info replication  看到的connected-slave为0,就是因为没有密码,slave过不了验证,连接不上master
    
    2. 注意关闭各个机器的防火墙
    

    顺序

    在主节点挂掉之后,各个客户端的哨兵程序互相通信,另外两个slave会推举出一个新的master节点,在新的master节点中,配置文件被重写,包括redis.conf文件,其中的slaveof配置被去掉,另一个的slave节点的redis配置文件中的slaveof变为replicaof 新的master节点信息,
    在原先挂掉的master拉起之后,将会变为一个新的slave节点,配置文件被改写。

    同时有主备数据的功能。

  • 相关阅读:
    HTTP——Web服务器、代理、缓存
    nginx配置文件详解2
    nginx配置文件详解
    shell笔记2
    django笔记
    python 发请求,urllib,urllib2
    nginx配置
    python os模块学习
    mac 终端命令小结
    mac常用命令笔记
  • 原文地址:https://www.cnblogs.com/cizao/p/14001747.html
Copyright © 2011-2022 走看看