Before demonstrating the redis sentinel, first prepare a set of master-slave (the production environment is that the sentinel and the master-slave will not be on the same machine, here for the demonstration, they are all deployed on one machine)
Prepare a master-slave environment
We use port 7000 as the master node, and 7001 and 7002 as the slave nodes
master configuration
slave configuration (same as 7002)
start three nodes
Look at the master-slave relationship
Build redis sentinel
1. Copy sentinel.conf in the redis installation directory to the newly created config directory
cp sentinel.conf ./config/
2. Go to the config directory, filter to the empty lines and comments of the configuration file and redirect the file redis-sentinel-26379.conf
cat sentinel.conf | grep -v "#" | grep -v "^$" > redis-sentinel-26379.conf
3. Look at the configuration file
port is the port number, sentinel defaults to 26379
dir is the working directory
In sentinel monitor, mymaster represents the name of the monitoring master node, followed by the ip port and a 2, which means that at least a few sentinels think that there is a problem with the master (failure discovery) and will start the next step (failover)
Sentinel down-after-milliseconds represents a time threshold for judging faults. The default is 30,000 milliseconds (here can be imagined as going to PING non-stop, if there is no response for 30 seconds, it is considered a fault, and failover is performed)
Sentinel parallel-syncs means that when the slave synchronizes with the new master, it can perform at most several times at the same time. The default is 1, which can reduce the pressure on the master.
failover-timeout is the time to failover
4. Edit the sentinel configuration in the config directory, and add the daemon process startup, working directory, log file name, and port number of the listening master
vim redis-sentinel-26379.conf
5. Edit the config of the two sentinels as above, change the port and log file to 26380, and start them up (note that the startup command here uses redis-sentinel)
6. Next, connect a sentinel with redis-cli and enter the info command to observe
You can see that under the sentinel node, it is found that the master is on port 7000, and there are 2 slaves, a total of 3 sentinels (proving that sentinels can perceive each other). You can also see that the configuration file of sentinel has changed
Found 2 slaves and 2 other sentinels.