14

I'm evaluating the cluster capabilities of Redis 3 (I'm using Redis 2 standalone at the moment), so I am reading the info at http://redis.io/topics/cluster-tutorial.

In this document I read a very important info:

Note that the minimal cluster that works as expected requires to contain at least three master nodes. For your first tests it is strongly suggested to start a six nodes cluster with three masters and three slaves.

Is it really true? In my mind this is correct if I would use sharding capabilities (data are shared between nodes), but what if I don't need it and I would be happy of having data on only one node?

I basically need one master and two slaves (so the cluster would be live if one node fails), can I have this configuration in a production environment? If yes, what are the contraindications?

Thank you very much for your help!

Mat
  • 1,783
  • 4
  • 22
  • 39

4 Answers4

7

Is it really true?

No. It's not really true. It's a strong recommendation (as you can tell from the "that works as expected" language; if you don't expect your data to be durable, and you expect it to disappear, etc. - you can set up a single node cluster. Why you would instead of just turning cluster mode off... that's up to you.)

So, yes, you can set up a single-node cluster, even though it isn't advised (for all the reasons mentioned in other answers and the documentation.) There is nothing in the redis cluster code that will stop you, other than a check in the redis-trib.rb helper that's there to dissuade naive users.

To get around that check, and set up a single node cluster (if you're sure that is what you want - remember, it almost certainly isn't), you can either manually assign the shards to your node with CLUSTER ADDSLOTS 1 2 3 ... (etc, for all 16384 shards). Or use the Python version of redis-trib which doesn't have the 3-node safety check (redis-trib.py create 127.0.0.1:6379).

  • though manually ADDSLOTS, still not possible to set a k/v pair. cluster info: state fail, The cluster is down. – sgohl Apr 23 '19 at 11:05
  • 1
    Since Redis does not work with Docker (requires nethost), it is impossible to provide a redis cluster to developers on their workstations. – sgohl Apr 23 '19 at 11:07
6

Is it really true?

Yes, that's why it is in the documentation :)

In my mind this is correct if I would use sharding capabilities (data are shared between nodes), but what if I don't need it and I would be happy of having data on only one node?

Using Redis in cluster mode means sharding. If you're happy with a single instance, simply don't use the cluster. Otherwise, refer to the cluster specification itself to understand more about the underlying assumptions. Specifically, in the case of minimal cluster configuration, you'll want 3 masters to ensure the cluster's availability in case of a partition, or else you won't be able to agree on majority.

Itamar Haber
  • 884
  • 8
  • 8
  • Thanks! But I need fault tolerance on three nodes. Will I need replication instead of cluster? And shall I use Sentinel to manage failover? – Mat Nov 19 '16 at 09:40
  • Replication can be used both in cluster as well as in single instance modes - it is commonly used for providing high availability. The cluster has fail over built in, but for a single instance you'd need Sentinel or another solution. – Itamar Haber Nov 19 '16 at 10:02
  • 1
    Thanks! So one master single instance and two slaves replicated from the master. And Sentinel will manage the HA. What other solution are you referring to? – Mat Nov 19 '16 at 10:29
5

I know that this question is old, but if someone needs a similar setup can use Master-Slaves configuration instead Cluster. You need:

  • 2 Redis server at least
  • 3 Redis Sentinel to monit the health and avoid Split-Brain
  • A way to check who's the master (I use HAProxy on client server with some check commands)

If you can made it smart enough, you can just write to master and read from all the nodes. I use this setup on some Wordpress sites but the plugin is not made to detect who's the master, so I just use HAProxy to detect the master and send all trafic to that node. If master node dies, an Slave node takes the master role (redis-sentinel manage that). HAProxy detects that master has changed and then change the node that receive all the traffic.

Sorry for don't post code and examples, but now I can't to do it.

Greetings!!

4

If you rely on Redis to fail over, you need a minimal of three master nodes and three slave nodes (a minimal of 3 servers, each running a master and a slave).

If you use external cluster software, for example heartbeat, you can setup two nodes, one being master and one being slave in cluster mode, allocate all 16384 slots to the master, and use failover scripts to "CLUSTER FAILOVER TAKEOVER" when the master is DOWN. Of course you may also setup a service IP to failover together with redis. This additional arrangement allows you to use non-cluster redis client as well.

Production run for one year and fail over a few times (machine reboot for kernel update) and so far no problem reported from operation team.

Ken Cheung
  • 156
  • 1