Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
serkodev committed May 16, 2022
0 parents commit 9826368
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RABBITMQ_DEFAULT_USER=guest
RABBITMQ_DEFAULT_PASS=guest
RABBITMQ_DEFAULT_VHOST=/
1 change: 1 addition & 0 deletions .erlang.cookie
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
12345
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 SerKo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# RabbitMQ Cluster Docker

Setup a RabbitMQ Cluster environment on your device using the pure [RabbitMQ](https://hub.docker.com/_/rabbitmq/) official docker image with Docker Compose.

## Features

- Super easy setup, config and expand
- Use a purely official RabbitMQ image
- Support latest version, optimized for Erlang cookie config
- Build-in HAProxy load balancing

## Quick start

```
docker compose up
```

## Configuration

### `docker-compose.yml`

Docker [compose](https://docs.docker.com/compose/compose-file/) config file, including 3 RabbitMQ service cluster and a HAProxy.

| Service | Description |
| ----------- | ------------------------- |
| `rabbitmq1` | RabbitMQ (cluster) |
| `rabbitmq2` | RabbitMQ (cluster member) |
| `rabbitmq3` | RabbitMQ (cluster member) |
| `haproxy` | Load Balancer |

### `.env`

| Name | Default |
| ------------------------ | ------- |
| `RABBITMQ_DEFAULT_USER` | guest |
| `RABBITMQ_DEFAULT_PASS` | guest |
| `RABBITMQ_DEFAULT_VHOST` | / |

### `.erlang.cookie`

Put your custom [Erlang Cookie](https://www.rabbitmq.com/clustering.html#erlang-cookie) inside this file (default: `12345`) for the nodes in cluster communicate with each other.

### `haproxy.cfg`

Load balancer [HA Proxy](http://www.haproxy.org/) config. Including the load balancing config and the hostnames of the nodes in cluster.

## References

- [docker-rabbitmq-cluster](https://github.com/pardahlman/docker-rabbitmq-cluster)
- [rabbitmq-cluster](https://github.com/JohnnyVicious/rabbitmq-cluster)

## LICENSE

MIT
26 changes: 26 additions & 0 deletions cluster-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -e

# Change .erlang.cookie permission
chmod 400 /var/lib/rabbitmq/.erlang.cookie

# Get hostname from enviromant variable
HOSTNAME=`env hostname`
echo "Starting RabbitMQ Server For host: " $HOSTNAME

if [ -z "$JOIN_CLUSTER_HOST" ]; then
/usr/local/bin/docker-entrypoint.sh rabbitmq-server &
sleep 5
rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbit\@$HOSTNAME.pid
else
/usr/local/bin/docker-entrypoint.sh rabbitmq-server -detached
sleep 5
rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbit\@$HOSTNAME.pid
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@$JOIN_CLUSTER_HOST
rabbitmqctl start_app
fi

# Keep foreground process active ...
tail -f /var/log/rabbitmq/*.log
49 changes: 49 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
version: '3'
services:
rabbitmq1:
image: rabbitmq:3-management
hostname: rabbitmq1
environment:
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
- RABBITMQ_DEFAULT_VHOST=${RABBITMQ_DEFAULT_VHOST}
volumes:
- ./.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
entrypoint: /usr/local/bin/cluster-entrypoint.sh

rabbitmq2:
image: rabbitmq:3-management
hostname: rabbitmq2
depends_on:
- rabbitmq1
environment:
- JOIN_CLUSTER_HOST=rabbitmq1
volumes:
- ./.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
entrypoint: /usr/local/bin/cluster-entrypoint.sh

rabbitmq3:
image: rabbitmq:3-management
hostname: rabbitmq3
depends_on:
- rabbitmq1
environment:
- JOIN_CLUSTER_HOST=rabbitmq1
volumes:
- ./.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
entrypoint: /usr/local/bin/cluster-entrypoint.sh

haproxy:
image: haproxy:1.7
volumes:
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
depends_on:
- rabbitmq1
- rabbitmq2
- rabbitmq3
ports:
- 15672:15672
- 5672:5672
44 changes: 44 additions & 0 deletions haproxy.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
global
log 127.0.0.1 local1
maxconn 4096

defaults
log global
mode tcp
option tcplog
retries 3
option redispatch
maxconn 2000
timeout connect 5000
timeout client 50000
timeout server 50000

listen stats
bind *:1936
mode http
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /

listen rabbitmq
bind *:5672
mode tcp
balance roundrobin
timeout client 3h
timeout server 3h
option clitcpka
server rabbitmq1 rabbitmq1:5672 check inter 5s rise 2 fall 3
server rabbitmq2 rabbitmq2:5672 check inter 5s rise 2 fall 3
server rabbitmq3 rabbitmq3:5672 check inter 5s rise 2 fall 3

listen mgmt
bind *:15672
mode tcp
balance roundrobin
timeout client 3h
timeout server 3h
option clitcpka
server rabbitmq1 rabbitmq1:15672 check inter 5s rise 2 fall 3
server rabbitmq2 rabbitmq2:15672 check inter 5s rise 2 fall 3
server rabbitmq3 rabbitmq3:15672 check inter 5s rise 2 fall 3

0 comments on commit 9826368

Please sign in to comment.