Skip to content

Commit 9826368

Browse files
committed
init
0 parents  commit 9826368

File tree

7 files changed

+198
-0
lines changed

7 files changed

+198
-0
lines changed

.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
RABBITMQ_DEFAULT_USER=guest
2+
RABBITMQ_DEFAULT_PASS=guest
3+
RABBITMQ_DEFAULT_VHOST=/

.erlang.cookie

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
12345

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 SerKo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# RabbitMQ Cluster Docker
2+
3+
Setup a RabbitMQ Cluster environment on your device using the pure [RabbitMQ](https://hub.docker.com/_/rabbitmq/) official docker image with Docker Compose.
4+
5+
## Features
6+
7+
- Super easy setup, config and expand
8+
- Use a purely official RabbitMQ image
9+
- Support latest version, optimized for Erlang cookie config
10+
- Build-in HAProxy load balancing
11+
12+
## Quick start
13+
14+
```
15+
docker compose up
16+
```
17+
18+
## Configuration
19+
20+
### `docker-compose.yml`
21+
22+
Docker [compose](https://docs.docker.com/compose/compose-file/) config file, including 3 RabbitMQ service cluster and a HAProxy.
23+
24+
| Service | Description |
25+
| ----------- | ------------------------- |
26+
| `rabbitmq1` | RabbitMQ (cluster) |
27+
| `rabbitmq2` | RabbitMQ (cluster member) |
28+
| `rabbitmq3` | RabbitMQ (cluster member) |
29+
| `haproxy` | Load Balancer |
30+
31+
### `.env`
32+
33+
| Name | Default |
34+
| ------------------------ | ------- |
35+
| `RABBITMQ_DEFAULT_USER` | guest |
36+
| `RABBITMQ_DEFAULT_PASS` | guest |
37+
| `RABBITMQ_DEFAULT_VHOST` | / |
38+
39+
### `.erlang.cookie`
40+
41+
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.
42+
43+
### `haproxy.cfg`
44+
45+
Load balancer [HA Proxy](http://www.haproxy.org/) config. Including the load balancing config and the hostnames of the nodes in cluster.
46+
47+
## References
48+
49+
- [docker-rabbitmq-cluster](https://github.com/pardahlman/docker-rabbitmq-cluster)
50+
- [rabbitmq-cluster](https://github.com/JohnnyVicious/rabbitmq-cluster)
51+
52+
## LICENSE
53+
54+
MIT

cluster-entrypoint.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Change .erlang.cookie permission
6+
chmod 400 /var/lib/rabbitmq/.erlang.cookie
7+
8+
# Get hostname from enviromant variable
9+
HOSTNAME=`env hostname`
10+
echo "Starting RabbitMQ Server For host: " $HOSTNAME
11+
12+
if [ -z "$JOIN_CLUSTER_HOST" ]; then
13+
/usr/local/bin/docker-entrypoint.sh rabbitmq-server &
14+
sleep 5
15+
rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbit\@$HOSTNAME.pid
16+
else
17+
/usr/local/bin/docker-entrypoint.sh rabbitmq-server -detached
18+
sleep 5
19+
rabbitmqctl wait /var/lib/rabbitmq/mnesia/rabbit\@$HOSTNAME.pid
20+
rabbitmqctl stop_app
21+
rabbitmqctl join_cluster rabbit@$JOIN_CLUSTER_HOST
22+
rabbitmqctl start_app
23+
fi
24+
25+
# Keep foreground process active ...
26+
tail -f /var/log/rabbitmq/*.log

docker-compose.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
version: '3'
2+
services:
3+
rabbitmq1:
4+
image: rabbitmq:3-management
5+
hostname: rabbitmq1
6+
environment:
7+
- RABBITMQ_DEFAULT_USER=${RABBITMQ_DEFAULT_USER}
8+
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_DEFAULT_PASS}
9+
- RABBITMQ_DEFAULT_VHOST=${RABBITMQ_DEFAULT_VHOST}
10+
volumes:
11+
- ./.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie
12+
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
13+
entrypoint: /usr/local/bin/cluster-entrypoint.sh
14+
15+
rabbitmq2:
16+
image: rabbitmq:3-management
17+
hostname: rabbitmq2
18+
depends_on:
19+
- rabbitmq1
20+
environment:
21+
- JOIN_CLUSTER_HOST=rabbitmq1
22+
volumes:
23+
- ./.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie
24+
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
25+
entrypoint: /usr/local/bin/cluster-entrypoint.sh
26+
27+
rabbitmq3:
28+
image: rabbitmq:3-management
29+
hostname: rabbitmq3
30+
depends_on:
31+
- rabbitmq1
32+
environment:
33+
- JOIN_CLUSTER_HOST=rabbitmq1
34+
volumes:
35+
- ./.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie
36+
- ./cluster-entrypoint.sh:/usr/local/bin/cluster-entrypoint.sh
37+
entrypoint: /usr/local/bin/cluster-entrypoint.sh
38+
39+
haproxy:
40+
image: haproxy:1.7
41+
volumes:
42+
- ./haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
43+
depends_on:
44+
- rabbitmq1
45+
- rabbitmq2
46+
- rabbitmq3
47+
ports:
48+
- 15672:15672
49+
- 5672:5672

haproxy.cfg

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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

0 commit comments

Comments
 (0)