Redis 故障转移与来自 C# 的 StackExchange/Sentinel [英] Redis failover with StackExchange / Sentinel from C#

查看:64
本文介绍了Redis 故障转移与来自 C# 的 StackExchange/Sentinel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在使用 Redis 2.8.4 和 StackExchange.Redis(并且很喜欢它),但目前没有任何针对硬件故障等的保护.我正在尝试使解决方案起作用,我们有主/从和哨兵监控,但无法完全到达那里,并且在搜索后我无法找到任何真正的指针.

We're currently using Redis 2.8.4 and StackExchange.Redis (and loving it) but don't have any sort of protection against hardware failures etc at the moment. I'm trying to get the solution working whereby we have master/slaves and sentinel monitoring but can't quite get there and I'm unable to find any real pointers after searching.

所以目前我们已经走到了这一步:

So currently we have got this far:

我们在每个节点上有 3 个 redis 服务器和哨兵(由 Linux 人员设置):devredis01:6383(主)devredis02:6383(奴隶)devredis03:6383(奴隶)devredis01:26379(哨兵)devredis02:26379(哨兵)devredis03:26379(哨兵)

We have 3 redis servers and sentinel on each node (setup by the Linux guys): devredis01:6383 (master) devredis02:6383 (slave) devredis03:6383 (slave) devredis01:26379 (sentinel) devredis02:26379 (sentinel) devredis03:26379 (sentinel)

我能够将 StackExchange 客户端连接到 redis 服务器并使用 Redis 桌面管理器写入/读取并验证数据是否正在跨所有 redis 实例复制.

I am able to connect the StackExchange client to the redis servers and write/read and verify that the data is being replicated across all redis instances using Redis Desktop Manager.

我还可以使用不同的 ConnectionMultiplexer 连接到哨兵服务,查询配置,请求主 redis 节点,请求从节点等.

I can also connect to the sentinel services using a different ConnectionMultiplexer, query the config, ask for master redis node, ask for slaves etc.

我们还可以杀死主 redis 节点并验证其中一个从属被提升为主,并且复制到另一个从属继续工作.我们可以观察到尝试重新连接到 master 的 redis 连接,而且如果我重新创建 ConnectionMultiplexer,我可以再次向新提升的 master 写入/读取并从 slave 读取.

We can also kill the master redis node and verify that one of the slaves is promoted to master and replication to the other slave continues to work. We can observe the redis connection trying to reconnect to the master, and also if I recreate the ConnectionMultiplexer I can write/read again to the newly promoted master and read from the slave.

到目前为止一切顺利!

我缺少的一点是你如何将它们整合到一个生产系统中?

The bit I'm missing is how do you bring it all together in a production system?

我是否应该从哨兵获取 redis 端点并使用 2 个 ConnectionMultiplexers?我究竟需要做什么才能检测到节点已关闭?StackExchange 可以自动为我执行此操作还是传递事件以便我可以重新连接我的 redis ConnectionMultiplexer?我是否应该处理 ConnectionFailed 事件,然后重新连接以便 ConnectionMuliplexer 找出新的主节点是什么?据推测,当我重新连接时,任何写入尝试都会丢失?

Should I be getting the redis endpoints from sentinel and using 2 ConnectionMultiplexers? What exactly do I have to do to detect that a node has gone down? Can StackExchange do this for me automatically or does it pass an event so I can reconnect my redis ConnectionMultiplexer? Should I handle the ConnectionFailed event and then reconnect in order for the ConnectionMuliplexer to find out what the new master is? Presumably while I am reconnecting any attempts to write will be lost?

我希望我没有遗漏一些非常明显的东西,我只是在努力将它们整合在一起.

I hope I'm not missing something very obvious here I'm just struggling to put it all together.

提前致谢!

推荐答案

我刚刚问了这个问题,发现了一个与你和我类似的问题,我相信它回答了我们的代码(客户端)现在如何知道哪个问题当前主服务器宕机时是新的主服务器吗?

I just asked this question, and found a similar question to yours and mine which I believe answers the question of how does our code (the client) know now which is the new master server when the current master goes down?

如何分辨新 Redis 主节点使用 Sentinel 的客户端

显然,您只需要订阅和收听来自 Sentinels 的事件.有道理..我只是想有一种更精简的方式.

Apparently you just have to subscribe and listen to events from the Sentinels. Makes sense.. I just figured there was a more streamlined way.

我读了一些关于 Linux 版 Twemproxy 的文章,它充当代理,可能会为您执行此操作?但是我在 Windows 的 redis 上并试图找到一个 Windows 选项.如果这是被批准的方式,我们可能会转移到 Linux.

I read something about the Twemproxy for Linux which acts as a proxy and probably does this for you? But I was on redis for Windows and was trying to find a Windows option. We might just moved to Linux if that's the approved way it should be done.

这篇关于Redis 故障转移与来自 C# 的 StackExchange/Sentinel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆