背景:

     前面介绍了Redis 复制、Sentinel的搭建和原理说明,通过这篇文章大致能了解Sentinel的原理和实现方法以及相关的搭建。这篇文章就针对Redis Sentinel的搭建做下详细的说明。

安装:

     这里对源码编译进行一下说明,本文实例的操作系统是Ubuntu16.04,使用Redis的版本是3.2.0。安装步骤如下:

  • 下载源码包:wget http://download.redis.io/releases/redis-3.2.0.tar.gz
  • 安装依赖包:sudo apt-get install gcc tcl
  • 解压编译   :
    #tar zxvf redis-3.2.0.tar.gz
    ...
    ...
    #make
    ...
    Hint: It's a good idea to run 'make test' ;)
    #make test
    ...
    \o/ All tests passed without errors!
    ...
    #make install

    注意:这里很可能会在make test 这步出现一个错误:

    [err]: Test replication partial resync: ok psync (diskless: yes, reconnect: 1) in tests/integration/replication-psync.tcl

    Expected condition '[s -1 sync_partial_ok] > 0' to be true ([s -1 sync_partial_ok] > 0)

    出现这个问题的原因可能是"测试点在配置比较低的机器上会因为超时而过不了",本文的环境是一个lxc的虚拟机。不过有2个方法可以避免:

    1:在解压目录中修改
    # vi tests/integration/replication-psync.tcl
    把 after 100 改成 after 500
    
    2:用taskset来make test
    # taskset -c 1 make test

    到此redis编译安装完成。

  • 编译文件的目录里有2个配置:
    redis.confsentinel.conf,配置文件说明请见这篇文章
  • 本文测试的环境架构:
    3个redis实例1主、2从、3sentinel。M:10.0.3.110、S:10.0.3.92、10.0.3.66,每个redis实例上配置一个sentinel实例。修改配置文件:
    redis.conf
  • Redis Sentinel 高可用实现说明
    # Redis configuration file example.
    # ./redis-server /path/to/redis.conf
    
    ################################## INCLUDES ###################################
    
    # include /path/to/local.conf
    # include /path/to/other.conf
    
    ################################## NETWORK #####################################
    
    bind 10.0.3.110
    
    protected-mode yes
    
    port 6379
    
    tcp-backlog 511
    
    unixsocket "/tmp/redis.sock"
    unixsocketperm 700
    
    timeout 0
    
    tcp-keepalive 0
    
    ################################# GENERAL #####################################
    
    daemonize yes
    
    pidfile "/var/run/redis6379.pid"
    
    loglevel notice
    
    logfile "/var/log/redis/redis_6379.log"
    
    # syslog-enabled no
    # syslog-ident redis
    # syslog-facility local0
    
    databases 16
    supervised no
    
    ################################ SNAPSHOTTING  ################################
    
    save 900 1
    save 300 10
    save 60 10000
    
    stop-writes-on-bgsave-error yes
    
    rdbcompression yes
    
    rdbchecksum yes
    
    dbfilename "dump_6379.rdb"
    
    dir "/var/lib/redis_6379"
    
    ################################# REPLICATION #################################
    
    # slaveof <masterip> <masterport>
    masterauth "dxydxy"
    
    slave-serve-stale-data yes
    slave-read-only yes
    
    repl-diskless-sync no
    repl-diskless-sync-delay 5
    
    # repl-ping-slave-period 10
    # repl-timeout 60
    
    repl-disable-tcp-nodelay no
    repl-backlog-size 5mb
    repl-backlog-ttl 3600
    
    slave-priority 100
    
    #min-slaves-to-write 3
    #min-slaves-max-lag 10
    
    ################################## SECURITY ###################################
    
    requirepass "dxydxy"
    # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
    # rename-command CONFIG ""
    
    ################################### LIMITS ####################################
    
    maxclients 1000
    #maxmemory <bytes>
    maxmemory-policy noeviction
    # maxmemory-samples 5
    
    ############################## APPEND ONLY MODE ###############################
    
    appendonly yes
    
    appendfilename "appendonly_6379.aof"
    
    # appendfsync always
    appendfsync everysec
    # appendfsync no
    
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    aof-load-truncated yes
    
    ################################ LUA SCRIPTING  ###############################
    
    lua-time-limit 5000
    
    ################################ REDIS CLUSTER  ###############################
    
    # cluster-enabled yes
    # cluster-config-file nodes-6379.conf
    # cluster-node-timeout 15000
    # cluster-slave-validity-factor 10
    # cluster-migration-barrier 1
    # cluster-require-full-coverage yes
    
    ################################## SLOW LOG ###################################
    
    slowlog-log-slower-than 10000
    slowlog-max-len 128
    
    ################################ LATENCY MONITOR ##############################
    
    latency-monitor-threshold 0
    
    ############################# EVENT NOTIFICATION ##############################
    
    notify-keyspace-events ""
    
    ############################### ADVANCED CONFIG ###############################
    
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 64
    
    list-max-ziplist-entries 512
    list-max-ziplist-value 64
    
    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
    
    list-max-ziplist-size -2
    View Code

相关文章: