search
HomeDatabaseRedisLet'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!

Let's talk about the master-slave replication architecture in Redis6 and see what its characteristics are!

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!

Statement
This article is reproduced at:掘金社区. If there is any infringement, please contact admin@php.cn delete
PHP实现MySQL数据库主从复制的方法PHP实现MySQL数据库主从复制的方法May 17, 2023 am 08:18 AM

随着互联网的飞速发展,Web应用程序越来越多地集成了数据库操作。MySQL作为一款世界知名的关系型数据库系统,使用广泛。在高并发的Web应用中,MySQL主从复制是一种提高数据库性能和可用性的重要方式。本文将介绍如何使用PHP实现MySQL数据库主从复制。一、什么是MySQL主从复制MySQL主从复制是指将一个MySQL数据库服务器的数据复制到另一个服务器上

构建高可用的MySQL集群:主从复制与负载均衡的最佳实践指南构建高可用的MySQL集群:主从复制与负载均衡的最佳实践指南Sep 09, 2023 am 10:57 AM

构建高可用的MySQL集群:主从复制与负载均衡的最佳实践指南近年来,随着互联网的快速发展,数据库已成为大部分Web应用的核心数据存储和处理引擎之一。在这个场景下,高可用性和负载均衡成为了数据库架构设计中的重要考虑因素。而MySQL作为最受欢迎的开源关系型数据库之一,其集群化部署方案备受关注。本文将介绍如何通过MySQL主从复制与负载均衡实现高可用的数据库集群

MySQL中的数据主从复制技术MySQL中的数据主从复制技术Jun 14, 2023 pm 02:10 PM

MySQL数据库是一种非常流行的关系型数据库管理系统,支持多种数据复制技术,其中较为常用的是主从复制技术。本文将介绍MySQL中的数据主从复制技术,包括原理、实现方法、常见问题及应对措施等方面。一、主从复制技术的原理MySQL中的主从复制技术可以将一个MySQL数据库的数据复制到其他服务器上,以实现数据备份、负载均衡、读写分离等功能。它的基本原理是将主数据库

Redis的主从复制功能详解Redis的主从复制功能详解May 11, 2023 am 10:00 AM

Redis是一个开源的基于内存的键值存储系统,常用于缓存、队列和实时数据处理等场景。在大规模应用时,为了提高Redis的可用性和性能,常常需要采用分布式架构,其中主从复制是一种常用的机制。本文将介绍Redis的主从复制功能,包括定义、原理、配置和应用场景等方面。一、定义Redis的主从复制是指将一个Redis节点(即主节点)的数据自动同步到其他节点(即从节点

如何配置MySQL数据库的主从复制?如何配置MySQL数据库的主从复制?Jul 13, 2023 pm 10:05 PM

如何配置MySQL数据库的主从复制?MySQL数据库的主从复制是一种常见的数据备份和高可用性解决方案。通过配置主从复制,可以实现将数据从一个MySQL服务器(主服务器)同步到另一个(从服务器),从而提高数据库的可用性和性能。下面将介绍如何在MySQL数据库中配置主从复制,并提供相应的代码示例。确保MySQL服务器安装并启动首先,确保你的系统中已经安装了MyS

MySQL中的主从复制和高可用架构MySQL中的主从复制和高可用架构Sep 09, 2023 pm 12:03 PM

MySQL中的主从复制和高可用架构随着互联网应用和数据量的不断增长,数据库的高可用性和可扩展性变得越来越重要。MySQL作为一种使用广泛的开源关系型数据库,提供了主从复制和高可用架构的解决方案。主从复制是指将一个MySQL数据库实例作为主库(master),并将其数据复制到一个或多个从库(slave)的过程。这种复制的方式可以实现数据的冗余备份以及读写分离,

集群模式下的负载均衡与灾备:MySQL主从复制的深度解析与实践集群模式下的负载均衡与灾备:MySQL主从复制的深度解析与实践Sep 11, 2023 pm 05:51 PM

集群模式下的负载均衡与灾备:MySQL主从复制的深度解析与实践随着互联网行业的迅猛发展,数据存储和处理的需求越来越高。在应对高并发访问和海量数据存储的情况下,集群模式成为了一种常见的解决方案。而负载均衡与灾备则是集群系统中的重要组成部分,其中MySQL主从复制更是一种被广泛应用的方式。本文将深入探讨集群模式下的负载均衡与灾备,重点分析MySQL主从复制的原理

实现数据冗余与扩展:MySQL主从复制技术在集群环境中的应用案例实现数据冗余与扩展:MySQL主从复制技术在集群环境中的应用案例Sep 08, 2023 pm 04:36 PM

实现数据冗余与扩展:MySQL主从复制技术在集群环境中的应用案例引言:随着互联网发展,数据量的不断增大和用户的不断增加,传统的单机数据库已经无法满足高并发、高可用性的需求。在这种背景下,分布式数据库成为了热门的解决方案之一。MySQL作为最常用的关系型数据库之一,其主从复制技术在分布式数据库中的应用也受到了广泛关注。本文将介绍MySQL主从复制技术在集群环境

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

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

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft