What is the method for configuring Redis Sentinel?
To set up Redis Sentinel, you need to follow these steps:
- On the Redis master server, modify the redis.conf file to set the sentinel monitor command to define the primary server being monitored by the sentinel. For example:
- Monitor the sentinel named mymaster, located at 127.0.0.1 on port 6379 with a quorum of 2.
- The mymaster here refers to the name of the master server, 127.0.0.1 is the IP address of the master server, 6379 is the port number of the master server, and 2 indicates that at least 2 sentinels must agree before a failover is triggered in case the master server is deemed unavailable.
- Create a sentinel.conf file on the Redis Sentinel server and configure it as follows:
- use port number 26379, monitor the master server at IP address 127.0.0.1 on port 6379 with a quorum of 2.
- The port number 26379 here is for the sentinel server, “mymaster” is the name of the main server to monitor, the IP address of the main server is 127.0.0.1, the port number of the main server is 6379, and the number 2 specifies that at least 2 sentinels must agree before a failover is initiated when the main server is deemed unavailable.
- Start the Redis Sentinel server using the following command:
- /path/to/sentinel.conf for redis-sentinel
- Set up additional Redis Sentinel servers and repeat steps 2 and 3.
- Configure the client connection to connect to the Redis Sentinel server instead of directly connecting to the master server, allowing the client to obtain the master server’s address through the Sentinel.
Once the configuration is complete, the Redis Sentinel will automatically monitor the master server and handle failovers. If the Sentinel detects that the master server is unavailable, it will select a suitable slave server to promote as the new master and inform the other Sentinels and clients to update.