项目作者: jay-johnson

项目描述 :
Running a distributed 6-node Redis Cluster with Docker Swarm, Docker Compose, and Supervisor
高级语言: Shell
项目地址: git://github.com/jay-johnson/docker-redis-cluster.git
创建时间: 2015-12-02T02:05:42Z
项目社区:https://github.com/jay-johnson/docker-redis-cluster

开源协议:

下载


A Distributed Redis Cluster using Docker Swarm, Docker Compose, and Supervisor

Overview

This repository will start a distributed 6-node Redis Cluster using Docker Swarm with Docker Compose and Supervisor for high availability. The redis instances listen on the host node ports: 6379-6384. There are 3 master nodes and 3 replica nodes. If you are running a local Docker Swarm you can run the entire 6-node cluster locally.

How to Install

  1. Make sure Swarm is installed

    1. docker-redis-cluster $ sudo ./1_install_core.sh
  2. Restart the local consul, docker daemon, swarm manager, and swarm join

    1. docker-redis-cluster $ sudo ./boot_local_docker_services.sh
  3. Point to the Docker Swarm

    Please set the terminal environment to use the running Docker Swarm

    1. $ export DOCKER_HOST=localhost:4000
    2. $ env | grep DOCKER
    3. DOCKER_HOST=localhost:4000
    4. $
  4. Confirm the Docker Swarm Membership

    Running the swarm locally you should see only 1 node with something similar:

    1. $ docker info
    2. Containers: 0
    3. Images: 0
    4. Role: primary
    5. Strategy: spread
    6. Filters: health, port, dependency, affinity, constraint
    7. Nodes: 1
    8. localhost.localdomain: localhost:2375
    9. Containers: 0
    10. Reserved CPUs: 0 / 2
    11. Reserved Memory: 0 B / 4.053 GiB
    12. Labels: executiondriver=native-0.2, kernelversion=4.1.7-200.fc22.x86_64, operatingsystem=Fedora 22 (Twenty Two), storagedriver=devicemapper
    13. CPUs: 2
    14. Total Memory: 4.053 GiB
    15. Name: localhost.localdomain
    16. $

Start the Redis Cluster

Assuming consul, docker daemon, swarm manager, and swarm join are running with something similar to:

  1. $ ps auwwx | grep consul | grep -v grep
  2. root 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
  3. root 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
  4. root 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
  5. root 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
  6. $
  1. Make sure no other Redis nodes are running

    1. $ docker ps -a
    2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    3. $
  2. Start the Redis Cluster

    1. docker-redis-cluster $ ./start_cluster.sh
    2. Starting the Cluster on Docker Swarm
    3. Creating redismaster1
    4. Creating redismaster3
    5. Creating redismaster2
    6. Creating redisreplica1
    7. Creating redisreplica2
    8. Creating redisreplica3
    9. Done
    10. docker-redis-cluster $
  3. Confirm the Containers are running

    1. $ docker ps
    2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    3. 89f8ab731348 jayjohnson/redis-clusterable "/bin/sh -c '. /bin/s" 4 minutes ago Up 4 minutes 127.0.0.1:6384->6379/tcp, 127.0.0.1:16384->16379/tcp, 127.0.0.1:26384->26379/tcp localhost.localdomain/redisreplica3
    4. 6ff759f42bb6 jayjohnson/redis-clusterable "/bin/sh -c '. /bin/s" 4 minutes ago Up 4 minutes 127.0.0.1:6383->6379/tcp, 127.0.0.1:16383->16379/tcp, 127.0.0.1:26383->26379/tcp localhost.localdomain/redisreplica2
    5. fe97da8b920a jayjohnson/redis-clusterable "/bin/sh -c '. /bin/s" 4 minutes ago Up 4 minutes 127.0.0.1:6382->6379/tcp, 127.0.0.1:16382->16379/tcp, 127.0.0.1:26382->26379/tcp localhost.localdomain/redisreplica1
    6. 8ed2a60663f6 jayjohnson/redis-clusterable "/bin/sh -c '. /bin/s" 4 minutes ago Up 4 minutes 127.0.0.1:6380->6379/tcp, 127.0.0.1:16380->16379/tcp, 127.0.0.1:26380->26379/tcp localhost.localdomain/redismaster2
    7. 3a779ae52bd7 jayjohnson/redis-clusterable "/bin/sh -c '. /bin/s" 4 minutes ago Up 4 minutes 127.0.0.1:6381->6379/tcp, 127.0.0.1:16381->16379/tcp, 127.0.0.1:26381->26379/tcp localhost.localdomain/redismaster3
    8. 085b750909d5 jayjohnson/redis-clusterable "/bin/sh -c '. /bin/s" 4 minutes ago Up 4 minutes 127.0.0.1:6379->6379/tcp, 127.0.0.1:16379->16379/tcp, 127.0.0.1:26379->26379/tcp localhost.localdomain/redismaster1
    9. $

Confirm the Redis Cluster using the Command Line Tool

  1. $ redis-cli -h 127.0.0.1 -p 6384 cluster nodes
  2. aa81e0dc13f4985dd0b70647d338f899454326af :6379 myself,master - 0 0 6 connected
  3. $

Inspect the Redis Cluster Details

  1. $ ./cst.sh
  2. Printing Redis Cluster Status:
  3. redismaster1(6379):
  4. 399de28f4b010ae4395db704887bfdea92aa2144 :6379 myself,master - 0 0 1 connected 0-5460
  5. redismaster2(6380):
  6. 1c62661d9235463b5f3906a687ddc4010444f4ac :6379 myself,master - 0 0 2 connected 5461-10922
  7. redismaster3(6381):
  8. 6fc1dda1fec41b4fbb0654d926dbfe17700c412b :6379 myself,master - 0 0 3 connected 10923-16383
  9. redisreplica1(6382):
  10. fffa24ec3a9d8485e63bf4e0d09bb2428ca7851b :6379 myself,master - 0 0 4 connected
  11. redisreplica2(6383):
  12. bb6844f7b7a3ccc1c0bc392461d342037916b903 :6379 myself,master - 0 0 5 connected
  13. redisreplica3(6384):
  14. c05e9a770e8aa11d82793f2d1076b7a94334d83c :6379 myself,master - 0 0 6 connected
  15. Done
  16. $

Stop the Redis Cluster

  1. $ ./stop_cluster.sh
  2. Stopping the Cluster on Docker Swarm
  3. Stopping redisreplica3 ... done
  4. Stopping redisreplica2 ... done
  5. Stopping redisreplica1 ... done
  6. Stopping redismaster2 ... done
  7. Stopping redismaster3 ... done
  8. Stopping redismaster1 ... done
  9. Cleaning up old containers for ports
  10. Done
  11. $