Introduction to the


Sentinel can be used to monitor the status of REDis cluster. When the primary redis database is unavailable, Sentinel can select a new primary database through election to achieve a high availability state in which the redIS cluster automatically switches to the primary database.

Obtain sentinel configuration information


wget http://download.redis.io/redis-stable/sentinel.conf
Copy the code

The Redis cluster starts


The main library start


#Sh docker_restart.sh < library name > < Port >
sh docker_restart.sh redis-master 6300
#Into the container
docker exec -it redis-master bash
#Connect the redis
redis-cli -a lindj -p 6300
#Set the master library password
config set masterauth lindj
Copy the code

Start from library 1


#Sh docker_restart.sh < library name > < Port >
sh docker_restart.sh redis-slave1 6301
#Into the container
docker exec -it redis-slave1 bash
#Connect the redis
redis-cli -a lindj -p 6301
#Connect the main librarySlaveof 192.68.1.92 6300#Set the master library password
config set masterauth lindj
Copy the code

In the same way, start slave library 2 redis-slave2 by following the startup process of slave library 1

For specific cluster building, please refer to Docker-based Redis cluster building

Sentinel configuration


#Lindj-master: user-defined cluster name
#"Master - redis - > IP: IP main library
#< master - redis - port > : the main library of the port
#
      
       : minimum number of votes, which can be set to 2 since there are three Redis-Sentinel instances
      Sentinel Monitor LinDJ-Master 192.168.1.92 6300 2
#Redis Cluster password
sentinel auth-pass lindj-master lindj

#Add background run
daemonize yes
Copy the code

Start the sentinel


Sh docker_restart.sh <sentinel name >#Into the container
docker exec -it sentinel-master bash
#Load the configuration
redis-sentinel /usr/local/etc/redis/sentinel.conf
Copy the code

Docker_start. sh File content

#! /bin/shapplication_name=$1 echo "application=${application_name}" echo "container is stoping and removing" containerId=$(docker  ps -a | grep -E "${application_name}" | awk '{print $1}') if [ !  -z $containerId ] then docker stop $containerId && docker rm $containerId fi echo "container is running" docker run -it  --name ${application_name} \ -v /data/redis/sentinel/${application_name}.conf:/usr/local/etc/redis/sentinel.conf \ -d redis /bin/bashCopy the code

Follow this step to start the other Sentinel nodes

test


#Enter the main container
docker exec -it redis-master bash
#Main container sleep
redis-cli -a lindj -p 6300 DEBUG sleep 60
Copy the code

Go to the secondary container and execute Info Replication. You can see that the master has completed the switchover

After 60 seconds, the original master Redis is restored and you can see that it has been switched to the secondary library

Pay attention to the public every day harvest technical dry goods

reference

Construction of Redis High Availability Cluster Based on Docker (RedIS-Sentinel)