Apache Redis is an open source in memory cache store, used as a database cache and message broker. Redis is rich in data structures like strings, hashes, lists, sets, sorted sets with range queries,
bitmaps, hyperlog logs and geospatial indexes with radius queries. Apart from that Redis provides built-in replication, Lua scripting, LRU eviction, transactions and different levels of
on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
Apache Redis Cluster Setup on Ubuntu
In this article we will se how to setup a redis cluster on ubuntu machine, we have six 4GB ubuntu machines, three master and three slaves:
X.161.56.22, X.161.169.110, X.161.160.84, X.161.243.43, X.161.45.54, X.161.67.32
Following steps are needed to follow to setup a Redis cluster on ubuntu machines, with three master and three slaves:
Step1: Install Compiler for c on each machine
$sudo apt-get update
Step2: Download, extract and compile Redis
$sudo apt-get install build-essential
$sudo apt-get install tcl8.5
Step3: Change configuration on each machine as shown below:
$ wget http://download.redis.io/releases/redis-3.2.5.tar.gz
$ tar xzf redis-3.2.5.tar.gz
$ cd redis-3.2.5
A minimal configuration file for cluster mode must have following values:
Comment following line: "bind 127.0.0.1", make sure there is no element in the file with bind. Uncommenting it will make your redis server to be exposed everywhere on the internet, this is for test purpose only. In production please specify trusted ips in this bind element to restrict redis exposure to outer internet.
Consider more security measured related to "protected-mode" while deploying on production.
Step 4: Start redis on each machine
src/redis-server redis.conf &
You will see and output with initial lines telling about the nodeID, nodes in the cluster knows each other with this id and not by ips.
10086:M 27 Oct 16:29:40.925 * No cluster configuration found, I'm 0c16d6f19240ad4c53f20f4085992194887470b1
At the end of the log you will see,
10792:M 27 Oct 16:29:00.679 * The server is now ready to accept connections on port 7000
Step 5: Run the cluster
Now we have a running redis instance on each machine in cluster mode, lets create a cluster with these nodes.
This can be done with redis-trib, a Ruby program executing special commands on instances in order to create new clusters, check or reshard an existing cluster, and so forth.
Make sure you have "gem" installed already if now do this with following command:
sudo apt-get install rubygems-integration
First we need to install redis gem to be able to run redis-trib.
gem install redis
Now create a cluster with following command
src/redis-trib.rb create --replicas 1 X.0.0.1:7000 X.31.11.7:7000 \
X.161.160.84:7000 X.162.60.136:7000 X.162.1.220:7000 X.161.72.214:7000
You will see something like this:
[OK] All 16384 slots
That's it for this article, we have seen how to setup a redis cluster on ubuntu machine. In upcoming articles we will see more about Useful Commands, Integration with Java, Cluster and Sentinel setup.