


Let's talk about the master-slave replication architecture in Redis6 and see what its characteristics are!
This article will take you to understand the master-slave replication architecture in Redis6, and introduce the characteristics of Redis6 master-slave replication. I hope it will be helpful to everyone!
Introduction to master-slave replication
Master-slave replication refers to copying data from one Redis server to another Redis server. The former is the master node, and the latter becomes the slave node; data replication is one-way, and can only be from the master node to the slave node. By default, each Redis server is a master node, and a master node can have multiple slave nodes (or no slave nodes), but a slave node can only have one master node. [Related recommendations: Redis Video Tutorial]
The benefits of using master-slave replication: reading and writing are separated, which can expand the reading capacity of the master node and share the pressure on the master node. For disaster recovery, once the master node goes down, the slave node can be used as the backup of the master node and can be installed at any time.
Architecture Introduction
The slave node copies the data of the master node. After copying, we can do a read-write separation. If it is a single node, application requests are concentrated on the master node, but with the slave node, it can bear part of the read pressure. The master node can perform read and write operations, while the slave node can only perform read operations. This will share the pressure on the master node.
Redis master-slave replication, one master and two slaves architecture environment preparation
After talking about so many concepts, let’s start deploying the master-slave of Redis Let’s copy the architecture. This time we deploy a one-master-two-slave architecture.
#创建文件 mkdir -p /data/redis/master/data mkdir -p /data/redis/slave1/data mkdir -p /data/redis/slave2/data #从节点开启只读模式(默认) replica-read-only yes #从节点访问主节点的密码,和requirepass⼀样 masterauth 123456 #哪个主节点进⾏复制 replicaof 8.129.113.233 6379
First create a master node, touch a redis.conf file in the data/redis/master/data directory, edit the redis.conf file
bind 0.0.0.0 port 6379 daemonize yes requirepass "123456" logfile "/usr/local/redis/log/redis1.log" dbfilename "xdclass1.rdb" dir "/usr/local/redis/data" appendonly yes appendfilename "appendonly1.aof" masterauth "123456"
Then create slave node 1, in data Build redis.conf
bind 0.0.0.0 port 6380 daemonize yes requirepass "123456" logfile "/usr/local/redis/log/redis2.log" dbfilename "xdclass2.rdb" dir "/usr/local/redis/data" appendonly yes appendfilename "appendonly2.aof" replicaof 8.129.113.233 6379 masterauth "123456"
in the /redis/slave1/data directory. Create slave node 2 and build redis.conf
bind 0.0.0.0 port 6381 daemonize yes requirepass "123456" logfile "/usr/local/redis/log/redis3.log" dbfilename "xdclass3.rdb" dir "/usr/local/redis/data" appendonly yes appendfilename "appendonly3.aof" replicaof 8.129.113.233 6379 masterauth "123456"
in the data/redis/slave2/data directory. Note: Remember to turn off the firewall. , Alibaba Cloud Server remembers to open the network security group.
After creation, start the configured node
Startup method:
#启动主 ./redis-server/data/redis/master/data/redis.conf #启动从1 ./redis-server/data/redis/slave1/data/redis.conf #启动从2 ./redis-server/data/redis/slave2/data/redis.conf
Use info replication to view the status of the current node
Master-slave Replication and read-write verification
1.在主节点创建一个key set name jack 2.在两个从节点测试是否能拿到主节点的数据 get name 3.在从节点set key是失败的,因为从节点只支持读操作
Redis6 master-slave architecture-analysis of replication read-write separation principle
Master-slave replication is divided into two types: one One is to perform full synchronization when the master and slave first connect; the other is to perform incremental synchronization after full synchronization is completed.
Full copy: The master server will start a background process to generate an rdb file from Redis data. The master server will cache all received write commands from the client. When the process is saved in the background, it will The rdb file is passed to the slave server. At this time, the slave server has the data of the master server. After this, the master server will send the cached commands during this period to the slave server through the redis transmission protocol, and then the slave server will use these commands on its own local in turn, eventually achieving data consistency
Incremental replication: The master node will continue to write commands. When the slave completes initialization and starts working, the process of the master server sending write operations to synchronize them to the server is called incremental replication. Incremental replication means that every time the server executes a write command, it sends the same write command to the slave server, and the slave server accepts and executes the received write command.
What are the characteristics of master-slave replication:
Master-slave replication is non-blocking for the master/slave server, and all data is synchronized During this period, external requests can be processed normally. A master node can contain multiple slave nodes, and each slave node can accept connections from other slave nodes. The slave node will not let the key expire. Instead, after the key of the master node expires and is deleted, it will send a delete command to the slave node to delete it.
Accelerated replication: When the node completes resynchronization, you need to create an RDB file on the disk, and then load this file to send data from the server, but what if the disk speed is relatively low? This will cause data inconsistency between the master node and the slave node. In the new version of Redis, disk-less replication is supported, and RBD files are directly sent to the slave server through the network, without using disks as middleware.
If the master-slave connection is disconnected, replication can be continued from the interrupted point after reconnection without resynchronization. After version 2.8, this new feature of resynchronization uses the PSYNC command, while the old one uses the SYNC command
For more programming-related knowledge, please visit:Programming Video! !
The above is the detailed content of Let's talk about the master-slave replication architecture in Redis6 and see what its characteristics are!. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the rapid development of the Internet, Web applications are increasingly integrating database operations. MySQL is a world-renowned relational database system that is widely used. In highly concurrent web applications, MySQL master-slave replication is an important way to improve database performance and availability. This article will introduce how to use PHP to implement master-slave replication of MySQL database. 1. What is MySQL master-slave replication? MySQL master-slave replication refers to copying data from one MySQL database server to another server.

Building a Highly Available MySQL Cluster: Best Practice Guide for Master-Slave Replication and Load Balancing In recent years, with the rapid development of the Internet, the database has become one of the core data storage and processing engines for most web applications. In this scenario, high availability and load balancing have become important considerations in database architecture design. As one of the most popular open source relational databases, MySQL's cluster deployment solution has attracted much attention. This article will introduce how to implement a highly available database cluster through MySQL master-slave replication and load balancing.

MySQL database is a very popular relational database management system that supports a variety of data replication technologies, among which the more commonly used is master-slave replication technology. This article will introduce the data master-slave replication technology in MySQL, including principles, implementation methods, common problems and countermeasures. 1. Principle of master-slave replication technology The master-slave replication technology in MySQL can copy the data of a MySQL database to other servers to achieve data backup, load balancing, read-write separation and other functions. Its basic principle is to convert the main database

Redis is an open source memory-based key-value storage system that is commonly used in scenarios such as caching, queuing, and real-time data processing. In large-scale applications, in order to improve the availability and performance of Redis, it is often necessary to adopt a distributed architecture, in which master-slave replication is a commonly used mechanism. This article will introduce the master-slave replication function of Redis, including definition, principle, configuration and application scenarios. 1. Definition of Redis master-slave replication refers to automatically synchronizing the data of one Redis node (i.e. master node) to other nodes (i.e. slave node).

How to configure master-slave replication of MySQL database? Master-slave replication of MySQL database is a common data backup and high availability solution. By configuring master-slave replication, you can synchronize data from one MySQL server (master server) to another (slave server), thereby improving database availability and performance. The following describes how to configure master-slave replication in a MySQL database and provides corresponding code examples. Make sure the MySQL server is installed and started. First, make sure MySQL is installed on your system.

Master-slave replication and high-availability architecture in MySQL As Internet applications and data volumes continue to grow, the high availability and scalability of the database are becoming more and more important. As a widely used open source relational database, MySQL provides master-slave replication and high-availability architecture solutions. Master-slave replication refers to the process of using a MySQL database instance as the master database and replicating its data to one or more slave databases (slave). This replication method can achieve redundant backup of data and separation of reading and writing.

Memcached is an open source, high-performance distributed memory object caching system that can be used to speed up web applications and performs particularly well in large-scale data caching. For this system, master-slave replication is a very important function, which can be used to ensure data reliability and high availability. This article will introduce how to use PHP to implement master-slave replication of Memcached database. Introduction to the master-slave mode The master-slave mode is a distributed structure of the Memcached server. It consists of at least two servers: one

Load balancing and disaster recovery in cluster mode: in-depth analysis and practice of MySQL master-slave replication. With the rapid development of the Internet industry, the demand for data storage and processing is getting higher and higher. In response to high concurrent access and massive data storage, cluster mode has become a common solution. Load balancing and disaster recovery are important components of the cluster system, and MySQL master-slave replication is a widely used method. This article will delve into load balancing and disaster recovery in cluster mode, focusing on the principle of MySQL master-slave replication.
