Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Sentinel mechanism in Redis

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to use the Sentinel mechanism in Redis. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1. Overview

Redis-Sentinel is a high availability (HA) solution officially recommended by Redis. When Redis is used as a high-availability solution for Master-slave, if master goes down, Redis itself (including many of its clients) does not automatically switch between master and slave, and Redis-sentinel itself is also an independent process, which can monitor multiple master-slave clusters and switch itself when master is down.

Its main functions are as follows:

Monitor from time to time whether redis is running well as expected.

If a redis node is found to be in trouble, you can notify another process (such as its client)

Can switch automatically. When a master node is unavailable, one of the multiple slave of the master (if there is more than one slave) can be elected as the new master, and the other slave nodes will change the address of the master it follows to the new address of the slave promoted to the master.

2. Sentinel supports clusters

Obviously, it is unreliable to use only a single sentinel process to monitor the redis cluster. When the sentinel process is down (sentinel itself has a single point of problem, single-point-of-failure), the entire cluster system will not run as expected. So it is necessary to cluster sentinel, which has several benefits:

Even if some sentinel processes are down, the active / standby switch of the redis cluster can still be carried out.

If there is only one sentinel process, if the process runs wrong, or the network is blocked, then the active / standby switching of the redis cluster will not be possible (single point problem)

If you have multiple sentinel,redis clients, you can freely connect to any sentinel to get information about the redis cluster.

3. Sentinel version

The current stable version of Sentinel is called Sentinel 2 (distinguished from the previous Sentinel 1). Released with the redis2.8 installation package. After installing Redis2.8, you can find the startup program for Redis-sentinel in redis2.8/src/.

Strong recommendation: 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 a lot of Bug, has been officially abandoned, so it is strongly recommended to use redis2.8 and sentinel 2.

4. Run Sentinel

There are two ways to run sentinel:

First kind

Redis-sentinel / path/to/sentinel.conf

The second kind

Redis-server / path/to/sentinel.conf-- sentinel

In both of the above ways, you must specify a configuration file sentinel.conf for sentinel. If you do not specify it, you will not be able to start sentinel. Sentinel listens on port 26379 by default, so you must make sure that the port is not occupied by another process before running.

5. Configuration of Sentinel

The Redis source package contains a sentinel.conf file as a configuration file for sentinel, which comes with an explanation of 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 item is configured with two master named mymaster and resque respectively. The configuration file only needs to configure master information, not slave information, because slave can be automatically detected (the master node will have a message about slave). It should be noted that the configuration file will be dynamically modified during the sentinel operation. For example, when the master / slave switch occurs, the master in the configuration file will be modified to another slave. In this way, if sentinel restarts later, it can restore the status of its previously monitored redis cluster according to this configuration.

Next, we will explain the above configuration items one by one:

Sentinel monitor mymaster 127.0.0.1 6379 2

The name of the master that this line represents sentinel monitoring is mymaster, and the address is 127.0.0.1 mymaster 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 because of network congestion. When sentinel is clustered, the solution to this problem becomes very simple. It only requires multiple sentinel to communicate with each other to confirm whether a master is really dead. This 2 means that when two sentinel in the cluster think that master is dead, they can really think that the master is no longer available. (the sentinel in the sentinel cluster also communicates with each other through the gossip protocol.)

This is the end of the article on "how to use the Sentinel mechanism in Redis". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report