├── remove_docker_redis_cluster.sh ├── README.md └── provision_docker_redis_cluster.sh /remove_docker_redis_cluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo docker rm -f redis_0 3 | sudo docker rm -f redis_1 4 | 5 | sudo docker rm -f sentinel_0 6 | sudo docker rm -f sentinel_1 7 | sudo docker rm -f sentinel_2 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | docker-rediscluster 2 | =================== 3 | 4 | Sets up a disposable redis cluster for testing sentinel failover. 5 | 6 | Topology 7 | -------- 8 | 9 | redis_0 - master 10 | 11 | redis_1 - slave of redis_0 12 | 13 | sentinel_0 14 | 15 | sentinel_1 16 | 17 | sentinel_2 18 | 19 | The sentinels are configured with a "testing" instance with the following properties - 20 | 21 | ``` 22 | down-after-milliseconds 1000 23 | failover-timeout 1000 24 | parallel-syncs 1 25 | ``` 26 | 27 | Set up 28 | ------ 29 | 30 | Install the redis-cli maybe using apt-get install redis-server 31 | 32 | ``` 33 | docker pull redis 34 | docker pull joshula/redis-sentinel 35 | ``` 36 | 37 | Run 38 | --- 39 | 40 | provision_docker_redis_cluster.sh 41 | 42 | Remove cluster 43 | -------------- 44 | 45 | remove_docker_redis_cluster.sh 46 | 47 | Play with it 48 | ------------ 49 | 50 | Attach to a sentinel 51 | 52 | ``` 53 | sudo docker attach sentinel_1 54 | ``` 55 | 56 | Pause/Unpause redis instances 57 | 58 | ``` 59 | sudo docker pause redis_0 60 | sudo docker unpause redis_0 61 | ``` 62 | 63 | -------------------------------------------------------------------------------- /provision_docker_redis_cluster.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DOCKER_IP=$(ifconfig docker0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}') 4 | 5 | echo "DOCKER IP : $DOCKER_IP" 6 | 7 | # create two redis instances 8 | sudo docker run --name redis_0 -t -d -i redis:2.8 9 | sudo docker run --name redis_1 -t -d -i redis:2.8 10 | 11 | #get master ip 12 | REDIS_0_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' redis_0) 13 | REDIS_1_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' redis_1) 14 | 15 | echo "REDIS_0_IP : $REDIS_0_IP" 16 | echo "REDIS_1_IP : $REDIS_1_IP" 17 | 18 | # start up the sentinels 19 | sudo docker run --name sentinel_0 -d -p 26379:26379 joshula/redis-sentinel --sentinel announce-ip $DOCKER_IP --sentinel announce-port 26379 20 | sudo docker run --name sentinel_1 -d -p 26378:26379 joshula/redis-sentinel --sentinel announce-ip $DOCKER_IP --sentinel announce-port 26378 21 | sudo docker run --name sentinel_2 -d -p 26377:26379 joshula/redis-sentinel --sentinel announce-ip $DOCKER_IP --sentinel announce-port 26377 22 | 23 | #get sentinel ips 24 | SENTINEL_0_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' sentinel_0) 25 | SENTINEL_1_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' sentinel_1) 26 | SENTINEL_2_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' sentinel_2) 27 | 28 | echo "SENTINEL_0_IP : $SENTINEL_0_IP" 29 | echo "SENTINEL_1_IP : $SENTINEL_1_IP" 30 | echo "SENTINEL_2_IP : $SENTINEL_2_IP" 31 | 32 | redis-cli -h $REDIS_1_IP -p 6379 slaveof $REDIS_0_IP 6379 33 | 34 | redis-cli -p 26379 sentinel monitor testing $REDIS_0_IP 6379 2 35 | redis-cli -p 26379 sentinel set testing down-after-milliseconds 1000 36 | redis-cli -p 26379 sentinel set testing failover-timeout 1000 37 | redis-cli -p 26379 sentinel set testing parallel-syncs 1 38 | 39 | redis-cli -p 26378 sentinel monitor testing $REDIS_0_IP 6379 2 40 | redis-cli -p 26378 sentinel set testing down-after-milliseconds 1000 41 | redis-cli -p 26378 sentinel set testing failover-timeout 1000 42 | redis-cli -p 26378 sentinel set testing parallel-syncs 1 43 | 44 | redis-cli -p 26377 sentinel monitor testing $REDIS_0_IP 6379 2 45 | redis-cli -p 26377 sentinel set testing down-after-milliseconds 1000 46 | redis-cli -p 26377 sentinel set testing failover-timeout 1000 47 | redis-cli -p 26377 sentinel set testing parallel-syncs 1 --------------------------------------------------------------------------------