Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis cluster creation [closed]

Tags:

redis

Is it possible to create a redis cluster with 2 nodes , one acting as a master and other one as slave.

I get the following error if I try with 2 nodes (one as master and other as slave)

>>> Creating cluster
Connecting to node 127.0.0.1:6379: OK
Connecting to node 192.168.40.159:6379: OK
*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least 3 master nodes.
*** This is not possible with 2 nodes and 1 replicas per node.
*** At least 6 nodes are required.
like image 754
Janaki Sathiyamurthy Avatar asked Feb 22 '14 10:02

Janaki Sathiyamurthy


2 Answers

Yes. The requirement of at least 3 master nodes is set by the ruby script, but not a hard limit in cluster.

The first thing you need to do is send a cluster command with 16385 arguments like

cluster addslots 0 1 2 3 ... 16384

to the cluster. Since there is too many arguments to manually type them in a redis-cli, I suggest write a program to do that, in which you open a TCP socket connecting to the redis node, convert the previous command into a redis command string and write it to the socket.

The single node cluster will be online after few seconds you send the command. Then connect to the other node with redis-cli, type the following command to make it a slave

cluster meet MASTER_HOST MASTER_PORT
cluster replicate MASTER_ID

where MASTER_HOST:MASTER_PORT is the address of the previous node, and MASTER_ID is the ID of that node, which you could retrieve it via a cluster nodes command.

For convenience I've written a python tool for those kinds of redis cluster management, you could install it with

pip install redis-trib

For more detail please go to https://github.com/HunanTV/redis-trib.py/

like image 102
neuront Avatar answered Sep 18 '22 16:09

neuront


Redis-Cluster is not a fit for your use case.

For your use case, you need to configure one server (the master), then configure a second server and add the "slaveof" directive - pointing it to the master. How you handle failover is up to your scenario but I would recommend the use of redis-sentinel.

For a more detailed walkthrough, see the Redis Replication page

like image 20
The Real Bill Avatar answered Sep 17 '22 16:09

The Real Bill