Redis Cluster
Cluster, Version, Tips
eZ Conference 2018
Version 0.1
Understanding Redis setups
Simple Server and Master Slave
01
Slave configuration:
/etc/redis/redis.conf this Redis server an exact copy of a master server�# slaveof <masterip> <masterport>�slaveof localhost 6379�# setting a slave to authenticate to a master�masterauth mypass
Master configuration:
requirepass mypass
Get replication information: redis-cli -p 6379 -a mypass info replication
Stop replication and turning slave into a master: redis-cli -p 6380 slaveof no one
Redis Cluster
02
=> Manual configuration
Redis Cluster is not able to guarantee strong consistency. In practical terms this means that under certain conditions it is possible that Redis Cluster will lose writes that were acknowledged by the system to the client.
This means that during writes the following happens:
As you can see B does not wait for an acknowledge from B1, B2, B3 before replying to the client
Redis Cluster with Sentinel
03
Configuration example:
sentinel monitor mymaster redis-master 6379 $SENTINEL_QUORUM
sentinel down-after-milliseconds mymaster $SENTINEL_DOWN_AFTER
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster $SENTINEL_FAILOVER
The quorum is the number of Sentinels that need to agree about the fact the master is not reachable, in order for really mark the slave as failing, and eventually start a failover procedure if possible.
*Minimal numbers of Sentinel servers to be effective: 3
Create your own Redis Cluster Sentinel with Docker
HaProxy and Redis cluster auto-discovery ?
HashiCorp Consul: Service discovery and configuration made easy (https://www.consul.io/)
GliderLabs Registrator: Swatches for new Docker containers and inspects them to determine what services they provide. (http://gliderlabs.github.io/registrator/latest/)
HashiCorp Consul-template: queries a Consul instance and updates any number of specified templates on the filesystem. As an added bonus, Consul Template can execute arbitrary commands when a template update completes. (https://www.hashicorp.com/blog/introducing-consul-template)
01 | Service discovery
02 | Failure detection
03 | Multi datacenter
04 | KV storage
01 | Consul support
02 | Etcd support
03 | Sky DNS 2 support
Demo
Source code: https://github.com/dspe/docker-redis-cluster