{"id":18123308,"url":"https://github.com/jay-johnson/docker-redis-sentinel-replication-cluster","last_synced_at":"2025-04-14T23:04:28.342Z","repository":{"id":72596189,"uuid":"49406086","full_name":"jay-johnson/docker-redis-sentinel-replication-cluster","owner":"jay-johnson","description":"A Redis Replication Cluster running across a Docker Swarm using Compose, Supervisor, and Sentinel","archived":false,"fork":false,"pushed_at":"2016-01-11T18:17:40.000Z","size":12,"stargazers_count":11,"open_issues_count":3,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T23:03:56.582Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jay-johnson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-11T06:13:10.000Z","updated_at":"2021-10-12T07:57:37.000Z","dependencies_parsed_at":"2023-03-17T16:10:57.851Z","dependency_job_id":null,"html_url":"https://github.com/jay-johnson/docker-redis-sentinel-replication-cluster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-johnson%2Fdocker-redis-sentinel-replication-cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-johnson%2Fdocker-redis-sentinel-replication-cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-johnson%2Fdocker-redis-sentinel-replication-cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jay-johnson%2Fdocker-redis-sentinel-replication-cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jay-johnson","download_url":"https://codeload.github.com/jay-johnson/docker-redis-sentinel-replication-cluster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975315,"owners_count":21192208,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-01T07:09:12.504Z","updated_at":"2025-04-14T23:04:28.304Z","avatar_url":"https://github.com/jay-johnson.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"## A Distributed Redis + Sentinel Replication Cluster using Docker Swarm, Docker Compose, and Supervisor\n\n### Overview\n\nThis repository will start a distributed 3-node replication cluster using Redis, Sentinel and Supervisor using Docker Swarm and Compose for high availability. There are 3 Redis instances listening on ports: 9000-9002. There can be only 1 master Redis node at a time and the other 2 nodes are set up for fault-tolerant replication with Sentinel and Supervisor. The goal of this replication cluster is to reduce message and data loss even when the master Redis node crashes. When the master node crashes Sentinel will host a leader election and another node will become the new master by winning the election. Supervisor runs in each container and will automatically attempt to restart any stopped Redis instance. Sentinel is paired up with each Redis server and listens on ports 19000-19002 (***Redis Server Port*** + 10000).\n\n### How to Install\n\n1. Make sure Swarm is installed \n\n  ```\n  docker-redis-sentinel-replication-cluster $ sudo ./_install_docker_services.sh\n  ```\n\n1. Restart the local consul, docker daemon, swarm manager, and swarm join\n\n  ```\n  docker-redis-sentinel-replication-cluster $ sudo ./boot_local_docker_services.sh\n  ``` \n\n1. Point to the Docker Swarm\n\n  Please set the terminal environment to use the running Docker Swarm \n  \n  ```\n  $ export DOCKER_HOST=localhost:4000\n  $ env | grep DOCKER\n  DOCKER_HOST=localhost:4000\n  $\n  ```\n\n1. Confirm the Docker Swarm Membership\n\n  Running the swarm locally you should see only 1 node with something similar:\n\n  ```\n  $ docker info\n  Containers: 0\n  Images: 0\n  Role: primary\n  Strategy: spread\n  Filters: health, port, dependency, affinity, constraint\n  Nodes: 1\n   localhost.localdomain: localhost:2375\n    └ Containers: 0\n    └ Reserved CPUs: 0 / 2\n    └ Reserved Memory: 0 B / 4.053 GiB\n    └ Labels: executiondriver=native-0.2, kernelversion=4.1.7-200.fc22.x86_64, operatingsystem=Fedora 22 (Twenty Two), storagedriver=devicemapper\n  CPUs: 2\n  Total Memory: 4.053 GiB\n  Name: localhost.localdomain\n  $\n  ```\n\n### Start the Redis Replication Cluster \n\nAssuming consul, docker daemon, swarm manager, and swarm join are running with something similar to:\n\n```\n$ ps auwwx | grep consul | grep -v grep\nroot     29447  0.4  0.4 34110388 19204 pts/4  Sl   19:39   0:14 consul agent -server -data-dir=/tmp/consul -bind=0.0.0.0 -bootstrap-expect 1\nroot     31650 12.9  1.2 1329604 51208 pts/4   Sl   20:00   3:42 /usr/local/bin/docker daemon -H localhost:2375 --cluster-advertise 0.0.0.0:2375 --cluster-store consul://localhost:8500/developmentswarm\nroot     31738  0.0  0.5 488084 20512 pts/1    Sl   20:02   0:01 /usr/local/bin/swarm manage -H tcp://localhost:4000 --advertise localhost:4000 consul://localhost:8500/developmentswarm\nroot     31749  0.0  0.3 128416 14304 pts/1    Sl   20:02   0:00 /usr/local/bin/swarm join --addr=localhost:2375 consul://localhost:8500/developmentswarm\n$\n```\n \n1. Make sure no other Redis nodes are running\n\n  ```\n  $ docker ps -a\n  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES\n  $ \n  ```\n\n1. Start the Redis Cluster\n\n  ```\n  docker-redis-sentinel-replication-cluster $ ./start_cluster.sh \n  Starting the Redis Replication Cluster on Docker Swarm\n  Creating redisnode1\n  Creating redisnode3\n  Creating redisnode2\n  Done\n  docker-redis-sentinel-replication-cluster $\n  ```\n\n1. Confirm the Containers are running\n\n  ```\n  $ docker ps\n  bbdd5e7bdeaf        jayjohnson/redis-sentinel-supervisor-clusterable   \"/bin/sh -c '. /bin/s\"   24 seconds ago      Up 23 seconds       127.0.0.1:9001-\u003e9001/tcp, 6379/tcp, 127.0.0.1:19001-\u003e19001/tcp   localhost.localdomain/redisnode2\n  113642320e1b        jayjohnson/redis-sentinel-supervisor-clusterable   \"/bin/sh -c '. /bin/s\"   24 seconds ago      Up 23 seconds       127.0.0.1:9002-\u003e9002/tcp, 6379/tcp, 127.0.0.1:19002-\u003e19002/tcp   localhost.localdomain/redisnode3\n  94f3a89efc19        jayjohnson/redis-sentinel-supervisor-clusterable   \"/bin/sh -c '. /bin/s\"   25 seconds ago      Up 24 seconds       127.0.0.1:9000-\u003e9000/tcp, 6379/tcp, 127.0.0.1:19000-\u003e19000/tcp   localhost.localdomain/redisnode1\n  $\n  ```\n\n### Find the Redis Cluster Master Node using the Command Line Tool or Script\n\n\n```\n$ redis-cli -p 19000 sentinel get-master-addr-by-name redis-cluster\n1) \"10.0.0.2\"\n2) \"9000\"\n$ \n```\n\n```\n$ ./get_cluster_master.sh \n1) \"10.0.0.2\"\n2) \"9000\"\n$\n```\n\n### Redis Sentinel Client Discovery\n\nBased off the docker-compose.yml's CLUSTER_NAME env var, you can use the Redis Sentinel API to find the Master and Slave nodes for the named cluster.\n\nHere's the example from using the python client [redis-py](https://github.com/andymccurdy/redis-py#sentinel-support):\n\n```\n$ python\nPython 2.7.10 (default, Jul  5 2015, 14:15:43) \n[GCC 5.1.1 20150618 (Red Hat 5.1.1-4)] on linux2\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n\u003e\u003e\u003e from redis.sentinel import Sentinel\n\u003e\u003e\u003e sentinel = Sentinel([('localhost', 19000)], socket_timeout=0.1)\n\u003e\u003e\u003e sentinel.discover_master('redis-cluster')\n('10.0.1.2', 9000)\n\u003e\u003e\u003e sentinel.discover_slaves('redis-cluster')\n[('10.0.1.4', 9001), ('10.0.1.3', 9002)]\n\u003e\u003e\u003e \n```\n\n### Stop the Redis Cluster\n\n```\n$ ./stop_cluster.sh \nStopping the Redis Replication Cluster on Docker Swarm\nStopping redisnode2 ... \nStopping redisnode3 ... \nStopping redisnode1 ... \n$\n```\n\n### License\n\nThis is free to use under the MIT LICENSE.\n\nEnjoy.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjay-johnson%2Fdocker-redis-sentinel-replication-cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjay-johnson%2Fdocker-redis-sentinel-replication-cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjay-johnson%2Fdocker-redis-sentinel-replication-cluster/lists"}