Sentinel objective:Monitor the master and slave servers and automatically perform failover when the master server goes offline
Start Sentinel
Run the redis-Sentinel Program in the redis Installation File to start an sentinel instance:
redis-sentinel sentinel.conf
Because redis Sentinel is actually a redis server running in Sentinel mode, we can also use the following command to start a sentinel instance
redis-server sentinel.conf --sentinel
When starting Sentinel, you must specify the configuration file, which records the master server to be monitored and related configuration parameters.
Use sentinel to monitor the master-slave server and its slave server
Each sentinel instance can monitor any number of Master servers and all slave servers under the monitored master server.
Sentinel Network
Multiple sentinel instances can monitor the same master server. These sentinel instances that monitor the same master server are automatically connected to each other to form a distributed sentinel network, communicate with each other and exchange information about the monitored server.
Server offline judgment
When an sentinel considers that the monitored server has been deprecated, it will confirm with other sentinel in the network to determine whether the server has actually been deprecated;
If the server is deprecated as the master server, the Sentinel network will automatically failover the master server. By upgrading a slave server of the master server to a new server, and switch other slave servers to a new master server, so that the system can go online again.
Automatic failover
Deprecate the master server and re-launch it
Sentinel Configuration
Monitoring configuration options
When starting Sentinel, you must specify the corresponding configuration file:
redis-sentinel sentinel.conf
A sentinel configuration file must contain at least one monitoring configuration option. You must specify the information of the monitored master server.
sentinel monitor <name> <ip> <port> <quorum>
Name: The name set by the user for the monitored master server;
IP: IP address of the master server to be monitored;
Port: the port of the monitored master server;
Quorum: Minimum number of sentinel required to confirm that the master server has been deprecated;
Example: Configure sentinel monitor hadoop000 127.0.0.1 6379 2
Indicates that the name of the master server to be monitored is hadoop000, its IP address is 127.0.0.1, and the port number is 6379. To confirm that the server is offline, at least two sentinels must agree;
Sentinel can automatically discover and monitor all slave servers under the master server. Therefore, you only need to provide the address and port number of the master server..
Port Configuration Options
If you want to run multiple sentinel instances on the same machine, you also need to use the port number option to set different port numbers for each sentinel instance. If you do not set the port number, the default port number of Sentinel is 26379;
Example:
To run two sentinel instances on the same machine, you can load the following two configuration files to set the port numbers of the two sentinel instances to 26379 and 26380 respectively:
# sentinel1.confport 26379sentinel monitor …# sentinel2.confport 26380sentinel monitor …
Sentinel configuration instance
Run the following two commands to create two sentinel instances that monitor the master server S1:
$ redis-sentinel sentinel1.conf$ redis-sentinel sentinel2.conf
The content of sentinel1.conf is:
port 26379sentinel monitor s1 127.0.0.1 6379 2
The content of sentinel2.conf is:
port 26380sentinel monitor s1 127.0.0.1 6379 2
Redis multi-host function-Sentinel