├── .env ├── README.md ├── cluster-entrypoint.sh ├── docker-compose.yml └── haproxy.cfg /.env: -------------------------------------------------------------------------------- 1 | RABBITMQ_ERLANG_COOKIE=12345 2 | RABBITMQ_DEFAULT_USER=guest 3 | RABBITMQ_DEFAULT_PASS=guest 4 | RABBITMQ_DEFAULT_VHOST=/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cluster RabbitMQ :rabbit: 2 | 3 | There are a lots of good options if you want to run a [RabbitMQ](https://hub.docker.com/_/rabbitmq/) cluster in [docker](http://docker.com/). Here's an solution that only rely on [docker official images](https://hub.docker.com/_/rabbitmq/) :tada: 4 | 5 | The main benifit with this approach is that you can use [any version](https://hub.docker.com/r/library/rabbitmq/tags/) of RabbitMQ, which is maintaied by docker and will be up-to-date with future releases. 6 | 7 | ## Install 8 | 9 | ``` 10 | > git clone https://github.com/pardahlman/docker-rabbitmq-cluster.git 11 | > cd docker-rabbitmq-cluster 12 | > docker-compose up 13 | ``` 14 | 15 | Most things will be how you expect: 16 | 17 | * The default username and password are `guest`/`guest` 18 | * The broker accepts connections on `localhost:5672` 19 | * The Management interface is found at `localhost:15672` 20 | 21 | ## Customize 22 | 23 | The `.env` file contains environment variables that can be used to change the default username, password and virtual host. 24 | 25 | ## HA Proxy 26 | 27 | This `docker-compose.yml` file comes with the latest version of [HA Proxy](http://www.haproxy.org/), an open source software that provides a high availability load balancer and proxy server. 28 | 29 | It should be fairly easy to add a [`port mapping`](https://docs.docker.com/compose/compose-file/#ports) for the individual containers if it is desired to connect to a specific broker node. 30 | 31 | ## Read more 32 | 33 | I wrote [a blog post](http://fellowdeveloper.se/2017/05/24/cluster-rabbitmq-in-docker/) that explains some of the ideas behind this repo. 34 | -------------------------------------------------------------------------------- /cluster-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # Start RMQ from entry point. 6 | # This will ensure that environment variables passed 7 | # will be honored 8 | /usr/local/bin/docker-entrypoint.sh rabbitmq-server -detached 9 | 10 | # Do the cluster dance 11 | rabbitmqctl stop_app 12 | rabbitmqctl join_cluster rabbit@rabbitmq1 13 | 14 | # Stop the entire RMQ server. This is done so that we 15 | # can attach to it again, but without the -detached flag 16 | # making it run in the forground 17 | rabbitmqctl stop 18 | 19 | # Wait a while for the app to really stop 20 | sleep 2s 21 | 22 | # Start it 23 | rabbitmq-server -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | 5 | rabbitmq1: 6 | image: rabbitmq:3-management 7 | hostname: rabbitmq1 8 | environment: 9 | - RABBITMQ_ERLANG_COOKIE=${RABBITMQ_ERLANG_COOKIE} 10 | - RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER} 11 | - RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS} 12 | - RABBITMQ_DEFAULT_VHOST=${RABBITMQ_DEFAULT_VHOST} 13 | 14 | rabbitmq2: 15 | image: rabbitmq:3-management 16 | hostname: rabbitmq2 17 | depends_on: 18 | - rabbitmq1 19 | environment: 20 | - RABBITMQ_ERLANG_COOKIE=${RABBITMQ_ERLANG_COOKIE} 21 | volumes: 22 | - ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh 23 | entrypoint: /usr/local/bin/cluster-entrypoint.sh 24 | 25 | rabbitmq3: 26 | image: rabbitmq:3-management 27 | hostname: rabbitmq3 28 | depends_on: 29 | - rabbitmq1 30 | environment: 31 | - RABBITMQ_ERLANG_COOKIE=${RABBITMQ_ERLANG_COOKIE} 32 | volumes: 33 | - ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh 34 | entrypoint: /usr/local/bin/cluster-entrypoint.sh 35 | 36 | haproxy: 37 | image: haproxy:1.7 38 | volumes: 39 | - ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro 40 | depends_on: 41 | - rabbitmq1 42 | - rabbitmq2 43 | - rabbitmq3 44 | ports: 45 | - 15672:15672 46 | - 5672:5672 47 | -------------------------------------------------------------------------------- /haproxy.cfg: -------------------------------------------------------------------------------- 1 | global 2 | log 127.0.0.1 local1 3 | maxconn 4096 4 | 5 | defaults 6 | log global 7 | mode tcp 8 | option tcplog 9 | retries 3 10 | option redispatch 11 | maxconn 2000 12 | timeout connect 5000 13 | timeout client 50000 14 | timeout server 50000 15 | 16 | listen stats 17 | bind *:1936 18 | mode http 19 | stats enable 20 | stats hide-version 21 | stats realm Haproxy\ Statistics 22 | stats uri / 23 | 24 | listen rabbitmq 25 | bind *:5672 26 | mode tcp 27 | balance roundrobin 28 | timeout client 3h 29 | timeout server 3h 30 | option clitcpka 31 | server rabbitmq1 rabbitmq1:5672 check inter 5s rise 2 fall 3 32 | server rabbitmq2 rabbitmq2:5672 check inter 5s rise 2 fall 3 33 | server rabbitmq3 rabbitmq3:5672 check inter 5s rise 2 fall 3 34 | 35 | listen mgmt 36 | bind *:15672 37 | mode tcp 38 | balance roundrobin 39 | timeout client 3h 40 | timeout server 3h 41 | option clitcpka 42 | server rabbitmq1 rabbitmq1:15672 check inter 5s rise 2 fall 3 43 | server rabbitmq2 rabbitmq2:15672 check inter 5s rise 2 fall 3 44 | server rabbitmq3 rabbitmq3:15672 check inter 5s rise 2 fall 3 --------------------------------------------------------------------------------