zoukankan      html  css  js  c++  java
  • Redis 哨兵模式

    Redis Sentinel是Redis 的高可用性解决方案,由一个或多个Sentinel(哨兵)实例组成。它可以监视任意多个主服务器,以及这些主服务器属下的所有从服务器,

    并在被监视的主服务器进入下线状态时,自动将某个从服务器升级为新的主服务器,它的主要功能如下:

    • 监控(Monitoring):Sentinel会不断地检查你的主服务器和从服务器是否运作正常; 
    • 通知(Notification):当被监控的某个 Redis 服务器出现问题时, Sentinel可以通过API向管理员或者其他应用程序发送通知。
    • 故障迁移:当主服务器不能正常工作时,Sentinel会自动进行故障迁移,也就是主从切换。
    • 统一的配置管理:连接者询问sentinel取得主从的地址。

    哨兵的配置主要就是修改sentinel.conf配置文件中的参数

    1. 复制sentinel.conf 文件到/usr/local/replica/master 目录下:

     # cp /root/tools/redis-5.0.7/sentinel.conf  /usr/local/replica/master

    2.编辑 sentinel.conf 

    主要修改4个地方:

     1)修改哨兵实例运行的端口
           port 26379 
     2) 是否设置后台启动   
             daemonize:yes
     3) 配置哨兵sentinel的日志文件
            logfile "/usr/local/sentinel/26379.log"
     4)配置哨兵sentinel监控的redis主节点的端口和地址, 2 代表两个哨兵都监听到了
         sentinel monitor mymaster 127.0.0.1 6379 2

    从节点:

    1. 复制sentinel.conf 文件到/usr/local/replica/slave1 目录下:

     # cp /root/tools/redis-5.0.7/sentinel.conf  /usr/local/replica/slave1 

    2.编辑 sentinel.conf 

    主要修改4个地方:

     1)修改哨兵实例运行的端口
           port 26380
     2) 是否设置后台启动   
             daemonize:yes
     3) 配置哨兵sentinel的日志文件
            logfile "/usr/local/sentinel/26380.log"
     4)配置哨兵sentinel监控的redis主节点的端口和地址, 2 代表两个哨兵都监听到了
         sentinel monitor mymaster 127.0.0.1 6379 2
    同理配置 slave2
     
    测试:
    首先启动Redis主从:
    cd /usr/local/replica/master ./redis-server redis.conf
    cd /usr/local/replica/slave1 ./redis-server redis.conf
    cd /usr/local/replica/slave2 ./redis-server redis.conf
     
    启动3个哨兵:
    cd /usr/local/replica/master ./redis-sentinel sentinel.conf
    cd /usr/local/replica/slave1 ./redis-sentinel sentinel.conf
    cd /usr/local/replica/slave2 ./redis-sentinel sentinel.conf
     
    查Redis 进程:
     # ps axu|grep redis 

    三个Redis和三个哨兵都已启动。

    进入slave1的客户端查询:

    #  cd /usr/local/replica/slave1  redis-cli -p  6380 

    # info replication 

     当前角色为salve;

    杀掉主节点,

    # kill -9 26430 

    再次查看slave1的角色:

     可以看到,由于master停止服务,slave1 自动切换到主节点,Sentinel 会自动进行故障迁移,实现主从切换。

     
  • 相关阅读:
    获取iframe中的元素
    用npm安装express后express命令找不到
    Openfire 单人聊天和多人聊天(发送消息、接收消息)
    openfire拦截数据包与发送广播
    xmpp with openfire 插件-利用Broadcast实现群
    Smack 结合 Openfire服务器,建立IM通信,发送聊天消息
    openfire默认数据库与应用系统数据库整合
    ios即时通讯客户端开发之-mac上安装MySQL
    ios即时通讯客户端开发之-mac上搭建openfire服务器
    IOS block使用中碰到的一个小坑
  • 原文地址:https://www.cnblogs.com/brain008/p/15572550.html
Copyright © 2011-2022 走看看