Setup HA Redis using Redis Sentinel part 2


Sentinel are really badass creatures. Whether are they Marvel Sentinel or The Matrix Sentinel, they did a good job to protect their evil masters until the saviour do them in.

In the second part of the high availability set up, I will show how to set up redis sentinel

Step 1: Do Step 2 to step 5 in the part 1 post

Step 2: Copy src/redis-sentinel to /usr/local/sbin

Step 3: Copy sentinel.conf to /etc/redis-sentinel.conf

Step 4: Edit /etc/redis-sentinel.conf. search for sentinel monitor and replace to the master sentinel internal IP.

Do take note that the last number on sentinel monitor is 2. What it means is it needs at least 2 sentinels to confirm that the master redis is down before they switch it to slave. You can set that between 1-3

Step 5: add the following lines to the end of the redis-sentinel.conf. Save the file

daemonize yes
logfile "/var/log/sentinel.log"

Step 6: Create /etc/init.d/redis-sentinel file and paste the following in:

# chkconfig: 2345 95 20
# description: Simple Redis init.d script conceived to work on Linux systems
# processname: redis



case "$1" in
        if [ -f $PIDFILE ]
                echo "$PIDFILE exists, process is already running or crashed"
                echo "Starting Redis Sentinel server..."
                $EXEC $CONF
        if [ ! -f $PIDFILE ]
                echo "$PIDFILE does not exist, process is not running"
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                    echo "Waiting for Redis Sentinel to shutdown ..."
                    sleep 1
                echo "Redis Sentinel stopped"
        echo "Please use start or stop as first argument"

Step 7: Set up redis-sentinel proper

chmod +x /etc/init.d/redis-sentinel
chkconfig --add redis-sentinel
chkconfig --level 3 redis-sentinel on

Step 8: repeat all these steps for the remaining 2 sentinel

Step 9: run /etc/init.d/redis-sentinel for all

So your redis sentinel is ready for use! Do take note that it operates slightly different from normal standalone redis. You need to take the master value from sentinel. Sentinel will give you the IP from which to use which redis.

Happy developing!


One thought on “Setup HA Redis using Redis Sentinel part 2

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s