• redis 集群搭建


    1、测试环境单台机器多个redis实例

    [yyapp@LAPP-V1173 redis_6381]$ cat redis.conf  |grep -v  "^#" |grep -v  "^$"
    bind 0.0.0.0 
    protected-mode yes
    port 6381  多个实例需要修改
    tcp-backlog 511
    timeout 60
    tcp-keepalive 300
    daemonize yes
    supervised no
    pidfile /var/run/redis_6381.pid
    loglevel notice
    logfile ""
    databases 16
    always-show-logo yes
    save 900 1
    save 300 10
    save 60 10000
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename dump.rdb
    dir ./
    slave-serve-stale-data yes
    slave-read-only yes
    repl-diskless-sync no
    repl-diskless-sync-delay 5
    repl-disable-tcp-nodelay no
    slave-priority 100
    lazyfree-lazy-eviction no
    lazyfree-lazy-expire no
    lazyfree-lazy-server-del no
    slave-lazy-flush no
    appendonly no
    appendfilename "appendonly.aof"
    appendfsync everysec
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    aof-load-truncated yes
    aof-use-rdb-preamble no
    lua-time-limit 5000
    slowlog-log-slower-than 10000
    slowlog-max-len 128
    latency-monitor-threshold 0
    notify-keyspace-events ""
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 64
    list-max-ziplist-size -2
    list-compress-depth 0
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    hll-sparse-max-bytes 3000
    activerehashing yes
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit slave 256mb 64mb 60
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    aof-rewrite-incremental-fsync yes
    
    重新
     sed  -i 's/6390/6391/g' redis.conf
    
    启动: /usr/local/bin/redis-server  /app/redis_6391/redis.conf 

    2、redis 生产集群环境搭建

    参考文档:https://blog.csdn.net/kjsayn/article/details/53411625

    1、安装redis

    redis 配置文件
    
    
    protected-mode no
    port 6379
    tcp-backlog 511
    timeout 0
    tcp-keepalive 300
    daemonize no
    supervised no
    pidfile "/app/redis/var/run/redis_6379.pid"
    loglevel notice
    logfile "/log/redis/redis_6379.log"
    databases 16
    always-show-logo yes
    save 900 1
    save 300 10
    save 60 10000
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename "dump_6379.rdb"
    dir "/app/redis/var/data"
    slave-serve-stale-data yes
    slave-read-only yes
    repl-diskless-sync no
    repl-diskless-sync-delay 5
    repl-disable-tcp-nodelay no
    slave-priority 100
    lazyfree-lazy-eviction no
    lazyfree-lazy-expire no
    lazyfree-lazy-server-del no
    slave-lazy-flush no
    appendonly no
    appendfilename "appendonly.aof"
    appendfsync everysec
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    aof-load-truncated yes
    aof-use-rdb-preamble no
    lua-time-limit 5000
    slowlog-log-slower-than 10000
    slowlog-max-len 128
    latency-monitor-threshold 0
    notify-keyspace-events ""
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 64
    list-max-ziplist-size -2
    list-compress-depth 0
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    hll-sparse-max-bytes 3000
    activerehashing yes
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit slave 256mb 64mb 60
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    aof-rewrite-incremental-fsync yes


    如果是备:

    slave-serve-stale-data yes
    slave-read-only yes
    slave-priority 100
    slave-lazy-flush no
    client-output-buffer-limit slave 256mb 64mb 60
    slaveof 192.168.9.164 6379

     

    [yyapp@H-LAPP-V234 conf]$ cat sentinel.conf 
    # port 5000
    # 别名 IP 端口 2个Sentinel即失效
    #
    # sentinel monitor mymaster 127.0.0.1 6379 2
    # 5000毫秒即可判定主观下线
    #
    # sentinel down-after-milliseconds mymaster 5000
    #
    # 不同sentinel 尝试下线redis间隔
    # sentinel failover-timeout mymaster 60000
    #
    # 故障转移时只允许1个从对新的主服务器同步
    # 数字越小同步时间越长,数字越大故障转移时越多从不能用
    # sentinel parallel-syncs mymaster 1
    # --------------------------------------------------------
    
    port 26379
    protected-mode no   ### 开启
    dir "/app/redis/var/tmp"
    logfile "/log/redis/sentinel.log"
    
    # for 6378 redis
    sentinel myid 4ddf1e2e9e3427fdc0d556363e7aac3c2b684a5c
    sentinel monitor mymaster 192.168.9.164 6379 2
    sentinel down-after-milliseconds mymaster 5000
    sentinel failover-timeout mymaster 60000
    
    # for 6380 redis
    sentinel config-epoch mymaster 7
    sentinel leader-epoch mymaster 7
    sentinel known-slave mymaster 192.168.9.165 6379
    sentinel known-sentinel mymaster 192.168.9.165 26379 9fa02fd4191256c8b7b40716779930294cdf5477
    sentinel known-sentinel mymaster 192.168.9.163 26379 078c3fe38b8cb262345130e3a89156198f567b56
    sentinel current-epoch 7


    3、keepalive 配置  检测

    
    


    global_defs {
    notification_email {
    xiajq@yonyou.com
    }
    notification_email_from  xiajq@yonyou.com
    smtp_server 127.0.0.1
    smtp_connect_timeout 30
    router_id KEEPALIVED
    }


    vrrp_script chk_redis { script
    "/app/redis/bin/redis-cli info | grep role:master &> /dev/null" interval 2 weight -5 fall 3 rise 2 }
  • 相关阅读:
    Python JSON的基本使用
    python socket函数详解
    python关于字符编码的基本操作
    关于git的一些简单命令
    CS和BS结构的优缺点
    Web测试详细点
    详解SESSION与COOKIE的区别
    如何测试一个网页登陆界面
    二层交换机、三层交换机和路由器的原理及区别
    LSA分类
  • 原文地址:https://www.cnblogs.com/xiajq/p/13808679.html
Copyright © 2020-2023  润新知