diff --git a/bitnami/redis/5.0/debian-9/Dockerfile b/bitnami/redis/5.0/debian-9/Dockerfile index 06187fc8a36e..3023661a5449 100644 --- a/bitnami/redis/5.0/debian-9/Dockerfile +++ b/bitnami/redis/5.0/debian-9/Dockerfile @@ -23,6 +23,9 @@ ENV ALLOW_EMPTY_PASSWORD="no" \ REDIS_MASTER_PASSWORD="" \ REDIS_MASTER_PASSWORD_FILE="" \ REDIS_MASTER_PORT_NUMBER="6379" \ + REDIS_SENTINEL_HOST="" \ + REDIS_SENTINEL_MASTER_NAME="mymaster" \ + REDIS_SENTINEL_PORT_NUMBER="26379" \ REDIS_PASSWORD="" \ REDIS_PASSWORD_FILE="" \ REDIS_REPLICATION_MODE="" diff --git a/bitnami/redis/5.0/debian-9/rootfs/libredis.sh b/bitnami/redis/5.0/debian-9/rootfs/libredis.sh index 14648858aef9..f7b71dc86f67 100644 --- a/bitnami/redis/5.0/debian-9/rootfs/libredis.sh +++ b/bitnami/redis/5.0/debian-9/rootfs/libredis.sh @@ -273,6 +273,11 @@ redis_configure_replication() { redis_conf_set masterauth "$REDIS_PASSWORD" fi elif [[ "$REDIS_REPLICATION_MODE" =~ ^(slave|replica)$ ]]; then + if [[ -n "$REDIS_SENTINEL_HOST" ]]; then + REDIS_SENTINEL_INFO=($(redis-cli -h $REDIS_SENTINEL_HOST -p $REDIS_SENTINEL_PORT_NUMBER sentinel get-master-addr-by-name $REDIS_SENTINEL_MASTER_NAME)) + REDIS_MASTER_HOST=${REDIS_SENTINEL_INFO[0]} + REDIS_MASTER_PORT_NUMBER=${REDIS_SENTINEL_INFO[1]} + fi wait-for-port --host "$REDIS_MASTER_HOST" "$REDIS_MASTER_PORT_NUMBER" [[ -n "$REDIS_MASTER_PASSWORD" ]] && redis_conf_set masterauth "$REDIS_MASTER_PASSWORD" # Starting with Redis 5, use 'replicaof' instead of 'slaveof'. Maintaining both for backward compatibility diff --git a/bitnami/redis/5.0/ol-7/Dockerfile b/bitnami/redis/5.0/ol-7/Dockerfile index bde96284faba..70cea23d157c 100644 --- a/bitnami/redis/5.0/ol-7/Dockerfile +++ b/bitnami/redis/5.0/ol-7/Dockerfile @@ -23,6 +23,9 @@ ENV ALLOW_EMPTY_PASSWORD="no" \ REDIS_MASTER_PASSWORD="" \ REDIS_MASTER_PASSWORD_FILE="" \ REDIS_MASTER_PORT_NUMBER="6379" \ + REDIS_SENTINEL_HOST="" \ + REDIS_SENTINEL_MASTER_NAME="mymaster" \ + REDIS_SENTINEL_PORT_NUMBER="26379" \ REDIS_PASSWORD="" \ REDIS_PASSWORD_FILE="" \ REDIS_REPLICATION_MODE="" diff --git a/bitnami/redis/5.0/ol-7/rootfs/libredis.sh b/bitnami/redis/5.0/ol-7/rootfs/libredis.sh index 14648858aef9..f7b71dc86f67 100644 --- a/bitnami/redis/5.0/ol-7/rootfs/libredis.sh +++ b/bitnami/redis/5.0/ol-7/rootfs/libredis.sh @@ -273,6 +273,11 @@ redis_configure_replication() { redis_conf_set masterauth "$REDIS_PASSWORD" fi elif [[ "$REDIS_REPLICATION_MODE" =~ ^(slave|replica)$ ]]; then + if [[ -n "$REDIS_SENTINEL_HOST" ]]; then + REDIS_SENTINEL_INFO=($(redis-cli -h $REDIS_SENTINEL_HOST -p $REDIS_SENTINEL_PORT_NUMBER sentinel get-master-addr-by-name $REDIS_SENTINEL_MASTER_NAME)) + REDIS_MASTER_HOST=${REDIS_SENTINEL_INFO[0]} + REDIS_MASTER_PORT_NUMBER=${REDIS_SENTINEL_INFO[1]} + fi wait-for-port --host "$REDIS_MASTER_HOST" "$REDIS_MASTER_PORT_NUMBER" [[ -n "$REDIS_MASTER_PASSWORD" ]] && redis_conf_set masterauth "$REDIS_MASTER_PASSWORD" # Starting with Redis 5, use 'replicaof' instead of 'slaveof'. Maintaining both for backward compatibility diff --git a/bitnami/redis/5.0/rhel-7/Dockerfile b/bitnami/redis/5.0/rhel-7/Dockerfile index c10f3641960d..2827a4d1960e 100644 --- a/bitnami/redis/5.0/rhel-7/Dockerfile +++ b/bitnami/redis/5.0/rhel-7/Dockerfile @@ -23,6 +23,9 @@ ENV ALLOW_EMPTY_PASSWORD="no" \ REDIS_MASTER_PASSWORD="" \ REDIS_MASTER_PASSWORD_FILE="" \ REDIS_MASTER_PORT_NUMBER="6379" \ + REDIS_SENTINEL_HOST="" \ + REDIS_SENTINEL_MASTER_NAME="mymaster" \ + REDIS_SENTINEL_PORT_NUMBER="26379" \ REDIS_PASSWORD="" \ REDIS_PASSWORD_FILE="" \ REDIS_REPLICATION_MODE="" diff --git a/bitnami/redis/5.0/rhel-7/rootfs/libredis.sh b/bitnami/redis/5.0/rhel-7/rootfs/libredis.sh index 14648858aef9..f7b71dc86f67 100644 --- a/bitnami/redis/5.0/rhel-7/rootfs/libredis.sh +++ b/bitnami/redis/5.0/rhel-7/rootfs/libredis.sh @@ -273,6 +273,11 @@ redis_configure_replication() { redis_conf_set masterauth "$REDIS_PASSWORD" fi elif [[ "$REDIS_REPLICATION_MODE" =~ ^(slave|replica)$ ]]; then + if [[ -n "$REDIS_SENTINEL_HOST" ]]; then + REDIS_SENTINEL_INFO=($(redis-cli -h $REDIS_SENTINEL_HOST -p $REDIS_SENTINEL_PORT_NUMBER sentinel get-master-addr-by-name $REDIS_SENTINEL_MASTER_NAME)) + REDIS_MASTER_HOST=${REDIS_SENTINEL_INFO[0]} + REDIS_MASTER_PORT_NUMBER=${REDIS_SENTINEL_INFO[1]} + fi wait-for-port --host "$REDIS_MASTER_HOST" "$REDIS_MASTER_PORT_NUMBER" [[ -n "$REDIS_MASTER_PASSWORD" ]] && redis_conf_set masterauth "$REDIS_MASTER_PASSWORD" # Starting with Redis 5, use 'replicaof' instead of 'slaveof'. Maintaining both for backward compatibility diff --git a/bitnami/redis/README.md b/bitnami/redis/README.md index e91b6a3f8117..4f338af7a37e 100644 --- a/bitnami/redis/README.md +++ b/bitnami/redis/README.md @@ -377,6 +377,26 @@ The above command scales up the number of replicas to `3`. You can scale down in > **Note**: You should not scale up/down the number of master nodes. Always have only one master node running. +### Using redis-sentinel + +If you have redis-sentinel running, you can use it to find the current master by configuring the following environment variables: +- REDIS_REPLICATION_MODE=slave (we only want to configure this when in slave mode) +- REDIS_SENTINEL_HOST= (this would ideally be a round robin DNS hostname) +- REDIS_SENTINEL_PORT= + +What happens behind the scenes is at startup the sentinel gets queried for the current master IP and port, and sets the ```REDIS_MASTER_HOST``` and ```REDIS_MASTER_PORTNUMER``` with those values. + +```bash +$ docker run --name redis-replica \ + --link redis-master:master \ + -e REDIS_REPLICATION_MODE=slave \ + -e REDIS_SENTINEL_HOST=redis-sentinel \ + -e REDIS_SENTINEL_PORT_NUMBER=26379 \ + -e REDIS_SENTINEL_MASTER_NAME=mymaster \ + -e REDIS_PASSWORD=password123 \ + bitnami/redis:latest +``` + ## Configuration file The image looks for configurations in `/opt/bitnami/redis/etc/redis.conf`. You can overwrite the `redis.conf` file using your own custom configuration file.