zoukankan      html  css  js  c++  java
  • Redis的sentinel机制(sentinel节点IP为:192.168.23.10) “哨兵”

      • 万一主节点打击,主从模型将会停止工作,为了解决这个问题,Redis提供了一个sentinel(哨兵),以此来实现主从切换的功能,一旦主节点宕机了,sentinel将会在从节点中挑一个作为主节点。与zookeeper类似
    • 编辑/etc/redis-sentinel.conf文件
    1: mymaster指定主节点的主机名(可以随便取一个名),127.0.0.1 6379:指明主节点的IP和端口,2:表示一个节点要成为主节点必须拥有的票数,这里默认是2,因此最好启动2个以上centinel进程。这个指令可以写多个,表明sentinel可以监控多个Redis主从架构。这里改为1,启动centinel进程演示
    sentinel monitor mymaster 192.168.23.10 6379 1
     
    2:指明主节点多少秒联系不上,认定主服务器宕机,默认30000毫秒
    sentinel down-after-milliseconds mymaster 3000
     
    3:从新指定主服务器后,允许几台从服务器去主服务器同步数据
    sentinel parallel-syncs mymaster 1
     
    4:指定故障转移的超时时长,如果180000毫秒,无法在从服务器选择主服务器,则故障转移失败
    sentinel failover-timeout mymaster 18000
     
    5: 指定与master通信的密码
    sentinel auth-pass mymaster 123456
    • 启动systemctl
    systemctl start redis-sentinel.service
    • 登入Sentinel,查看主从状态
    redis-cli -p 26379
     
    127.0.0.1:26379> info Sentinel
    # Sentinel
    sentinel_masters:1
    sentinel_tilt:0
    sentinel_running_scripts:0
    sentinel_scripts_queue_length:0
    sentinel_simulate_failure_flags:0
    master0:name=mymaster,status=ok,address=192.168.23.10:6379,slaves=2,sentinels=1
    • 停止Redis的master节点,登入sentinel查看节点信息(此时的主节点已经是192.168.23.12了)
    systemctl stop redis.service
     
    [root@7 ~]# redis-cli -p 26379
    127.0.0.1:26379> info sentinel
    # Sentinel
    sentinel_masters:1
    sentinel_tilt:0
    sentinel_running_scripts:0
    sentinel_scripts_queue_length:0
    sentinel_simulate_failure_flags:0
    master0:name=mymaster,status=ok,address=192.168.23.12:6379,slaves=2,sentinels=1
     
    127.0.0.1:26379> sentinel masters
  • 相关阅读:
    [纯C#实现]基于BP神经网络的中文手写识别算法
    【转载】Jedis对管道、事务以及Watch的操作详细解析
    redis 缓存用户账单策略
    redis 通配符 批量删除key
    explain分析sql效率
    mysql 常用命令大全
    【转载】实战mysql分区(PARTITION)
    mysql表名忽略大小写配置
    【转】微服务架构的分布式事务解决方案
    【转载】Mysql中的Btree与Hash索引比较
  • 原文地址:https://www.cnblogs.com/liu1026/p/7685993.html
Copyright © 2011-2022 走看看