在不同机器上使用Redis Replication(多主) [英] Using Redis Replication on different machines (multi master)

查看:46
本文介绍了在不同机器上使用Redis Replication(多主)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中使用 Redis 作为分布式缓存.需求之一是具有 Active Active 可用性,这意味着我在一个地方有一个数据中心,在其他地方有另一个数据中心.如果一个数据中心出现故障,我希望我的用户没有任何感觉,并且能够从第二个站点的第一个数据中心获得所有数据并继续工作 - 在第二个站点也有一个主数据中心.可能吗?

I want to use Redis as distributed cache in my application. One of the demands is to have Active Active availability meaning that I have one data center in one place and another one somewhere else. If one data center fails I want my user to feel nothing and to be able to have all the data from the first data center in the second site and continue working - to have a master on the second site as well. Is it possible?

推荐答案

您要的是 Active-Active,也就是多主解决方案,但您的问题表明您可能不需要它.

You're asking for an Active-Active, a.k.a. multi master, solution but your question suggests you may not need it.

如果您只需要一个数据库可用于写入,即所有写入始终进行,您可以使用 Redis 的标准主从复制来实现.指示您的应用程序使用 master 进行写入,并且(可能)让您的 slave 也提供一些读取服务.如果主节点出现故障,将第二个 DC 中的从节点提升为新的主节点,并重定向您的应用程序/客户端以使用它.Redis的Sentinel可以实现监控和推广.

If you only require one of the databases to be available for writes, i.e. all writes always go it, you can achieve that with Redis's standard master-slave replication. Direct your application to use the master for writes and (potentially) have your slave serve some of the reads as well. If the master fails, promote the slave in the 2ndary DC to be the new master and redirect your application/clients to use it. Monitoring and promoting can be achieved with Redis' Sentinel.

在实施此类设置时,您必须考虑一些事项.首先请注意,Redis 的复制是异步的,因此根据主服务器的负载、写入量和复制的网络链接质量,您可能会在发生故障转移时丢失一些最近的更新.其次,在同一主题上,DC 间网络链接可能容易受到带宽限制和延迟增加的影响 - 您应该配置 Redis 来处理这个问题,并可能对该流量使用压缩(例如,通过 SSH 隧道).最后,为了准确检测故障,您需要在不同位置至少设置 3 个 Sentinel.但尽管存在这些挑战,这一切都是可行的.

There are a few things you'll have to take into consideration when implementing this type of setup. First note that Redis' replication is asynchronous so depending on your master's load, the volume of writes and the replication's network link quality, you could loose some of the recent updates in case of a failover. Secondly and on the same topic, an inter-DC network link could be prone to limited bandwidth and increased latency - you should configure Redis to handle this and perhaps use compression for that traffic (e.g. via an SSH tunnel). Lastly, to accurately detect failures you'll want to have at least 3 Sentinels in different locations. But despite these challenges, that's all doable.

也就是说,Redis 目前不支持可以针对任何数据库任意执行写入的多主设置.如果这确实是您的需要,请考虑使用不同的解决方案.

That said, a multi master setup in which writes can be arbitrarily done against any database isn't supported by Redis at the moment. If that's actually what you need, consider using a different solution.

注意:根据您的具体要求,如果您可以保证对不同 DC 的写入是互斥的(即每个 DC 仅写入其他 DC 未共享的不同密钥子集),则可以使用两个数据库每个 DC 有一个主机,另一个 DC 有一个从机.

Note: depending on your exact requirements, if you can guarantee that writes to different DCs are mutually exclusive (i.e. each DC gets writes only to a distinct subset of keys that's not shared by the other DC), you can use two databases with a master in each DC and the slave in the other one.

这篇关于在不同机器上使用Redis Replication(多主)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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