• REDIS7.X哨兵模式


    https://github.com/redis/redis/archive/7.2.4.tar.gz

    https://redis.io/docs/install/install-redis/

    https://blog.csdn.net/const_/article/details/89222823

    https://c.biancheng.net/redis/config-summary.html

    https://blog.51cto.com/u_15049794/4057388

    安装redis

    mkdir /data && cd /data
    tar -zxvf 7.2.4.tar.gz
    cd /data/redis-7.2.4
    make
    make install PREFIX=/usr/local/redis
    
    • 1
    • 2
    • 3
    • 4
    • 5

    server 配置

    # bind 127.0.0.1 -::1
    daemonize yes
    logfile "6379.log"
    masterauth "123456"
    requirepass "123456"
    dbfilename "dump.rdb"
    appendonly yes
    appenddirname "appendonlydir"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    sentinel 配置

    port 26379
    daemonize yes
    logfile "26379.log"
    pidfile "/var/run/redis-sentinel.pid"
    dir ./
    sentinel auth-pass mymaster 123456
    sentinel monitor mymaster 192.168.1.171 6379 2
    sentinel down-after-milliseconds mymaster 30000
    sentinel parallel-syncs mymaster 1
    sentinel failover-timeout mymaster 20000
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    启动脚本

    /data/redis-7.2.4/utils/redis_init_script

    server /etc/rc.d/init.d/redis-server

    #!/bin/sh
    #
    # Simple Redis init.d script conceived to work on Linux systems
    # as it does use of the /proc filesystem.
    
    ### BEGIN INIT INFO
    # Provides:     redis_6379
    # Default-Start:        2 3 4 5
    # Default-Stop:         0 1 6
    # Short-Description:    Redis data structure server
    # Description:          Redis data structure server. See https://redis.io
    ### END INIT INFO
    
    REDISPORT=6379
    AUTH=123456
    EXEC=/usr/local/redis/bin/redis-server
    CLIEXEC=/usr/local/redis/bin/redis-cli
    
    PIDFILE=/var/run/redis_${REDISPORT}.pid
    CONF="/usr/local/redis/redis.conf"
    
    case "$1" in
        start)
            if [ -f $PIDFILE ]
            then
                    echo "$PIDFILE exists, process is already running or crashed"
            else
                    echo "Starting Redis server..."
                    $EXEC $CONF
            fi
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                    echo "$PIDFILE does not exist, process is not running"
            else
                    PID=$(cat $PIDFILE)
                    echo "Stopping ..."
                    $CLIEXEC -p $REDISPORT -a $AUTH shutdown 2>/dev/null
                    while [ -x /proc/${PID} ]
                    do
                        echo "Waiting for Redis to shutdown ..."
                        sleep 1
                    done
                    echo "Redis stopped"
            fi
            ;;
        restart)
            $0 stop
            $0 start
            ;;
        *)
            echo "Please use start or stop as first argument"
            ;;
    esac
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55

    sentinel /etc/rc.d/init.d/redis-sentinel

    #!/bin/sh
    #
    # Simple Redis init.d script conceived to work on Linux systems
    # as it does use of the /proc filesystem.
    
    ### BEGIN INIT INFO
    # Provides:     redis_6379
    # Default-Start:        2 3 4 5
    # Default-Stop:         0 1 6
    # Short-Description:    Redis data structure server
    # Description:          Redis data structure server. See https://redis.io
    ### END INIT INFO
    
    REDISPORT=26379
    EXEC=/usr/local/redis/bin/redis-sentinel
    CLIEXEC=/usr/local/redis/bin/redis-cli
    
    PIDFILE=/var/run/redis-sentinel.pid
    CONF="/usr/local/redis/sentinel.conf"
    
    case "$1" in
        start)
            if [ -f $PIDFILE ]
            then
                    echo "$PIDFILE exists, process is already running or crashed"
            else
                    echo "Starting Redis sentinel..."
                    $EXEC $CONF
            fi
            ;;
        stop)
            if [ -f $PIDFILE ]
            then
                    echo "Redis sentinel is not running!"
            else
                    echo "Stopping ..."
                    $CLIEXEC -p $REDISPORT shutdown 2>/dev/null
                    echo "Redis stopped"
            fi
            ;;
        restart)
            $0 stop
            $0 start
            ;;
        *)
            echo "Please use start or stop as first argument"
            ;;
    esac
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48

    增加执行权限

    chmod u+x /etc/init.d/redis-server /etc/init.d/redis-sentinel
    
    • 1

    设置开机启动

    chkconfig redis-sentinel on
    chkconfig redis-server on
    
    • 1
    • 2

    启动

    service redis-server start
    service redis-sentinel start 
    
    • 1
    • 2

    其他

    somaxconn 告警

    The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
    
    • 1
    /etc/sysctl.conf
    net.core.somaxconn = 1024
    
    • 1
    • 2

    vm.overcommit_memory 内存分配告警

    16821:C 07 Feb 2024 13:53:37.747 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
    
    • 1

    RedisInsight

    https://redis.io/docs/install/install-redisinsight/install-on-docker/

    docker run -d --name redisinsight -p 5540:5540 redis/redisinsight:latest -v redisinsight:/data/redisinsight
    
    • 1

    压测

    redis-benchmark -h host -p port -c connections -n requests
    
    • 1
  • 相关阅读:
    LeedCode 1402. 做菜顺序
    xss学习笔记
    2009-2013、2018-2020计算机网络考研408真题
    【面试八股总结】C++内存管理:内存分区、内存泄漏、new和delete、malloc和free
    【面试必备】我跟面试官聊了一个小时线程池!
    OA系统,有效提升企业办公效率落实执行力
    【mysql官方文档】死锁
    数据挖掘与分析课程笔记(Chapter 15)
    gcc -static 在centos stream8 和centos stream9中运行报错的解决办法
    BE节点经常挂掉:[IO_ERROR]failed to list /proc/27349/fd/: No such file or directory
  • 原文地址:https://blog.csdn.net/a53715668/article/details/136210515