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

Detailed explanation of Redis master-slave replication

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Problems existing in stand-alone Redis

Unable to fail over, unable to avoid single point of failure

Disk space bottleneck

QPS bottleneck

The role of Redis master-slave replication

Provide a copy of the data

Extended read performance

Configuration method

By command

Through the configuration file

Demo

For demonstration purposes, set up a redis master and slave on a server (not in production), distinguished by port.

Main library 6379

From library 6380

Edit configuration file

Vi redis-6379.conf

# background process starts daemonize yes # port port 637 log file name logfile "6379.log" # Redis working directory dir / server/redis_data#RDB file name dbfilename dump-6379.rdb

Vi redis-6380.conf

Daemonize yesport 6380logfile "6380.log" dir / server/redis_data# master library ip and port slaveof 10.238.162.34 637slave read-only slave-read-only yes

Start the redis service

Redis-server / usr/local/redis/config/redis-6379.confredis-server / usr/local/redis/config/redis-6380.conf

View replication status

Main library [root@localhost config] # redis-cli-p 6379 info replication# Replicationrole:masterconnected_slaves:1slave0:ip=10.238.162.34,port=6380,state=online,offset=1525 Lag=0master_repl_offset:1525repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:2repl_backlog_histlen:1524 slave library [root@localhost config] # redis-cli-p 6380 info replication# Replicationrole:slavemaster_host:10.238.162.34master_port:6379master_link_status:upmaster_last_io_seconds_ago:4master_sync_in_progress:0slave_repl_offset:1595slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl _ backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0

View the log to observe the replication process

Main library

Slave library

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.

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