Redis之Sentinel高可用安装部署
发布日期:2021-05-09 09:25:57 浏览次数:16 分类:博客文章

本文共 28982 字,大约阅读时间需要 96 分钟。

���������

      ������������������������������������sentinel���������������������������������������������������������������������������������������������������������������������������sentinel���������2���redis���������������3���sentinel���������������������������������������������������Sentinel������������������

���������

      Redis���������Redis-3.2.8

      ���������������Ubuntu 14.04

      ��������� ���192.168.1.55���192.168.1.56���192.168.1.57���55/56������redis���sentinel���������57������sentinel������������������������55���Master���

������(���������)���

       ������������������������������������apt-get install make gcc tcl

  • ���
    wget http://download.redis.io/releases/redis-3.2.8.tar.gz
  • ���������
    1: ���������/usr/local/src ���������������������root@redis1:/usr/local/src# tar zxvf redis-3.2.8.tar.gz root@redis1:/usr/local/src# ls -lhdrwxrwxr-x 6 root root 4.0K  2��� 22 15:01 redis-3.2.82������������������/usr/local/redis������������������������/usr/local/redis/ --���������������make PREFIX=/usr/local/redis install3������������������������bin���������������������������ln -s /usr/local/redis/bin/redis-cli /usr/local/bin/redis-cliln -s /usr/local/redis/bin/redis-sentinel /usr/local/bin/redis-sentinelln -s /usr/local/redis/bin/redis-server /usr/local/bin/redis-server
  • ���������
    1������������������������������������������sentinel.conf���redis.conf������������������/etc/redis/���������������������������������������������������������������������redis���������7021���sentinel���17021���cp /usr/local/src/redis-3.2.8/redis.conf /etc/redis/redis_7021.conf cp /usr/local/src/redis-3.2.8/sentinel.conf /etc/redis/sentinel_17021.conf ���������������������������������������������2������������������������������������������utils������������redis_init_script���������������/etc/init.d/���������������������redis���������������������������������������������������������������cp /usr/local/src/redis-3.2.8/utils/redis_init_script /etc/init.d/redis 3���������/etc/init.d/redis������������������������redis���������������������������������������������������������������������������������������������redis������������������

    redis_7021.conf���������

    #redis.conf# Redis configuration file example.# ./redis-server /path/to/redis.conf################################## INCLUDES ####################################������������������������������������������redis���������������������������������������������������# include /path/to/local.conf# include /path/to/other.conf################################ GENERAL ######################################������������������������yes������������������no������������������������������������������daemonize yes#3.2������������������������������������������������������������������������������������bind���������������������������������redis���������������������������������������������������������������������   ���bind���������������������   ���������������������������no���protected-mode yes#redis���������������pidfile "/var/run/redis/redis_7021.pid"#redis���������������������port 7021#������������������TCP������������������������(������������������������)������������ ���������������������������Linux���������������/proc/sys/net/core/somaxconn���������������511������Linux���������������������128���������������������������������������������������������������������������������������������������������������������������������������������128������������������������������������������������������������������������������������2048������������������/etc/sysctl.conf���������:net.core.somaxconn = 2048���������������������������sysctl -p���tcp-backlog 511#������ redis ��������������������� IP ���������������������������������������������������������������������bind 192.168.1.55#������unix socket������redis���������������������������unixsocket "/var/run/redis/redis_7021.sock"#������unix socket���������������������# unixsocketperm 700# ���������������������������������������timeout���������������������������������0���������������������������������������������������0���timeout 0#tcp keepalive���������������������������0������������������tcp���SO_KEEPALIVE������������keepalive���������������:���������������������������������������������������������������������������������������������������������������������Linux���������������������keepalive���redis������������������������ack���������������������������������������������������tcp-keepalive 0#���������������������������������������������������debug���������������������������������������������verbose���������������������������������������debug���������������������notice���������������������������������������������������warn���������������������������������loglevel notice#������������������������������������������������������������������������������������������������������������redis���������������/dev/null���logfile "/var/log/redis/redis_7021.log"#������������������syslog������# syslog-enabled no#syslog���������������# syslog-ident redis#������������������������# syslog-facility local0#������������������������������������������������DB 0������������������SELECT ���������������������dbdatabases 16################################ SNAPSHOTTING ################################# ������������# ������������save������������������������������������������������������������# ������sedis���������������������������������# 900������15������������������1���key������������������������������������--������������# 300������5������������������10���key������������������������������������--������������# 60������1������������������10000���key������������������������������������--������������#save 900 1#save 300 10#save 60 10000#���RDB������������������������������������������������������������������yes������������������������no������������������������������������������info������rdb_last_bgsave_status������RDB������������������������stop-writes-on-bgsave-error yes#������������rdb���������rdb������������������LZF���������������yes������������������������������cpu������������no������������������������������������������rdbcompression yes#������������rdb������������rdb������������������������������������rdb������������������������CRC64������������������������������������������������������������������rdb������������������������������10%���������������������������������������������������������������������������rdbchecksum no#rdb���������������dbfilename "dump.rdb"#������������������������������������������������������rdb���aof������������������������������dir "/var/lib/redis_7021"################################# REPLICATION ##################################���������������slave���������������master���# slaveof 
    #������master���������requirepass���������slave���������master������������master������������������masterauth������������������master���������������������������������master������������������masterauth "XYZ"#������������������������������������������������������������������������������������������1) ������slave-serve-stale-data���������yes(������������)���������������������������������������������2) ������slave-serve-stale-data���������no���������INFO���SLAVOF������������������������������������������������������SYNC with master in progress������slave-serve-stale-data yes#���������������������������������������������������yes���������������������NO������������������������������slave-read-only yes#������������socket���������������������������redis���������������������������disk���socket���������������slave������������������������slave������������������������������������������������master���������rdb������������2������������disk���������master���������������������������rdb������������������������������������������rdb���������������slave���socket���master������������������������������������rdb���������socket���������������slave���disk���������������������������rdb���������������������������slave������������������rdb���������socket������������������������slave���������������������������������������������������������������������socket���������repl-diskless-sync no#diskless���������������������������������������0������������������������������������������������slave������������������������������rdb������������������������������������������������������slave������������repl-diskless-sync-delay 5#slave���������������������������������������������ping��������������������������������� repl_ping_slave_period ������������������10������repl-ping-slave-period 5#���������������������������master���slave������������������������������master���������slave���������������������������repl-timeout������������slave������������������slave���������slave������������������master���������������������repl-timeout������������master���������������������������repl-timeout���������������������repl-ping-slave-period������������������������������������������������repl-timeout 60#������������������tcp���������tcp nodelay������������������yes������no������������no������������tcp nodelay���������master���������yes���������tcp nodelay������������������������������slave���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������yes���repl-disable-tcp-nodelay no#���������������������������������������������������������������������������������������������������������slave���������������������������������������master������������������������������������������������������������������������������������������slave���������������������������������������������������������������slave���������������������������������������������������������slave���������������������������������������slave���������������������������������������������������1m���repl-backlog-size 32mb#master������slave������������������������������������������������repl-backlog-ttl���������������������������������������������repl-backlog-ttl 3600#���master������������Sentinel���������slave������������������������master������������������������slave���������master���������������0���������������������������slave-priority 100#redis������������������master���������������������������������������min-slaves-to-write������������slave���������������N���mater������������������master������������������������������slave������������������������������������������������������������N���slave���������������������master���������������������������������������������������slave������������master���������������������������������������������0���������������������# min-slaves-to-write 3#������������min-slaves-max-lag������slave���������������������slave���# min-slaves-max-lag 10# ������1���������������������0���������������������# Setting one or the other to 0 disables the feature.# By default min-slaves-to-write is set to 0 (feature disabled) and# min-slaves-max-lag is set to 10.################################## SECURITY ####################################requirepass���������������������������AUTH���������������������������������������������������������redis���������������������������������������������������������������������������������������������������������������������������������������������������requirepass������������������������������redis������������������������������15w���������������������������������������������������������������������������������������������requirepass "XYZ"#���������������������������������������������������CONFIG������������������������������������������������������������������������������������������������������������������������# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52rename-command SHUTDOWN REDIS_SHUTDOWNrename-command FLUSHDB REDIS_FLUSHDBrename-command FLUSHALL REDIS_FLUSHALLrename-command KEYS REDIS_KEYS#rename-command CONFIG REDIS_CONFIG#rename-command SLAVEOF REDIS_SLAVEOF#���������������������������������������������������# rename-command CONFIG ""################################### LIMITS ##################################### ���������������redis������������������������������������������10000���������������������������redis������������������������������������������������������������������slave������������������maxclients���������������������32������������������maxclients���redis���������������������������max number of clients reached������������������������# maxclients 10000#redis������������������������������������������������������������maxmemory-policy���������������������������slave���������������������������������maxmemory������������������������������������������������������������������maxmemory���������������������maxmemory 512mb#������������������maxmemory���������������������#volatile-lru���������LRU������������������������������������key���#volatile-random���������������������������������������key���#volatile-ttl������������������������key���������������������������������������������TTL���#allkeys-lru���������LRU������������������key���#allkeys-random���������������������key���#noeviction������������������key���������������������������������#������������������������������������redis���������������key���������������������������������������������������redis������������������������������������get���������������������������set setnx setex append incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby getset mset msetnx exec sort���maxmemory-policy allkeys-lru#lru���������������������������lru������ttl������������������������������������������������������sample���key������������������������������key���������# maxmemory-samples 5############################## APPEND ONLY MODE ################################������redis������������rdb���������������������������������������������������������������������������redis������������������������������������������������������������������������save���������������������������Append Only File���������������������������������������������������������������������Redis������������������������������������������������ appendonly.aof ������������������������Redis������������������������������������������������������������RDB���������appendonly no#aof���������appendfilename "appendonly.aof"#aof������������������������#no���������������fsync���������������������������������������������������������������#always���������������������������fsync������������������������������������#everysec������������������������fsync���������������������������1s���������appendfsync everysec# ���aof������������������rdb���������������������������������IO���������������everysec���always���aof���������������������fsync������������������������������no-appendfsync-on-rewrite������������������������������no���������������������������������������������������������������������yes������������������������no���������������������������������������������������������������������yes������rewrite������������������������fsync,���������������������,���rewrite������������������������������no���������yes���Linux���������fsync���������30������������������30������������no-appendfsync-on-rewrite yes#aof������������������������������aof������������������������������������aof���������������������������������������������������aof������������������������������������Redis������������bgrewriteaof������������������������������������AOF���������������������������������������AOF���������������������������������100������������������������������������������������auto-aof-rewrite-percentage 100#���������������������������aof���������������������������������������������������������������������������������������auto-aof-rewrite-min-size 64mb#aof������������������������������������������redis������������������aof������������������������������������������������������redis������������������������������������������������ext4������������������������data=ordered���������redis���������������������������������������������������������������������������������������������������redis���������������������������������������������������������������yes���������������aof������������������������������������������������log������������������load������������no���������������������redis-check-aof������AOF������������������aof-load-truncated yes################################ LUA SCRIPTING ################################ ���������������������������������������������redis���������log���������������error������������������������������������������������SCRIPT KILL���SHUTDOWN NOSAVE���������������������������������������write���������������������������������������write���������������������������������lua-time-limit 5000################################ REDIS CLUSTER ################################������������������������������������������������#cluster-enabled yes#���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Redis������������������������Redis���������������������������������������������������������������������������������������������������������������#cluster-config-file nodes-7021.conf#���������������������������������������������������������#cluster-node-timeout 30000#���������������������������������������slave���������������������master���������������slave���������master������������������������������������������������������������������slave���������������������master������������������������������slave���������master������������������������������������������������#������slave������������������������(node-timeout * slave-validity-factor) + repl-ping-slave-period#������������������������������������, ������slave-validity-factor���10,���������������repl-ping-slave-period���10���������������������310���slave���������������������������������#������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������#������������������������������������������������������������������������������������������������������#cluster-slave-validity-factor 10#master���slave���������������������slave���������������������������master���������������������������������2���������������������������������������2 ���������������������������������������������������������������������#���������������������������������������������������������������������������������������������������������������������# cluster-migration-barrier 1#���������������������������������slot������������������������������������ok���������������������������������no������������slot������������������������������������������������������������������������������������������������������������������master������������������������������������������������������������������#���������key���������������������������������������������������������yes���(���������), ���������������������������������������������������������������no������������������������������������������key���������������#cluster-require-full-coverage yes################################## SLOW LOG ######################################slog log���������������redis������������������������������������������������������������������������������������������������slow log������slog log���������������������������������IO���������#���������������slowlog-log-slower-than���������������������slowlog���������������������������������1000000������1���������������������������������������������������������0���������������������������������slowlog-log-slower-than 10000#��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� SLOWLOG RESET ������������������slowlog-max-len 128################################ LATENCY MONITOR ###############################���������������������������������redis������������������������������������������LATENCY������redis������������������������������������������������������������������������������������������0������������������������������������������������������������������������������������������������������������CONFIG SET���������������������latency-monitor-threshold 0############################# EVENT NOTIFICATION ###############################��������������������������������������������������������������������������������������������������������� Redis ������������������������������������������������������������������������ CPU ������������������������������������������������������������#notify-keyspace-events ������������������������������������������������������������������������������������������������������##K ��������������������������������� __keyspace@__ ���������##E ��������������������������������� __keyevent@__ ���������##g DEL ��� EXPIRE ��� RENAME ���������������������������������������##$ ������������������������##l ���������������������##s ���������������������##h ���������������������##z ���������������������������##x ���������������������������������������������������##e ������(evict)��������������������������� maxmemory ���������������������������##A ������ g$lshzxe ���������#������������������������������������ K ������ E��������������������������������������������������������������������� ������������������������������������������http://redis.io/topics/notificationsnotify-keyspace-events "e"############################### ADVANCED CONFIG ################################���������������������hash-max-ziplist-entries������ziplist���������hash-max-ziplist-entries���hashhash-max-ziplist-entries 512#value������������������hash-max-ziplist-value������ziplist���������hash-max-ziplist-value���hash���hash-max-ziplist-value 64#���������������������list-max-ziplist-entries���ziplist���������list-max-ziplist-entries���list���list-max-ziplist-entries 512#value������������������list-max-ziplist-value������ziplist���������list-max-ziplist-value���list���list-max-ziplist-value 64#���������������������set-max-intset-entries���iniset���������set-max-intset-entries���set���set-max-intset-entries 512#���������������������zset-max-ziplist-entries���ziplist���������zset-max-ziplist-entries���zset���zset-max-ziplist-entries 128#value������������������zset-max-ziplist-value���ziplist���������zset-max-ziplist-value���zset���zset-max-ziplist-value 64#value������������������hll-sparse-max-bytes���������������������������sparse������������hll-sparse-max-bytes������������������������������dense���������������16000������value������������������������������value���������3000������������CPU���������������������������������������������������������10000���������hll-sparse-max-bytes 3000#Redis���������100���������������1���������CPU������������redis���hash���������������hash���������������������������������������������������������������������������������������������������������������Redis������������������������2������������������������������������������no���������������������������������������������������������������yes���������������������������������������������activerehashing yes##���������������������������������������������������������������������������������������������������������������������������������������������������������#������normal client������������0������������hard limit������������0������������0������������soft limit���normal client���������������������������������������������������������������������������������client-output-buffer-limit normal 0 0 0#������slave client���MONITER client���������client-output-buffer������������256mb������������������64mb������60���������������������������������������������������������client-output-buffer-limit slave 256mb 64mb 60#������pubsub client���������client-output-buffer������������32mb������������������8mb������60���������������������������������������������������������client-output-buffer-limit pubsub 32mb 8mb 60#redis������������������������1s������hz���hz 10#���aof���������������������������������aof-rewrite-incremental-fsync���������������������32MB������������fsync���������������������������������������������������������������������������������������aof-rewrite-incremental-fsync yes
    View Code

    sentinel_17021.conf���������

    port 17021dir "/var/lib/sentinel_17021"logfile "/var/log/redis/sentinel_17021.log"daemonize yesprotected-mode nosentinel monitor configs 192.168.1.55 7021 2sentinel down-after-milliseconds configs 5000sentinel failover-timeout configs 120000#sentinel client-reconfig-script configs /opt/bin/notify.pyrename-command SHUTDOWN REDIS_SHUTDOWNsentinel auth-pass configs XYZ
    View Code

    /etc/init.d/redis���������

    #!/bin/sh## Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.REDISPORT=7021EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis/redis_${REDISPORT}.pidCONF="/etc/redis/redis_${REDISPORT}.conf"case "$1" in    start)        if [ -f $PIDFILE ]        then                echo "$PIDFILE exists, process is already running or crashed"        else                echo "Starting Redis server..."                su redis -c "$EXEC $CONF"        fi        ;;    stop)getchar() {  stty cbreak -echo  dd if=/dev/tty bs=1 count=1 2> /dev/null  stty -cbreak echo}printf "passwd: "while : ; do  ret=`getchar`  if [ x$ret = x ]; then    echo    break  fi  str="$str$ret"  printf "*"done#echo $str        if [ ! -f $PIDFILE ]        then                echo "$PIDFILE does not exist, process is not running"        else                PID=$(cat $PIDFILE)                echo "Stopping ..."                $CLIEXEC -a $str -h 192.168.1.55 -p $REDISPORT redis_shutdown                while [ -x /proc/${PID} ]                do                    echo "Waiting for Redis to shutdown ..."                    sleep 1                done                echo "Redis stopped"        fi        ;;    *)        echo "Please use start or stop as first argument"        ;;esac
    View Code

    ���������������������������������������������������������

    mkdir /var/run/redis/mkdir /var/log/redis/mkdir /var/lib/redis_7021mkdir /var/lib/sentinel_17021
    View Code

    ���������������1.55���������redis���sentinel������������������������������������������������������

  • ���������������������
    • ���������������root���������������������������redis���������������������������������root���������������������������������������������������������������������������������������������������������������������������������������
      1���������������������useradd redis2������������������������������������������������chown -R redis.redis /var/lib/redis_7021/chown -R redis.redis /var/lib/sentinel_17021chown -R redis.redis /var/log/redis/chown -R redis.redis /var/run/redis/chown -R redis.redis /etc/redis/
    • ���������������������������
    • 1���redis ���������������root@redis1:~# /etc/init.d/redis startStarting Redis server...root@redis1:~# /etc/init.d/redis stoppasswd: *********************Stopping ...Redis stopped2���sentinel ���������������root@redis1:~# su redis -c "redis-sentinel /etc/redis/sentinel_17021.conf"root@redis2:~# redis-cli -h 192.168.1.55 -p 17021192.168.1.55:17021>REDIS_SHUTDOWN3���������ps������������������������������������redis���������������
    • ���������sentinel���������������������������������������������������redis������������sentinel������������������������
      useradd sentinelchown -R sentinel.sentinel /var/lib/sentinel_17021 chown root.root /etc/redis/chown -R sentinel.sentinel /etc/redis/sentinel_17021.conf  chmod 664 /etc/redis/sentinel_17021.conf chgrp sentinel /var/log/redis/chmod 775 /var/log/redis/#������������������������������������2������#chown -R sentinel.sentinel /var/log/redis/sentinel_17021.log #chmod 664 /var/log/redis/sentinel_17021.log #���������������������������������������������chgrp sentinel /opt/bin/notify.py

      ������������������������������redis���������������sentine���������������

      su sentinel -c "redis-sentinel /etc/redis/sentinel_17021.conf"

      ������������������������������

  • ���������redis���sentinel������������������1.55���������������������������������������������1.56������������������������������������������������������������������1.57���������������������������sentinel���������redis_7021.conf������������������(IP)������������sentinel_17021���������������������������������������������������sentinel���������55���56������������������������������������������56���������slaveof������������������������������������3���sentinel���������������������������������������������������������������������������������������master���������debug sleep���������������������������������������sentinel���������������������������������

    debug sleep 30

    ������������������������������������������sentinel������������������������������������������������������������

 ���������

      ���������������������������redis������������������������������������������sentinel���������������������������������������������������������redis cluster������������������������������������������������������������

上一篇:Redis Cluster部署、管理和测试
下一篇:MySQL备份mydumper的原理【转】

发表评论

最新留言

很好
[***.229.124.182]2025年04月11日 07时02分22秒