Sentinel plus VIP drift to achieve high availability of Redis cluster

note

aims

  • Build a three-node Redis service cluster to meet the requirements of high availability
    • Unified IP: Three-node cluster exposes a unified IP address
    • High availability: the master node is down, and the slave node needs to quickly assume the master node
    • Read and write separation: the master node allows reading and writing, and the slave node is read only
    • Quick join: After the down node restarts, join the cluster and become the cluster slave node

The main steps

  • Install three redis
  • Modify the redis.conf file
  • Modify sentinel.conf file
  • First start redis one by one, if there is a problem, see if you can find the answer here: some pits in the middleware installation process
  • Restart sentinel
  • Configure VIP script and initialize

Pro test can use script

  • redis.conf
protected-mode yes
port 6379
daemonize yes
bind 0.0.0.0
 
pidfile "/var/run/redis_6379.pid"
logfile "/etc/redis/redis.log"
 
dir "/etc/redis"
dbfilename "dump.rdb"
replica-read-only yes
 
requirepass "Sxxxxx4"
masterauth "Sxxxxxx4"
  • sentinel.conf
port 26379
daemonize yes
protected-mode no
 
pidfile "/var/run/redis-sentinel.pid"
logfile "/etc/redis/sentinel.log"
dir "/tmp"
 
sentinel myid e09252859aced76c83958ef6686b739da9b2035f
sentinel deny-scripts-reconfig yes

sentinel monitor mymaster01 1xx.xx.xx.4 6379 2
sentinel down-after-milliseconds mymaster01 5000#尽可能小,才能很快看出效果
sentinel failover-timeout mymaster01 10000 #尽可能小,才能很快看出效果
sentinel auth-pass mymaster01 Spdb@1234

sentinel client-reconfig-script mymaster01 /etc/redis/transip.sh
  • VIP drift script
#!/bin/bash
MASTER_IP=$6
LOCAL_IP='1x x x12'
VIP='1xxxx2'
NETMASK='24'
INTERFACE='eth0'

if [ ${MASTER_IP}=${LOCAL_IP} ]; then
    /sbin/ip  addr  add  ${VIP}/${NETMASK} dev ${INTERFACE}
    /sbin/arping    -q -c 3 -A ${VIP}  -I ${INTERFACE}
    exit 0
else
    /sbin/ip  addr  del  ${VIP}/${NETMASK} dev ${INTERFACE}
    exit 0
fi
exit 1

Guess you like

Origin blog.csdn.net/ljfirst/article/details/107965120