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

Sharing of master-slave instances of Redis switching between each other online

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

Share

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

Today, what the editor shares with you is an example of Redis switching between masters and slaves online. Many people don't know much about it. Today, in order to let you know more about Redis, I summarized the following contents for you. Let's look down together. I'm sure you'll get something.

For some reason, we may need to replace the redis master machine, we can stop the machine to replace it, but that may affect the user experience. This article briefly operates the non-stop migration.

System environment

CentOS 6.3 x64

Redis-server 2.6.16

Two machines S1\ S2

Operation steps

1. We start a redis instance on the new redis server, and the configuration is the same as that of master, except that slave-read-only no is modified and enabled in the configuration file.

So that slave can write, because "Since Redis 2.6 by default slaves are read-only."

2. Make the new redis slave:redis 127.0.0.1 SLAVEOF s1 6379

Then you can check the log on S2, there will be a lot of synchronization information, or you can use the info command to see the status.

3. After S2 completely synchronizes the data of S1, we modify the redis ip of the game app to the ip of S2.

4. Check whether the game is normal.

5. When there are no problems mentioned above, execute redis 127.0.0.1 redis 6379 > SLAVEOF NO ONE on S2

6. Offline S1

PS:

SLAVEOF host port

The SLAVEOF command is used to dynamically modify the behavior of the replication (replication) function while Redis is running.

By executing the SLAVEOF host port command, you can turn the current server into a slave server (slave server) to the specified server.

If the current server is already a slave to a master server (master server), executing SLAVEOF host port will cause the current server to stop synchronizing with the old primary server, discard the old dataset, and start synchronizing with the new primary server instead.

In addition, executing the command SLAVEOF NO ONE on a secondary server will cause the secondary server to turn off replication and switch back to the primary server from the secondary server, so that the original synchronized dataset will not be discarded.

Taking advantage of the feature that "SLAVEOF NO ONE will not discard the synchronized dataset", the secondary server can be used as the new master server when the primary server fails, thus achieving uninterrupted operation.

Available versions:

> = 1.0.0

Time complexity:

SLAVEOF host port, O (N), N is the amount of data to be synchronized.

SLAVEOF NO ONE, O (1).

Return value:

Always return OK.

The above is a brief introduction to the examples of Redis switching between masters and slaves online. Of course, the differences in the detailed use of the above have to be understood by everyone. If you want to know more, welcome to follow the industry information channel!

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