Code Monkey home page Code Monkey logo

redis-sentinel-docker's Introduction

redis-sentinel

Dockerfiles for Redis Sentinel based on alpine images, suitable for the production environment. Image is available directly from public docker registry. This images are updated via pull requests to the s7anley/redis-sentinel-docker GitHub repo.

Redis Sentinel

Redis Sentinel provides high availability for Redis. In practical terms this means that using Sentinel you can create a Redis deployment that resists without human intervention to certain kind of failures. Additionally also provides other collateral tasks such as monitoring, notifications and acts as a configuration provider for clients.

Supported tags and respective Dockerfile links

Demo

For demonstration purposes you can use docker-compose -p sentinel up -d to bootstrap one redis master and slave and single sentinel to monitor them. In case you want to simulate sentinel cluster, scale number of sentinels with docker-compose -p sentinel up -d --scale sentinel=3.

To obtain confirm, that everything is working, we can ask for current master IP address with command:

$ docker exec sentinel_sentinel_1 redis-cli -p 26379 sentinel get-master-addr-by-name mymaster

You can find all available sentinel commands in documentation

How to use this image

In documentation is suggested to add Sentinel one one at a time, in order to still guarantee that majority can be achieved only in one side of a partition, in the chance failures should happen in the process of adding new Sentinels. Recommended delay is 30 seconds.

$ docker run --name redis-sentinel_1 -d -e QUORUM=2 -e MASTER=<some ip address> redis-sentinel

Sentinel, Docker and possible issues

Running sentinel with network setting bridge will break Sentinel's auto-discovery, unless you instruct Docker to map the port 1:1. To force Sentinel to announce a specific IP (e.g. your host machine) and mapped port, you should use ANNOUNCE_IP and ANNOUNCE_PORT environment variables. For more information see documentation.

AWS ECS

Amazon EC2 Container Service currently doesn't support host network setting, therefore Sentinel has to announce IP address of host machine. Setting variable AWS_IP_DISCOVERY to true, will force auto discovery of internal IP address of EC2 machine. For further explanation see section above.

Environment Variables

MASTER - Colon-separated IP address and port or Redis master. Port is optional, REDIS_PORT is used when missing. E.g. ip_address or ip_address:port.

REDIS_PORT - Port on which is master available. Default value is 6379.

SENTINEL_PORT - A port on which sentinel is communicating. A default value is 26379. In case you change this value, don't forget to expose additional port manually. By default, only 26379 is exposed.

MASTER_NAME - Unique name for master. When defined, monitoring will be initialized.

QUORUM - 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 fail over procedure if possible. Default value is 2.

DOWN_AFTER - Time in milliseconds an instance should not be reachable for a Sentinel starting to think it is down. Default value 30000.

FAILOVER_TIMEOUT - Wait time before failover retry of the same master. Default value 180000.

PARALLEL_SYNCS - Sets the number of slaves that can be reconfigured to use the new master after a failover at the same time. Default value 1.

SLAVES - Manually setting of all the slaves of monitored master. Accepted format is a colon-separated IP address and port for each slave server. Multiple slaves are separated by a semicolon. E.g. ip_address:host;ip_address. Use only in-case your slave hosts could not be correctly resolved.

NOTIFICATION_SCRIPT - Manually setting of notification-script on master. Script must exists and be executable or container will fail to start.

CLIENT_RECONFIG_SCRIPT - Manually setting of client-reconfig-script on master. Script must exists and be executable or container will fail to start.

ANNOUNCE_IP - Host machine IP address.

ANNOUNCE_PORT - Mapped sentinel port.

AWS_IP_DISCOVERY - Use internal IP address of AWS EC2 machine as ANNOUNCE_IP.

AUTH_PASS - Authentication password to use when connecting to master.

redis-sentinel-docker's People

Contributors

gustav-b avatar kadashu avatar linux-colonel avatar mqasimsarfraz avatar s7anley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

redis-sentinel-docker's Issues

sentinel get master return local network ip:port

I started the cluster successfully and then I try to use this cluster, but when I connect to sentinel, and get master info from it, it returns an ip in 172.x.x.x network.

here is the code:

import redis

r = redis.Redis(host='10.227.10.225', port=16379, db=0) # master
s = redis.Redis(host='10.227.10.225', port=16380, db=0) # salve

from redis.sentinel import Sentinel
st = Sentinel([('10.227.10.225', '26379')], password=pwd)
m = st.master_for('mymaster')
m.keys() 

and it raise an exception redis.exceptions.ConnectionError: Error 60 connecting to 172.28.0.2:6379. Operation timed out.
apparently master_for get an addr of the local network. is there any way to bind the network with host ip(like create a network with host type) to avoid this problem.

/etc/sentinel.conf config error!

error

my docker-compose.yml

version: '3'

services:
  master:
    image: redis:4.0.10-alpine
    hostname: master
    container_name: master
    network_mode: 'redis_sentinel_net'

  slave_1:
    image: redis:4.0.10-alpine
    hostname: slave_1
    container_name: slave_1
    network_mode: 'redis_sentinel_net'

  slave_2:
    image: redis:4.0.10-alpine
    hostname: slave_2
    container_name: slave_2
    network_mode: 'redis_sentinel_net'
    
  sentinel_1:
    image: s7anley/redis-sentinel-docker:4.0.10
    hostname: sentinel_1
    container_name: sentinel_1
    network_mode: 'redis_sentinel_net'
    ports:
      - 26379:26379
    environment:
      - MASTER_NAME=mymaster
      - QUORUM=2
      - MASTER=master
      - SLAVES=slave_1;slave_2
    depends_on:
      - master

  sentinel_2:
    image: s7anley/redis-sentinel-docker:4.0.10
    hostname: sentinel_2
    container_name: sentinel_2
    network_mode: 'redis_sentinel_net'
    ports:
      - 26380:26379
    environment:
      - MASTER_NAME=mymaster      
      - QUORUM=2
      - MASTER=master
      - SLAVES=slave_1;slave_2
    depends_on:
      - master

  sentinel_3:
    image: s7anley/redis-sentinel-docker:4.0.10
    hostname: sentinel_3
    container_name: sentinel_3
    network_mode: 'redis_sentinel_net'
    ports:
      - 26381:26379
    environment:
      - MASTER_NAME=mymaster      
      - QUORUM=2
      - MASTER=master
      - SLAVES=slave_1;slave_2
    depends_on:
      - master

Start Stop doesn't work

I can start with docker-compose up -d and all works.

But when i stop with docker-compose stop and then start docker-compose start the sentinel failed.

logs

sentinel_1      | *** FATAL CONFIG FILE ERROR ***
sentinel_1      | Reading the configuration file, at line 9
sentinel_1      | >>> 'sentinel known-slave mymaster 192.168.208.2 6379'
sentinel_1      | Wrong hostname or port for slave.
redissentinel_sentinel_1 exited with code 1

docker-compose.yml

version: '2'

services:
    redis_master:
        image: redis:3.2.9-alpine

    redis_slave:
        image: redis:3.2.9-alpine

    sentinel:
        image: s7anley/redis-sentinel-docker:3.2.9
        environment:
            - MASTER_NAME=mymaster
            - QUORUM=1
            - MASTER=redis_master
            - SLAVES=redis_slave
            - SENTINEL_PORT=26380
        expose:
            - 26380
        depends_on:
            - redis_master

docker-compose down is not worked

I use docker-compose -p sentinel up -d to run the image
but when I try shutdown the service docker-compose down
it shows that

Removing network redis-sentinel-docker_default
WARNING: Network redis-sentinel-docker_default not found.

And cannot stop the service

Error when running docker-compose

Copied the docker-compose file from the repo. Now trying to run docker-compose up -d.

It fails with the following error:

Building sentinel
ERROR: Cannot locate specified Dockerfile: Dockerfile

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.