大网数据广告活动
服务器运维问答

Redis sentinel: force switch to another master

· 52CE 我爱测

Context: I have 3 redis nodes, and 3 sentinels. The failover works properly. When I'm taking the master down, another master is elected. Need: I need a way to test the behavior, to make sure everything works as expected. I wish I…

问题原文

原帖链接 · aspyct · CC BY-SA 4.0

Context:

I have 3 redis nodes, and 3 sentinels. The failover works properly. When I'm taking the master down, another master is elected.

Need:

I need a way to test the behavior, to make sure everything works as expected. I wish I could force the sentinels to select a specific redis node to be the master.

I guess I could do that by taking down the two nodes that should not be the master, but I wish I could just issue a command to one of the sentinels to solve my issue.

tl;dr:

Can I instruct my sentinels to select a specific redis node as master?

已采纳解答

原帖链接 · ETL · CC BY-SA 4.0

You can cause a hang on the two Redis-servers you don't want as master and I think (not tested) Sentinel will pick the remaining one. It may take two elections...

Simulating a hang on the Redis servers:

redis-cli DEBUG sleep 30

or

redis-cli DEBUG segfault

Then force a fail over:

SENTINEL failover

Perhaps a better approach is to use the priority option.

From https://redis.io/topics/sentinel

Slaves priority

Redis instances have a configuration parameter called slave-priority. This information is exposed by Redis slave instances in their INFO output, and Sentinel uses it in order to pick a slave among the ones that can be used in order to failover a master:

If the slave priority is set to 0, the slave is never promoted to master. Slaves with a lower priority number are preferred by Sentinel.

For example if there is a slave S1 in the same data center of the current master, and another slave S2 in another data center, it is possible to set S1 with a priority of 10 and S2 with a priority of 100, so that if the master fails and both S1 and S2 are available, S1 will be preferred.

For more information about the way slaves are selected, please check the slave selection and priority section of this documentation.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-02-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。