Created
May 19, 2015 11:52
-
-
Save jedi4ever/6920d4daf03bc31aac6a to your computer and use it in GitHub Desktop.
Redis - Redis Sentinel - Docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOCKER_IP=$(ip addr show docker0|grep "inet "|sed -e 's/^[ ]*//g'| cut -d ' ' -f 2| cut -d '/' -f 1) | |
docker stop redis_0 | |
docker stop redis_1 | |
docker stop sentinel_0 | |
docker stop sentinel_1 | |
docker stop sentinel_2 | |
docker rm redis_0 | |
docker rm redis_1 | |
docker rm sentinel_0 | |
docker rm sentinel_1 | |
docker rm sentinel_2 | |
echo "DOCKER IP : $DOCKER_IP" | |
# create two redis instances | |
sudo docker run --name redis_0 -t -d -i redis:2.8 | |
sudo docker run --name redis_1 -t -d -i redis:2.8 | |
#get master ip | |
REDIS_0_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' redis_0) | |
REDIS_1_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' redis_1) | |
echo "REDIS_0_IP : $REDIS_0_IP" | |
echo "REDIS_1_IP : $REDIS_1_IP" | |
# start up the sentinels | |
sudo docker run --name sentinel_0 -d -p 26379:26379 joshula/redis-sentinel --sentinel announce-ip $DOCKER_IP --sentinel announce-port 26379 | |
sudo docker run --name sentinel_1 -d -p 26378:26379 joshula/redis-sentinel --sentinel announce-ip $DOCKER_IP --sentinel announce-port 26378 | |
sudo docker run --name sentinel_2 -d -p 26377:26379 joshula/redis-sentinel --sentinel announce-ip $DOCKER_IP --sentinel announce-port 26377 | |
#get sentinel ips | |
SENTINEL_0_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' sentinel_0) | |
SENTINEL_1_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' sentinel_1) | |
SENTINEL_2_IP=$(sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' sentinel_2) | |
echo "SENTINEL_0_IP : $SENTINEL_0_IP" | |
echo "SENTINEL_1_IP : $SENTINEL_1_IP" | |
echo "SENTINEL_2_IP : $SENTINEL_2_IP" | |
docker exec redis_0 redis-cli -h $REDIS_1_IP -p 6379 slaveof $REDIS_0_IP 6379 | |
docker exec sentinel_0 redis-cli -p 26379 sentinel monitor testing $REDIS_0_IP 6379 2 | |
docker exec sentinel_0 redis-cli -p 26379 sentinel set testing down-after-milliseconds 1000 | |
docker exec sentinel_0 redis-cli -p 26379 sentinel set testing failover-timeout 1000 | |
docker exec sentinel_0 redis-cli -p 26379 sentinel set testing parallel-syncs 1 | |
docker exec sentinel_1 redis-cli -p 26379 sentinel monitor testing $REDIS_0_IP 6379 2 | |
docker exec sentinel_1 redis-cli -p 26379 sentinel set testing down-after-milliseconds 1000 | |
docker exec sentinel_1 redis-cli -p 26379 sentinel set testing failover-timeout 1000 | |
docker exec sentinel_1 redis-cli -p 26379 sentinel set testing parallel-syncs 1 | |
docker exec sentinel_2 redis-cli -p 26379 sentinel monitor testing $REDIS_0_IP 6379 2 | |
docker exec sentinel_2 redis-cli -p 26379 sentinel set testing down-after-milliseconds 1000 | |
docker exec sentinel_2 redis-cli -p 26379 sentinel set testing failover-timeout 1000 | |
docker exec sentinel_2 redis-cli -p 26379 sentinel set testing parallel-syncs 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment