• redis复制集(sentinel)


    https://www.jianshu.com/p/45ffd2a84143

    内核配置

    cat >> /etc/rc.local << EOF
    
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
    EOF
    
    cat >> /etc/sysctl.conf << EOF
    vm.overcommit_memory = 1
    EOF
    

    静态解析

    cat >> /etc/hosts << EOF
    
    10.105.225.8    redis-master
    10.154.146.25   redis-slave
    EOF
    

    优化

    tcp-backlog 65536
    timout 300
    tcp-keepalive 300
    maxclients 10000
    maxmemory 2G
    maxmemory-policy volatile-lru
    

    配置复制

    # master /etc/redis.conf
    
    #daemonize no
    daemonize yes
    
    #bind 127.0.0.1
    bind 0.0.0.0
    
    #protected-mode yes
    protected-mode no
    
    #dir /var/lib/redis/
    dir /opt/www/redis/
    
    masterauth @sentinel
    requirepass @sentinel
    
    # slave /etc/redis.conf
    
    #daemonize no
    daemonize yes
    
    #bind 127.0.0.1
    bind 0.0.0.0
    
    #protected-mode yes
    protected-mode no
    
    #dir /var/lib/redis/
    dir /opt/www/redis/
    
    # 从机多了slaveof配置,注意主从要匹配
    slaveof redis-master 6379
    masterauth @sentinel
    requirepass @sentinel
    

    启用服务

    systemctl restart redis && systemctl enable redis
    
    systemctl restart redis-sentinel && systemctl enable redis-sentinel
    

    查看配置状态

    #redis-cli -h redis-master -a @sentinel info replication
    # Replication
    role:master
    connected_slaves:1
    slave0:ip=10.154.146.25,port=6379,state=online,offset=29,lag=1
    master_repl_offset:29
    repl_backlog_active:1
    repl_backlog_size:1048576
    repl_backlog_first_byte_offset:2
    repl_backlog_histlen:28
    
    #redis-cli -h redis-slave -a @sentinel info replication
    # Replication
    role:slave
    master_host:redis-master
    master_port:6379
    master_link_status:up
    master_last_io_seconds_ago:1
    master_sync_in_progress:0
    slave_repl_offset:15
    slave_priority:100
    slave_read_only:1
    connected_slaves:0
    master_repl_offset:0
    repl_backlog_active:0
    repl_backlog_size:1048576
    repl_backlog_first_byte_offset:0
    repl_backlog_histlen:0
    

    配置sentinel

    # 3台哨兵,2票选举
    
    cat > /etc/redis-sentinel.conf << EOF
    port 26379
    protected-mode no
    daemonize yes
    
    dir /tmp
    sentinel monitor mymaster redis-master 6379 2
    sentinel down-after-milliseconds mymaster 2000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 5000
    sentinel auth-pass mymaster @sentinel
    
    logfile /var/log/redis/sentinel.log
    EOF
    
    
    cat > /etc/sentinel_26380.conf << EOF
    port 26380
    protected-mode no
    daemonize yes
    
    dir /tmp
    sentinel monitor mymaster redis-01-master 6379 2
    sentinel down-after-milliseconds mymaster 2000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 5000
    sentinel auth-pass mymaster @sentinel
    
    logfile /var/log/redis/sentinel_26380.log
    EOF
    
    cat > /etc/sentinel_26381.conf << EOF
    port 26381
    protected-mode no
    daemonize yes
    
    dir /tmp
    sentinel monitor mymaster redis-02-master 6379 2
    sentinel down-after-milliseconds mymaster 2000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 5000
    sentinel auth-pass mymaster @sentinel
    
    logfile /var/log/redis/sentinel_26381.log
    EOF
    
    cat > /etc/sentinel_26382.conf << EOF
    port 26382
    protected-mode no
    daemonize yes
    
    dir /tmp
    sentinel monitor mymaster redis-03-master 6379 2
    sentinel down-after-milliseconds mymaster 2000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 5000
    sentinel auth-pass mymaster @sentinel
    
    logfile /var/log/redis/sentinel_26382.log
    EOF
    
    # /etc/rc.local
    /usr/bin/redis-sentinel /etc/sentinel_26380.conf &
    /usr/bin/redis-sentinel /etc/sentinel_26381.conf &
    /usr/bin/redis-sentinel /etc/sentinel_26382.conf &
    

    sentinel状态

    #redis-cli -h redis-master -p 26379 -a @sentinel info sentinel
    # Sentinel
    sentinel_masters:1
    sentinel_tilt:0
    sentinel_running_scripts:0
    sentinel_scripts_queue_length:0
    master0:name=redis-01,status=ok,address=10.105.225.8:6379,slaves=1,sentinels=3
    
    #redis-cli -h redis-slave -p 26379 -a @sentinel info sentinel
    # Sentinel
    sentinel_masters:1
    sentinel_tilt:0
    sentinel_running_scripts:0
    sentinel_scripts_queue_length:0
    master2:name=redis-01,status=ok,address=10.105.225.8:6379,slaves=1,sentinels=3
    

    sentinel切换日志

    sentinel日志
    [20104] 28 Mar 17:29:54.042 # +sdown master mymaster 10.105.225.8 6379
    [20104] 28 Mar 17:29:54.104 # +odown master mymaster 10.105.225.8 6379 #quorum 2/2
    [20104] 28 Mar 17:29:54.104 # +new-epoch 1
    [20104] 28 Mar 17:29:54.104 # +try-failover master mymaster 10.105.225.8 6379
    [20104] 28 Mar 17:29:54.169 # +vote-for-leader 016236a44f1376e34b8e6696c1b7eb0d8ebc3e59 1
    [20104] 28 Mar 17:29:54.169 # 10.154.146.25:26379 voted for b9d0dc3e20c5c138304419a17f572e56be61a3fd 1
    [20104] 28 Mar 17:29:54.169 # 10.154.43.8:26379 voted for 27c052e9e9b3ad99edc6fe85f5566157e9865309 1
    [20104] 28 Mar 17:29:54.169 # 10.154.162.125:26379 voted for b9d0dc3e20c5c138304419a17f572e56be61a3fd 1
    [20104] 28 Mar 17:29:54.189 # 10.154.160.30:26379 voted for b9d0dc3e20c5c138304419a17f572e56be61a3fd 1
    [20104] 28 Mar 17:29:54.195 # 10.105.93.170:26379 voted for 1823e7153adb3b302a6c05e2a79ce508217e5b9f 1
    [20104] 28 Mar 17:30:04.361 # -failover-abort-not-elected master redis-01 10.105.225.8 6379
    [20104] 28 Mar 17:30:04.416 # Next failover delay: I will not start a failover before Wed Mar 28 17:35:54 2018
    [20104] 28 Mar 17:35:54.336 # +new-epoch 2
    [20104] 28 Mar 17:35:54.341 # +vote-for-leader b9d0dc3e20c5c138304419a17f572e56be61a3fd 2
    [20104] 28 Mar 17:35:54.341 # Next failover delay: I will not start a failover before Wed Mar 28 17:41:54 2018
    [20104] 28 Mar 17:35:54.728 # +config-update-from sentinel 10.154.162.125:26379 10.154.162.125 26379 @ redis-01 10.105.225.8 6379
    [20104] 28 Mar 17:35:54.728 # +switch-master redis-01 10.105.225.8 6379 10.154.146.25 6379
    [20104] 28 Mar 17:35:54.728 * +slave slave 10.105.225.8:6379 10.105.225.8 6379 @ redis-01 10.154.146.25 6379
    [20104] 28 Mar 17:36:24.754 # +sdown slave 10.105.225.8:6379 10.105.225.8 6379 @ redis-01 10.154.146.25 6379
    
  • 相关阅读:
    TCPUDPSocket调试工具v2.2
    C#高性能Socket服务器IOCP实现
    c#使用HttpListener监听HTTP请求
    Winform Socket通信
    C# 方法中的this参数(扩展方法)
    C# 两种方法实现HTTP协议迷你服务器
    C#访问HTTP请求
    Socket通信原理
    C#数据decimal保留两位小数
    单机网站架构云化后架构图
  • 原文地址:https://www.cnblogs.com/liujitao79/p/8674560.html
Copyright © 2020-2023  润新知