Let's talk about the Sentinel mechanism in Redis and introduce its usage!
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!
1. Overview
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:
- Monitor whether redis follows the It is expected to run well;
- If it is found that a certain redis node is running abnormally, it can notify another process (such as its client);
- It can automatically switch. When a master node is unavailable, one of the master's multiple slaves (if there is more than one slave) can be elected as the new master. The other slave nodes will change the address of the master they follow to be promoted to The new address of the master's slave.
2. Sentinel supports cluster
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:
- Even if some sentinel processes are down, the active and backup switching of the redis cluster can still be performed;
- If there is only one Sentinel process, if this process runs incorrectly, or the network is blocked, then the active/standby switch of the redis cluster will not be possible (single point problem);
- If there are multiple sentinels, the redis client can connect at will Any sentinel to obtain information about the redis cluster.
3. Sentinel Version
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.
4. Running Sentinel
There are two ways to run Sentinel:
First type
redis-sentinel /path/to/sentinel.conf
Second type
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.
5. Sentinel configuration
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!

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

Redis is a NoSQL database suitable for efficient storage and access of large-scale data. 1.Redis is an open source memory data structure storage system that supports multiple data structures. 2. It provides extremely fast read and write speeds, suitable for caching, session management, etc. 3.Redis supports persistence and ensures data security through RDB and AOF. 4. Usage examples include basic key-value pair operations and advanced collection deduplication functions. 5. Common errors include connection problems, data type mismatch and memory overflow, so you need to pay attention to debugging. 6. Performance optimization suggestions include selecting the appropriate data structure and setting up memory elimination strategies.

The applications of Redis in the real world include: 1. As a cache system, accelerate database query, 2. To store the session data of web applications, 3. To implement real-time rankings, 4. To simplify message delivery as a message queue. Redis's versatility and high performance make it shine in these scenarios.

Redis stands out because of its high speed, versatility and rich data structure. 1) Redis supports data structures such as strings, lists, collections, hashs and ordered collections. 2) It stores data through memory and supports RDB and AOF persistence. 3) Starting from Redis 6.0, multi-threaded I/O operations have been introduced, which has improved performance in high concurrency scenarios.

RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis improves application performance and scalability by caching data, implementing distributed locking and data persistence. 1) Cache data: Use Redis to cache frequently accessed data to improve data access speed. 2) Distributed lock: Use Redis to implement distributed locks to ensure the security of operation in a distributed environment. 3) Data persistence: Ensure data security through RDB and AOF mechanisms to prevent data loss.

Redis's data model and structure include five main types: 1. String: used to store text or binary data, and supports atomic operations. 2. List: Ordered elements collection, suitable for queues and stacks. 3. Set: Unordered unique elements set, supporting set operation. 4. Ordered Set (SortedSet): A unique set of elements with scores, suitable for rankings. 5. Hash table (Hash): a collection of key-value pairs, suitable for storing objects.

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.