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:
...  22 Dec 22:22:43.309 # +failover-end master mymaster 127.0.0.1 7777  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"
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:
Or maybe even 3 Sentinel processes per box since each can only monitor one master?