Sentinel & Redis Quickstart

Here are a quick few steps to get Redis running locally with Sentinel. I’m using the following configuration:

sentinel_redis

To get things started:

$ git clone https://github.com/antirez/redis.git
$ cd redis
$ make
$ make test

To start the Redis master on port 7777:

$ cd src
$ ./redis-server --pidfile /tmp/redis-master.pid --port 7777

In another shell start the second Redis server:

$ cd src
$ ./redis-server --pidfile /tmp/redis-slave.pid --port 8888

Tell the second server running on port 8888 that he is the slave (this is later best done via config files but for the sake of keeping things short I won’t mess with config files here):

$ ./redis-cli -p 8888
redis 127.0.0.1:8888> slaveof 127.0.0.1 7777
OK

To start the two Sentinel processes we’ll prepare a config file in the top level Redis dir. The port change tells the Sentinel processes to monitor the Redis master running on port 7777:

$ cp sentinel.conf my-sentinel.conf
$ sed -i s/6379/7777/g my-sentinel.conf

Start the first Sentinel process:

$ ./redis-server ../my-sentinel.conf --sentinel --port 21111

And the second Sentinel process:

$ ./redis-server ../my-sentinel.conf --sentinel --port 22222

Both Sentinel processes will acknowledge that they see the master, the slave, and the other sentinel process. Let’s put a test value into the master:

$ ./redis-cli -p 7777
redis 127.0.0.1:7777> ping
PONG
redis 127.0.0.1:7777> set key1 value1
OK
redis 127.0.0.1:7777> get key1
"value1"

All seems fine. Now let’s kill the master. The two Sentinel processes should come to a consensus that the original master is dead and promote the slave to become the new master:

...
[8472] 22 Dec 22:22:43.309 # +failover-end master mymaster 127.0.0.1 7777
[8472] 22 Dec 22:22:43.309 # +switch-master mymaster 127.0.0.1 7777 127.0.0.1 8888

In a new client connection to port 8888 we check for key1:

$ ./redis-cli -p 8888
redis 127.0.0.1:8888> get key1
"value1"

Looks good.

Again, this configuration is purely for testing on a single computer and it makes no sense to run this anywhere but in dev (especially with the default quorum of 2). I suspect the minimal sensible config in prod that would address host failure would be something like this:

sentinel_prod_

Or maybe even 3 Sentinel processes per box since each can only monitor one master?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s