search
HomeDatabaseRedisRedis explains master-slave replication and sentry mode

Redis explains master-slave replication and sentry mode

Jan 26, 2021 am 09:45 AM
redismaster-slave replication

Redis explains master-slave replication and sentry mode

Recommendation (free): redis

##Article Directory

    Master-slave replication
    • Command
    • Configuration
  • Copy principle
    • Full copy
    • Incremental copy
    • Test
  • Nested master-slave
  • Sentinel mode
    • Configuration Sentinel
    • Test
##Master-slave replication


Master-slave replication

refers to copying the data of one Redis server to other Redis servers. The former is called the master node Master, and the latter is called the slave node Slave. It can only be copied one-way from the Master to Slave, generally Master mainly performs writing operations, and Slave mainly performs reading operations, achieving separation of reading and writing.

Function

Data redundancy: Master-slave replication realizes hot backup of data, which is a kind of data redundancy besides persistence. Way.
  1. Failure recovery: When a problem occurs on the master node, the slave node can provide services to achieve rapid failure recovery; it is actually a kind of service redundancy.
  2. Load balancing: Based on master-slave replication, combined with read-write separation, the master node can provide write services and the slave nodes can provide read services (that is, when writing Redis data, the application connects to the master node and reads Redis data When the application connects to the slave node), the server load is shared; especially in scenarios where there is less writing and more reading, sharing the read load through multiple slave nodes can greatly increase the concurrency of the Redis server.
  3. Cornerstone of high availability: In addition to the above functions, master-slave replication is also the basis for the implementation of sentinels and clusters. Therefore, master-slave replication is the basis of Redis high availability.
Command

##CommandFunctionslaveof host port will cause the slave server to turn off the replication function and transition from the slave server back to the master server. The original synchronized data set will not be discarded. info [, you can make the command return only a certain part of the information:

Configuration

Take a single machine with multiple services as an example (normally multiple machines with multiple services, but I only have one server)

First of all, each redis client The default is the host, which can be viewed through the info replication command.
Redis explains master-slave replication and sentry mode

Then we now need to open three clients at the same time to simulate one master and two slaves, so we need to modify the configuration:

  1. Modify the port number
  2. Modify pid name
  3. Modify log name
  4. Modify rdb name
  5. Set host connection (optional, use command line)

First Copy two configuration files as the slave configuration, and the master can use the default.
Redis explains master-slave replication and sentry mode
Take redis80.conf as an example to modify the above five configuration points in sequence. For 81, only the first four points are modified.
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode## Then start them (79, 80, 81)

Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode Set master and slave:

    80 is set in the configuration file (permanent), view it directly:

  1. Redis explains master-slave replication and sentry mode##81 If there is no configuration, you can manually set the command line

  2. Redis explains master-slave replication and sentry mode
  3. View 79 (master) at this time:


Redis explains master-slave replication and sentry mode

Copy principle


Full copy

Every time the slave connects to the host, it will copy in full, copying all the data from the host to the slave.

Incremental copy

After the slave machine is connected to the master machine, the data updated later by the master machine will be synchronously updated to the slave machine only for this part of the data.

Test

The slave is read-only by default and will incrementally copy the data of the synchronization host:

  1. Redis explains master-slave replication and sentry mode
    Redis explains master-slave replication and sentry mode
    Redis explains master-slave replication and sentry mode Host downtime:

  2. Redis explains master-slave replication and sentry mode
    Redis explains master-slave replication and sentry mode
    Redis explains master-slave replication and sentry mode
    Redis explains master-slave replication and sentry mode# 3 .Slave machine downtime:
    Redis explains master-slave replication and sentry mode

    Redis explains master-slave replication and sentry mode
    Redis explains master-slave replication and sentry mode
    Redis explains master-slave replication and sentry mode
    Redis explains master-slave replication and sentry mode
    Redis explains master-slave replication and sentry mode#embedded Set master and slave

As shown in the figure 79 is the host of 80, and 80 is the host of 81. This is a nested master-slave relationship.
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode

Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode

#Sentinel Mode


The above 80 upper position and nested master-slave are all entered by us on the command line manually.

The purpose is to avoid write operations after the host is down. During the window period, these require manual intervention.
Sentinel will run independently as an independent process. The principle is that Sentinel monitors multiple running Redis servers by sending commands and waiting for the Redis server to respond. If Sentinel detects that the host is offline, it will select a slave machine to "upper" (automatic fault migration) to become the new host. If the original host comes online, the original host will become the slave of the new host. The principle is to notify other servers through the publish and subscribe model, modify the configuration file, and thereby switch hosts.

Redis explains master-slave replication and sentry mode What if Sentinel goes down? Multiple sentinels can be used to monitor each other.

Redis explains master-slave replication and sentry mode
The picture is taken from https://www.jianshu.com/p/06ab9daf921d, intrusion and deletion

  • Subjective offline(Subjectively Down, SDOWN for short) refers to the offline judgment made by a single sentinel instance on the server.
  • Objective Down(Objectively Down, referred to as ODOWN) refers to multiple sentinel instances making subjective offline judgments on the same server, and through SENTINEL is-master-down- After the by-addr commands communicate with each other, the server is offline judged.
When the host objectively goes offline, Sentinel will vote for a new host (

The specific algorithm is omitted), perform automatic failover (failover), and notify other servers to switch through publish and subscribe. host.

Configuring Sentinel

First, there is a detailed annotated sentinel configuration in the installation directory:


Redis explains master-slave replication and sentry mode Create a new sentinel.conf to monitor 6379, The rest can be defaulted:

Redis explains master-slave replication and sentry mode Start Sentinel:

Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode

##Test

Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode
Redis explains master-slave replication and sentry mode# Multi-sentinel mode, Configure configuration files for different ports to open multiple Sentinel clients, and then follow the same pattern (
lazyRedis explains master-slave replication and sentry mode )

Transform the current server into a slave server of the specified server. If it is already a slave, it stops synchronizing the old master server, discards the old data set, and starts synchronizing the new master server. SLAVEOF NO ONE
section]The INFO command returns information about the Redis server in a format that is easy to understand and read. various information and statistical values. By giving the optional parameter section

The above is the detailed content of Redis explains master-slave replication and sentry mode. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
Redis: The Advantages of a NoSQL ApproachRedis: The Advantages of a NoSQL ApproachApr 27, 2025 am 12:09 AM

Redis is a NoSQL database that provides high performance and flexibility. 1) Store data through key-value pairs, suitable for processing large-scale data and high concurrency. 2) Memory storage and single-threaded models ensure fast read and write and atomicity. 3) Use RDB and AOF mechanisms to persist data, supporting high availability and scale-out.

Redis: Understanding Its Architecture and PurposeRedis: Understanding Its Architecture and PurposeApr 26, 2025 am 12:11 AM

Redis is a memory data structure storage system, mainly used as a database, cache and message broker. Its core features include single-threaded model, I/O multiplexing, persistence mechanism, replication and clustering functions. Redis is commonly used in practical applications for caching, session storage, and message queues. It can significantly improve its performance by selecting the right data structure, using pipelines and transactions, and monitoring and tuning.

Redis vs. SQL Databases: Key DifferencesRedis vs. SQL Databases: Key DifferencesApr 25, 2025 am 12:02 AM

The main difference between Redis and SQL databases is that Redis is an in-memory database, suitable for high performance and flexibility requirements; SQL database is a relational database, suitable for complex queries and data consistency requirements. Specifically, 1) Redis provides high-speed data access and caching services, supports multiple data types, suitable for caching and real-time data processing; 2) SQL database manages data through a table structure, supports complex queries and transaction processing, and is suitable for scenarios such as e-commerce and financial systems that require data consistency.

Redis: How It Acts as a Data Store and ServiceRedis: How It Acts as a Data Store and ServiceApr 24, 2025 am 12:08 AM

Redisactsasbothadatastoreandaservice.1)Asadatastore,itusesin-memorystorageforfastoperations,supportingvariousdatastructureslikekey-valuepairsandsortedsets.2)Asaservice,itprovidesfunctionalitieslikepub/submessagingandLuascriptingforcomplexoperationsan

Redis vs. Other Databases: A Comparative AnalysisRedis vs. Other Databases: A Comparative AnalysisApr 23, 2025 am 12:16 AM

Compared with other databases, Redis has the following unique advantages: 1) extremely fast speed, and read and write operations are usually at the microsecond level; 2) supports rich data structures and operations; 3) flexible usage scenarios such as caches, counters and publish subscriptions. When choosing Redis or other databases, it depends on the specific needs and scenarios. Redis performs well in high-performance and low-latency applications.

Redis's Role: Exploring the Data Storage and Management CapabilitiesRedis's Role: Exploring the Data Storage and Management CapabilitiesApr 22, 2025 am 12:10 AM

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: Understanding NoSQL ConceptsRedis: Understanding NoSQL ConceptsApr 21, 2025 am 12:04 AM

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.

Redis: Real-World Use Cases and ExamplesRedis: Real-World Use Cases and ExamplesApr 20, 2025 am 12:06 AM

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.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

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),

MinGW - Minimalist GNU for Windows

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.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function