In Part III we finished setting up Redis Sentinel and performed a test by shutting down the Primary and watching as Sentinel failed over to one of the Secondaries. In this article we are going to throw all of that away and start fresh, only this time we will deploy Redis Cluster to our 3 nodes.

If you are following along with the Vagrant setup described in Part II then now is the time to run vagrant destroy.

This will wipe out the current setup. Once that is done you need to start it all back up with vagrant up

Once the new environment is built, go ahead and finish setting up Docker swarm, again described in Part II.

Now that is done, we should have 3 machines, redis1, redis2, and redis3. Redis1 should be a docker swarm Manager node with 2 and 3 joined as Workers. Lets get started building out our cluster.

Like I mentioned in the previous post, it’ll be best if we define our own image. We started that work with the redis-sentinel image. We’re going to update things based on that. To start create a new file called redis-cluster.conf, and populate with this:

Then update your Dockerfile to match:

Now lets build the image and push it up to docker hub

Now lets start off by creating our 3 Primaries on the Docker Swarm:

Once those are running we can initiate the cluster:

Notice in the output the lines :

These identify the master ids in the redis cluster, we’ll need them for later. We are going to configure the instances as follows:

You’ll notice that with each instanced pinned to a Docker Host, and the Replica for a Master being on a different machine, we afford ourselves some fault tolerance.

Ok, now on to configuring the replicas. First we need to create the Docker Services:

Once those are running we need to connect to Redis1 and issue the commands to join the replicas to the masters:

We now have a fully functional Redis Cluster running on Docker Swarm with 3 Masters and 1 Replica / Master spread across the swarm in a fault tolerant way.

In the next post we’ll cover some basic Kernel Tuning that is essential to hosting Redis (or really any application) in Production.