Redis 哨兵与集群 [英] Redis sentinel vs clustering

查看:31
本文介绍了Redis 哨兵与集群的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解redis sentinel是在多个redis实例之间配置HA(高可用)的一种方式.如我所见,在任何给定时间,都有一个 redis 实例主动为客户端请求提供服务.还有两台额外的服务器处于待机状态(等待故障发生,因此其中一台可以再次运行).

  • 是否浪费资源?
  • 是否有更好的方法来充分利用可用资源?
  • Redis 集群是否可以替代 Redis 哨兵?

我已经查找了 和 https://github.com/xetorthio/jedis/issues/725谈论 JedisSentinelPool 是使用池的途径.

当 Sentinel 执行故障转移时,客户端将断开连接,Jedis 将(应该?)通过询问 Sentinel 当前的主人是谁来处理重新连接.

I understand redis sentinel is a way of configuring HA (high availability) among multiple redis instances. As I see, there is one redis instance actively serving the client requests at any given time. There are two additional servers are on standby (waiting for a failure to happen, so one of them can be in action again).

  • Is it waste of resources?
  • Is there a better way of using full use of the resources available?
  • Is Redis clustering an alternative to Redis sentinel?

I already looked up redis documentation for sentinel and clustering, can somebody having experience explain please.

UPDATE

OK. In my real deployment scenario I have two servers dedicated for redis. I have another server my Jboss server is running. The application running in Jboss is configured to connect to redis master server(M).

Failover scenario

Ideally, I think when Master cache server fails (either Redis process goes down or machine failure) the application in Jboss needs to connect to Slave cache server. How would I configure the redis servers to achieve this?

+--------+          +--------+
| Master  |---------| Slave  |
|         |         |        |
+--------+          +--------+

Configuration: quorum = 1

解决方案

First, lets talk sentinel.

Sentinel manages the failover, it doesn't configure Redis for HA. It is an important distinction. Second, the diagram you posted is actually a bad setup - you don't want to run Sentinel on the same node as the Redis nodes it is managing. When you lose that host you lose both.

As to "Is it waste of resources?" it depends on your use case. You don't need three Redis nodes in that setup, you only need two. Three increases your redundancy, but is not required. If you need the added redundancy then it isn't a waste of resources. If you don't need redundancy then you just run a single Redis instance and call it good - as running more would be "wasted".

Another reason for running two slaves would be to split reads. Again, if you need it then it wouldn't be a waste.

As to "Is there a better way of using full use of the resources available?" we can't answer that as it is far too dependent on your specific scenario and code. That said if the amount of data to store is "small" and the command rate is not exceedingly high, then remember you don't need to dedicate a host to Redis.

Now for "Is Redis clustering an alternative to Redis sentinel?". It really depends entirely on your use case. Redis Cluster is not an HA solution - it is a multiple writer/larger-than-ram solution. If your goal is just HA then it likely won't be suitable for you. Redis Cluster comes with limitations, particularly around multi-key operations, so it isn't necessarily a straightforward "just use cluster" operation.

If you think having three hosts running Redis (and three running sentinel) is wasteful, you'll likely hold Cluster to be even more so as it does require more resources.

The questions you've asked are probably too broad and opinion-based to survive as written. If you have a specific case/problem you are working out please update with that so we can provide specific assistance and information.

Update for specifics:

For proper failover management in your scenario I would go with 3 sentinels, one running on your JBoss server. If you have 3 JBoss nodes then go with one on each. I'd have a Redis pod (master+slave) on separate nodes, and let sentinel manage the failover.

From there it is a matter of wiring up JBoss/Jedis to use Sentinel for it's information and connection management. As I don't use those a quick search turns up that Jedis has the support for it, you just need to configure it correctly. Some examples I found are at Looking for an example of Jedis with Sentinel and https://github.com/xetorthio/jedis/issues/725 which talk about JedisSentinelPool being the route for using a pool.

When Sentinel executes a failover the clients will be disconnected and Jedis will (should?) handle the reconnection by asking the Sentinels who the current master is.

这篇关于Redis 哨兵与集群的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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