Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article has participated in the “Digitalstar Project” and won a creative gift package to challenge the creative incentive money.

First, environmental preparation

The Redis primary and secondary Sentinel monitoring configurations are as follows:

  1. 3 Sentinel instances (odd number, select Leader)
  2. Redis service (one master two).

Server resources limited friends, you can use VMware to start the virtual machine to build the environment, on how to use VMware to install virtual machines, network configuration, cloning, single instance of Redis installation in my blog have nanny level tutorials, please help yourself.

List of resources:

The IP address The node role port
192.168.211.104 Redis Master/ Sentinel 6379/26379
192.168.211.105 Redis Slave/ Sentinel 6379/26379
192.168.211.106 Redis Slave/ Sentinel 6379/26379

Close the firewall: since we learn to use it by ourselves, we do not have the best strategy for special ports (special operation and maintenance in the company will do it at the same time), so we directly close the firewall of the server (all three need to be closed).

Service # Check the firewall status systemctl stop firewald. service # Stop the firewall (it will fail after restart) systemctl disable Firewalld. Service # Disable startup upon startupCopy the code

Effect map, not the friend can refer to \

Overall structure diagram \

Configure one master and two slave nodes

The primary Redis node is 192.168.211.104, so replicaof points to the Master IP +port in the Redis configuration file 192.168.211.105 and 192.168.211.106. Configuration files in the Redis installation directory: \

Edit the redis.conf configuration file:

vim redis.conf

Default comments in the redis.conf configuration file:

# replicaof

Cancel the deregistration and set it to Master IP + port:

Replicaof 192.168.211.104 6379

Three, sentry configuration

In the case of a single node, the installation directory of Redis has the sentinel.conf configuration file by default. Back up the file first.

cp sentinel.conf sentinel.conf.copy

Create logs and other related files:

CD /usr/local/soft/redis-6.2.4/mkdir logs mkdir RDBS mkdir sentinel-tmp # sentinel Working directory

The sentinel.conf configuration file was modified on the three machines as follows (the content is the same) :

**daemonize yes **

**

port 26379

**

**protected-mode no

* * * * dir “/ usr/local/soft/redis – 6.2.4 / sentinel – TMP”

** ** Sentinel Monitor Redis-Master 192.168.211.104 6379 2

**

**sentinel down-after-milliseconds redis-master 30000

**

**sentinel failover-timeout redis-master 180000

**

sentinel parallel-syncs redis-master 1

Detailed interpretation of the above configuration:

Configuration items role
daemonize Background startup, the same as Redis. Yes indicates background startup
port port26379
protected-mode Enable the extranet access protection mode. No indicates that the extranet access is disabled
dir Sentinel Working Catalogue
sentinel monitor Sentinel monitors the Redis master node
sentinel failover-timeout 1. The interval between two failover operations performed by the same sentinel for the same master. 2. The time it takes to cancel an ongoing failover until the slave is corrected to synchronize data to the correct master. 4. When performing failover, configure the maximum time that all Slaves point to the new master
sentinel parallel-syncs This configuration item specifies the maximum number of slaves that can synchronize the new master at the same time when a failover occurs. The smaller the number is, the longer it takes to complete the failover. However, if the number is larger, This means that the more slaves become unavailable due to Replication. Setting this value to 1 ensures that only one slave at a time is unable to process command requests.

4. Service startup

This completes the configuration of monitoring the Redis primary/secondary cluster and the three Sentinel instances. The next step is to start Redis and Sentinel

4.1 start the redis

Go to the SRC directory under the Redis installation directory:

CD/usr/local/soft/redis – 6.2.4 / SRC

Start the Redis service (you can also configure the alias to start the service, please see my Redis standalone instance installation tutorial) :

./redis-server .. /redis.conf

4.2 start the Sentinel

The startup directory is the same as the Redis startup directory. The Redis installation directory is the SRC directory. Method 1:

./redis-sentinel .. /sentinel.conf

Method 2:

./redis-server .. /sentinel.conf –sentinel

4.3 Checking Cluster Status

Go to the Redis client and check the cluster status through Info Replication:

info replication

Rcli is the alias I configured to boot. If you don’t understand, please refer to my blog post about single-node instance deployment or leave a message and I will reply as soon as possible. As shown in the picture above, we can see that the cluster is ok

Five, the test

To test whether Sentinel is valid or not, run shutdown on primary node 192.168.211.104 via Redis:

shutdown

At this point, our 192.168.211.105 slave node is elected as the new, master node, which proves that Sentinel deployment is successful:

Finally, restart the shutdown node 192.168.211.104 to check the Redis cluster again

We found that 192.168.211.104 became a new slave node after being restarted, and the master node was still 192.168.211.105.