• redis哨兵练习


    1、6台服务器,3台作一个主从,3台作哨兵

    服务器IP
    主redis192.168.99.133
    从redis1192.168.99.139
    从redis2192.168.99.141
    哨兵1192.168.99.144
    哨兵2192.168.99.156
    哨兵3192.168.99.160

    6台服务器安装好redis,全部执行:

    #把redis的可执行程序文件放入路径环境变量的目录中便于系统识别
    ln -s /usr/local/redis/bin/* /usr/local/bin/
    cp -f /opt/redis-5.0.7/redis.conf /usr/local/redis/bin/
    cd /usr/local/redis/bin/
    sed -i '136s/daemonize no/daemonize yes/' /usr/local/redis/bin/redis.conf
    sed -i '69s/bind 127.0.0.1/bind 0.0.0.0/' /usr/local/redis/bin/redis.conf
    
    redis-server redis.conf
    

    从redis服务器

    redis-cli
    slaveof 192.168.99.133 6379
    

    查看从服务器状态

    info replication  
    

    在这里插入图片描述
    在这里插入图片描述
    在主redis添加一个key验证
    在这里插入图片描述
    配置3台哨兵

    cp -f /opt/redis-5.0.7/sentinel.conf /usr/local/redis/bin/
    vim /usr/local/redis/bin/sentinel.conf
    
    protected-mode no #17行,关闭保护模式
    port 26379 #21行,Redis哨兵默认的监听端口
    daemonize yes #26行,指定sentinel为后台启动
    logfile "/var/log/sentinel.log" #36行,指定日志存放路径
    dir /tmp #65行,指定数据库存放路径
    sentinel monitor mymaster 192.168.99.133 6379 2 #84行,修改 指定该哨兵节点监控192.168.99.133:6379这个主节点,该主节点的名称是mymaster,最后的2的含义与主节点的故障判定有关:至少需要2个哨兵节点同意,才能判定主节点故障并进行故障转移
    sentinel down-after-milliseconds mymaster 30000 #113行,判定服务器down掉的时间周期,默
    认30000毫秒(30秒)
    sentinel failover-timeout mymaster 180000 #146行,故障节点的最大超时时间为
    180000(180秒)
    
    redis-sentinel /usr/local/redis/bin/sentinel.conf
    

    查看哨兵信息

    redis-cli -p 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.99.133:6379,slaves=2,sentinels=3
    
    

    测试:
    杀死master

     ps -ef|grep redis
    root      97335      1  0 23:11 ?        00:00:01 redis-server 0.0.0.0:6379
    kill 97335
    
    redis-cli -p 26379 info Sentinel
    

    成功切换
    在这里插入图片描述

    2、6台服务器,每台服务器一个redis一个哨兵

    服务器IP
    主redis、哨兵1192.168.99.133
    从redis1、哨兵2192.168.99.139
    从redis2、哨兵3192.168.99.141
    从redis3、哨兵4192.168.99.144
    从redis4、哨兵5192.168.99.156
    从redis5、哨兵6192.168.99.160

    接上题6台服务器安装好redis并启动

    除去192.168.99.133:

    redis-cli
    replicaof 192.168.99.133 6379
    

    配置6台哨兵

    cp -f /opt/redis-5.0.7/sentinel.conf /usr/local/redis/bin/
    vim /usr/local/redis/bin/sentinel.conf
    
    protected-mode no #17行,关闭保护模式
    port 26379 #21行,Redis哨兵默认的监听端口
    daemonize yes #26行,指定sentinel为后台启动
    logfile "/var/log/sentinel.log" #36行,指定日志存放路径
    dir /tmp #65行,指定数据库存放路径
    sentinel monitor mymaster 192.168.99.133 6379 4 #84行,修改 指定该哨兵节点监控192.168.99.133:6379这个主节点,该主节点的名称是mymaster,最后的4的含义与主节点的故障判定有关:至少需要4个哨兵节点同意,才能判定主节点故障并进行故障转移
    sentinel down-after-milliseconds mymaster 30000 #113行,判定服务器down掉的时间周期,默
    认30000毫秒(30秒)
    sentinel failover-timeout mymaster 180000 #146行,故障节点的最大超时时间为
    180000(180秒)
    
    redis-sentinel /usr/local/redis/bin/sentinel.conf
    

    查看哨兵信息

    redis-cli -p 26379 info Sentinel
    

    在这里插入图片描述

  • 相关阅读:
    项目部署到Linux
    【Linux安全之iptables的target】
    前端数据可视化之【title、legend、tooltip、toolbox 】配置项
    DolphinScheduler3.1简介、部署、功能介绍以及架构设计
    HarmonyOS 实现底部导航栏
    嵌入式开发学习之--RCC(上)
    Ajax学习:Ajax请求基本操作
    BUUCTF--WEB
    centos 时间同步 ntpdate
    DOX-TF/Ce6/IgG 转铁蛋白/光敏剂/单抗IgG修饰阿霉素/阿霉素白蛋白纳米粒的制备
  • 原文地址:https://blog.csdn.net/qq_18296979/article/details/139490550