Deploy a Consul datacenter, and an sentinel-enabled redis service. These resources will be used to provide complete service mesh and redis high availability capabilities.
To prevent from confusing from redis cluster, avoid to use term - redis cluster.
- Vagrant
- VirtualBox
- Linux or OSX
All three nodes are independ, and all redis are master role.
- Clone consul-redis-sentinel-demo repository.
- Navigate to this directory.
vagrant up
to provision three servers, which areserver1
~server5
respectively.- Execute the following commands in three servers
$> vagrant ssh server1
vagrant@server1:~$ cd /vagrant
vagrant@server1:/vagrant$ ./docker-up-master.sh -d
All three nodes are joint cluster, and one of redis will play master role. Any content was resident in the slave role will be overwritten by master one.
- Execute the following commands in three servers
$> vagrant ssh server1
vagrant@server1:~$ cd /vagrant
vagrant@server1:/vagrant$ ./docker-stop.sh
vagrant@server1:/vagrant$ ./docker-up-cluster.sh -d
- Stop the node you would like to remove permanently, let's say
server1
$> vagrant ssh server1
vagrant@server1:~$ cd /vagrant
vagrant@server1:/vagrant$ ./docker-stop.sh
- Execute the following commands in one of alive nodes.
$> vagrant ssh server2
vagrant@server2:/vagrant$ docker exec -it consul-server sh -c "consul force-leave -prune server1"
- Accordingly, consul config should also be amended to reflect the new cluster setting.
bootstrap_expect = 4
retry_join = ["10.1.0.20", "10.1.0.30", "10.1.0.40", "10.1.0.50"]
retry_interval = "30s"
- Pick one of the rest of nodes as redis master while starting redis and sentinel containers, amend
docker-up-cluster.sh
accordingly.
MASTER_HOSTIP=10.1.0.30
- Lists the members of a Consul cluster and status.
vagrant@server1:/vagrant$ docker exec -it consul-server sh -c "consul members"
- Display the current Raft peer configuration includes leader and follower information.
vagrant@server1:/vagrant$ docker exec -it consul-server sh -c "consul operator raft list-peers"
- Redis replication status.
# connect to slave node by replacing port 6379 with 6380
vagrant@server1:/vagrant$ docker exec -it redis sh -c "redis-cli -h redis-proxy -p 6379"
redis-proxy:6379> auth supersecret
redis-proxy:6379> info replication