This article will take you to understand the Sentinel mechanism in Redis and introduce two ways to run sentinel. I hope it will be helpful to you!
Redis-Sentinel is the official recommended high availability (HA) solution for Redis Solution, when using Redis as a high-availability solution for Master-slave, if the master goes down, Redis itself (including many of its clients) does not implement automatic master-slave switching, and Redis-sentinel itself is also an independent operation. process, it can monitor multiple master-slave clusters and perform self-understanding switching after discovering that the master is down. [Related recommendations: Redis Video Tutorial]
Its main functions are as follows:
Obviously, using only a single sentinel process to monitor the redis cluster is unreliable. After the sentinel process crashes (sentinel itself also has a single-point-of-failure), the entire cluster system will not be able to operate as expected. Therefore, it is necessary to cluster sentinel, which has several advantages:
The current latest stable version of Sentinel is called Sentinel 2 (to distinguish it from the previous Sentinel 1 ). Released together with the redis2.8 installation package. After installing Redis2.8, you can find the Redis-sentinel startup program in redis2.8/src/.
Strongly recommended: If you are using redis2.6 (sentinel version is sentinel 1), you'd better use redis2.8 version of sentinel 2, because sentinel 1 has many bugs. It is officially deprecated, so it is strongly recommended to use redis2.8 and sentinel 2.
There are two ways to run Sentinel:
redis-sentinel /path/to/sentinel.conf
redis-server /path/to/sentinel.conf --sentinel
Both of the above two methods must specify a sentinel configuration file sentinel.conf. If not specified, Sentinel will not start. Sentinel listens to port 26379 by default, so you must make sure that the port is not occupied by other processes before running it.
The Redis source package contains a sentinel.conf file as the sentinel configuration file. Configuration The file comes with explanations about each configuration item. Typical configuration items are as follows:
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 60000 sentinel failover -timeout mymaster 180000 sentinel parallel-syncs mymaster 1 sentinel monitor resque 192.168.1.3 6380 4 sentinel down-after-milliseconds resque 10000 sentinel failover-timeout resque 180000 sentinel parallel-syncs resque 5
The above configuration The item configures two masters named mymaster and resque. The configuration file only needs to configure the master information. There is no need to configure the slave information, because the slave can be automatically detected (the master node will have messages about the slave). It should be noted that the configuration file will be dynamically modified while sentinel is running. For example, when a master-slave switchover occurs, the master in the configuration file will be modified to another slave. In this way, if sentinel is restarted later, it can restore the status of the redis cluster it previously monitored based on this configuration.
Next we will explain the above configuration items line by line:
sentinel monitor mymaster 127.0.0.1 6379 2
This line represents that the name of the master monitored by sentinel is mymaster, and the address is 127.0.0.1:6379. What does the last 2 at the end of the line mean? We know that the network is unreliable. Sometimes a sentinel will mistakenly think that a master redis is dead due to network congestion. When the sentinel is clustered, the solution to this problem becomes very simple. It only requires multiple sentinels to communicate with each other. Communicate to confirm whether a master is really dead. This 2 means that when there are two sentinels in the cluster that think the master is dead, the master can truly be considered unavailable. (Each sentinel in the sentinel cluster also communicates with each other through the gossip protocol).
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of Let's talk about the Sentinel mechanism in Redis and introduce its usage!. For more information, please follow other related articles on the PHP Chinese website!