美文网首页
Redis部署

Redis部署

作者: Lisong | 来源:发表于2017-11-16 10:27 被阅读16次

    redis 主从部署和哨兵配置

    系统Centos6.8

    master  192.168.150.128
    slave1  192.168.150.129
    slave2  192.168.150.130
    
    sentinel1  192.168.150.128
    sentinel2  192.168.150.129
    sentinel3  192.168.150.130
    

    安装redis

    redis官网获取最新稳定版redis
    https://redis.io/download

    yum install -y gcc-c++ tcl
    tar zxvf redis-3.2.9.tar.gz
    cd redis-3.2.9
    make && make install
    cd utils
    ./install_server.sh  #生成配置文件并启动服务
    

    安装完成后
    redis bin目录在
    /usr/local/

    redis master 配置

    killall redis-server
    cd  /etc/redis
    cp 6379.conf 6379.conf_bak
    
    cat 6379.conf
    #注释127.0.0.1 的绑定
    #bind 127.0.0.1
    #关闭安全模式
    protected-mode no
    port 6379
    tcp-backlog 511
    timeout 0
    tcp-keepalive 300
    daemonize yes
    supervised no
    pidfile "/var/run/redis_6379.pid"
    loglevel notice
    logfile "/var/log/redis_6379.log"
    databases 16
    save 900 1
    save 300 10
    save 60 10000
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename "dump.rdb"
    dir "/var/lib/redis/6379"
    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
    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
    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
    requirepass "mima"
    
    #绑定ip
    bind  192.168.150.128
    #从服务器只读模式
    slave-read-only yes
    

    redis slave 配置是一样的

    killall redis-server
    cd  /etc/redis
    cp 6379.conf 6379.conf_bak
    
    cat 6379.conf
    #注释127.0.0.1 的绑定
    #bind 127.0.0.1
    #关闭安全模式
    protected-mode no
    port 6379
    tcp-backlog 511
    timeout 0
    tcp-keepalive 300
    daemonize yes
    supervised no
    pidfile "/var/run/redis_6379.pid"
    loglevel notice
    logfile "/var/log/redis_6379.log"
    databases 16
    save 900 1
    save 300 10
    save 60 10000
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename "dump.rdb"
    dir "/var/lib/redis/6379"
    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
    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
    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
    
    #绑定ip
    Bind 192.168.150.129
    #从服务器只读模式
    slave-read-only yes
    #指定主服务器IP和端口
    slaveof 192.168.150.128 6379
    
    

    配置哨兵

    哨兵配置文件,其他哨兵在本机的,需要修改端口,端口不能重复
    vim sentinel_26381.conf

    port 26381   #指定哨兵端口
    protected-mode no   #关闭安全模式
    sentinel monitor master1 192.168.150.128 6379 2
    logfile "/data/logs/redis/sentinel_26381.log"
    sentinel down-after-milliseconds master1 30000
    sentinel failover-timeout master1 900000
    sentinel parallel-syncs master1 1
    

    启动redis

     #如果是使用的脚本生成的配置文件,使用下面方式可以启动
    service redis_端口号 start 
    
    service redis_6379 start 
    
    

    启动哨兵

    redis-sentinel /etc/redis/sentinel_26381.conf &
    

    查看redis状态

    redis-cli -p 6379 info | grep role
    ----------------------------------
    role:master
    

    查看哨兵状态

    redis-cli -p 26383 info | grep sentinel
    -----------------------------------------
    redis_mode:sentinel
    executable:/etc/redis/redis-sentinel
    config_file:/etc/redis/sentinel_26383.conf
    sentinel_masters:1
    sentinel_tilt:0
    sentinel_running_scripts:0
    sentinel_scripts_queue_length:0
    sentinel_simulate_failure_flags:0
    master0:name=master1,status=ok,address=127.0.0.1:6379,slaves=1,sentinels=3
    

    相关文章

      网友评论

          本文标题:Redis部署

          本文链接:https://www.haomeiwen.com/subject/wotlvxtx.html