Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of the principle of Redis Master-Slave synchronization (experiment)

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

redis master-slave synchronization principle

During the synchronization process,

The master creates the RDB file only on the first synchronization and uses it as a base for synchronization.

All subsequent synchronizations are performed by incremental command transfer (AOF).

Environment Description:

master: 192.168.2.100 Do not open RDB and AOF

slave: 192.168.2.200 Open RDB and AOF

Configuration information:

master:

# vim etc/redis.conf

#save 600 5 //disable RDB

appendonly no //disable AOF

requirepass 123456 //Specify authentication password

slave:

# vim etc/redis.conf

save 600 5 //disable RDB

appendonly yes //disable AOF

appendfilename "appendonly.aof" //Specify an AOF file

appendfsync everysec //Force writes to disk once per second

no-appendfsync-on-rewrite no //command appends are not performed during log rewriting

auto-aof-rewrite-percentage 100 //overwrite when current AOF exceeds previous AOF size by 100%

auto-aof-rewrite-min-size 64mb //log rewrite minimum

slaveof 192.168.2.100 6379 //Specify main library IP and port

masterauth 123456 //Specify the login password for the master library

Start redis:

master:# redis-server etc/redis.conf

slave:# redis-server etc/redis.conf

Observe synchronization:

master:

# redis-cli -a 123456

127.0.0.1: 6379> info replication //Check whether the master-slave relationship is correct

127.0.0.1: 6379> keys * //At this time, there is no RDB file in the master installation directory.

(empty list or set)

127.0.0.1:6379> set name zhagnsan //create key

OK

# ll /usr/local/redis-3.0.6-6379 //generate an RDB file to use as a basis for synchronization with slave

-rw-r--r-- 1 root root 35 May 20 21:59 dump_6379.rdb

slave:

# redis-cli

127.0.0.1: 6379> info replication //Check whether the master-slave relationship is correct

127.0.0.1: 6379> keys * //data synchronized

1) "name"

127.0.0.1:6379> get name

"zhagnsan"

# ll /usr/local/redis-3.0.6-6379 //directory to generate RDB files and AOF files

-rw-r--r-- 1 root root 60 May 20 21:59 appendonly.aof

-rw-r--r-- 1 root root 18 May 20 21:58 dump.rdb

master:

# redis-cli -a 123456

127.0.0.1:6379> set age 26 //add 2 keys

OK

127.0.0.1:6379> set home beijing

OK

# ll /usr/local/redis-3.0.6-6379 //RDB file size unchanged

-rw-r--r-- 1 root root 35 May 20 21:59 dump_6379.rdb

slave:

# redis-cli

127.0.0.1: 6379> keys * //data synchronized

1) "age"

2) "name"

3) "home"

# ll /usr/local/redis-3.0.6-6379 //Discovery: RDB file size unchanged, only AOF changed

-rw-r--r-- 1 root root 126 May 20 22:00 appendonly.aof

-rw-r--r-- 1 root root 18 May 20 21:58 dump.rdb

Summary: During data synchronization, master creates RDB files only on the first synchronization,

All subsequent synchronizations are synchronized by incremental transmission commands.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report