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

Example Analysis of Master-Slave replication and Sentinel Mode in Redis

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

Share

Shulou(Shulou.com)05/31 Report--

This article shares with you the content of sample analysis of master-slave replication and Sentinel mode in Redis. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Master-slave replication refers to copying the data from one Redis server to another Redis server. The former is called master node Master, and the latter is called slave node Slave, which can only be copied from Master to Slave one-way. Generally, Master is dominated by write operation and Slave is dominated by read operation to achieve read-write separation.

Action

Data redundancy: master-slave replication realizes the hot backup of data, which is a way of data redundancy in addition to persistence.

Fault recovery: when there is a problem with the master node, the service can be provided by the slave node to achieve rapid fault recovery; in fact, it is a kind of service redundancy.

Load balancing: on the basis of master-slave replication, combined with read-write separation, the master node can provide write services, and the slave node can provide read services (that is, the slave node is connected to the master node when writing Redis data and the slave node is connected when reading Redis data) to share the server load. Especially in the scenario of writing less and reading more, the concurrency of the Redis server can be greatly increased by sharing the read load among multiple slave nodes.

High availability cornerstone: in addition to the above functions, master-slave replication is the basis on which sentinels and clusters can be implemented, so master-slave replication is the basis of high availability for Redis.

Command

The command acts as slaveof host port to transform the current server into a slave server to the specified server. If it is already slave, stop synchronizing with the old primary server, discard the old dataset, and start synchronizing the new primary server instead. SLAVEOF NO ONE will cause the secondary server to turn off the replication function and switch from the secondary server to the primary server, so that the original synchronized dataset will not be discarded. The info [section] INFO command returns various information and statistical values about the Redis server in a format that is easy to understand and read. Given the optional parameter section, you can have the command return only a portion of the information:

Configuration

Take stand-alone multi-service as an example (normally it is multi-server, but I only have one server)

First of all, each redis client is the host by default, which can be viewed through the info replication command.

So now we need to open three clients at the same time to simulate one master and two slaves, so we need to modify the configuration:

Modify port number

Modify pid name

Modify log name

Modify rdb name

Set up the host connection (optional, use the command line)

First copy two configuration files as slave configuration, the host can use the default.

Take redis80.conf as an example, modify the above five-point configuration in turn, 81 only change the first four points.

Then start them (79, 80, 81)

Set the master and slave:

80 is set in the configuration file (permanent). Check it directly:

81 there is no configuration, you can set it manually on the command line

Check out 79 (master) at this point:

Principle of replication

As shown in figure 79, 80 is the host of 80, and 80 is the host of 81, which is a nesting master-slave relationship.

Sentinel mode

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