Home > Database > Redis > body text

How to perform master-slave replication in redis

(*-*)浩
Release: 2019-11-21 13:27:23
Original
3167 people have browsed it

How to perform master-slave replication in redis

The process of redis master-slave replication synchronization implementation

1. The slave service sends a sync synchronization command to the master service to request full synchronization (Recommended learning: Redis Video Tutorial)

2. When the main service receives the sync synchronization command from the slave service, it will fork a child process to execute the bgsave command in the background (non-blocking) to save the snapshot. Generate an RDB file and send the

RDB file to the slave service

3. The slave service then loads the received RDB file into its own redis memory

4. Wait After the slave service completes loading the RDB, the master service sends all the write commands in the buffer to the slave service

5. The slave service loads all the write commands of the master service into the memory to achieve complete data synchronization

6. The next time the slave service needs to synchronize data, it only needs to send its own offset position (equivalent to the position of mysql binlog). Only the newly added data will be synchronized, and full synchronization is no longer required.

Master-slave synchronization through configuration files

1. Just configure the slave service configuration file

[root@localhost ~]# vim /app/redis/etc/redis.conf
…..
slaveof 192.168.1.9 6379  #添加属于某台主机的从 服务
…..
masterauth 123456  #从服务连接主服的密码
……
slave-read-only yes  #从服务只读,不可在命令行写入数据
……
Copy after login

2. Restart the slave The service is to realize the master-slave connection

[root@localhost ~]# redis-server /app/redis/etc/redis.conf
[root@localhost ~]# redis-cli
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> info replication
#Replication
role:slave
master_host:192.168.1.9
master_port:6379
master_link_status:up
……
……
Copy after login

The above is the detailed content of How to perform master-slave replication in redis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template