Moon Light Box

Time is Money

Docker - RabbitMQ Cluster

| Comments

Prepare three nodes.

Node1:10.10.10.10 hostname:rabbitmq01
Node2:10.10.10.11 hostname:rabbitmq02
Node3:10.10.10.12 hostname:rabbitmq03

# docker run -d \
    --hostname rabbitmq01 or rabbitmq02 or rabbitmq03
    --name rabbitmq \
    -e RABBITMQ_ERLANG_COOKIE=2a91315f0f02f94005d94ee5d450cc86 \ // Example:2a91315f0f02f94005d94ee5d450cc86
    -e RABBITMQ_DEFAULT_USER=admin \
    -e RABBITMQ_DEFAULT_PASS=admin \
    -e RABBITMQ_HIPE_COMPILE=1 \
    -p 4369:4369 \
    -p 5672:5672 \
    -p 15672:15672 \
    -p 25672:25672 \
    --add-host rabbitmq01:10.10.10.10 \
    --add-host rabbitmq02:10.10.10.11 \
    --add-host rabbitmq03:10.10.10.12 \
    rabbitmq:3.6.6-management

Add Node2 and Node3 into cluster with Node1.

Node1:10.10.10.10 hostname:rabbitmq01
Node2:10.10.10.11 hostname:rabbitmq02
Node3:10.10.10.12 hostname:rabbitmq03

We need do this in Node2 and Node3, respectively.

# docker exec rabbitmq rabbitmqctl stop_app
# docker exec rabbitmq rabbitmqctl join_cluster rabbit@rabbitmq01
# docker exec rabbitmq rabbitmqctl start_app

Sync all nodes.

Node1:10.10.10.10 hostname:rabbitmq01
Node2:10.10.10.11 hostname:rabbitmq02
Node3:10.10.10.12 hostname:rabbitmq03

We need do this in Node1.

# docker exec rabbitmq rabbitmqctl set_policy ha-all '^(?!amq\.).*' '{"ha-mode": "all"}'
...
...
Setting policy "ha-all" for pattern "^(?!amq\\.).*" to "{\"ha-mode\": \"all\"}" with priority "0" ...

Check status.
# docker exec rabbitmq rabbitmqctl list_policies
...
...
Listing policies ...
/       ha-all  all     ^(?!amq\\.).*   {"ha-mode":"all"}       0

# docker exec -ti rabbitmq rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq01 ...
[{nodes,[{disc,[rabbit@rabbitmq01,rabbit@rabbitmq02,rabbit@rabbitmq03]}]},
 {running_nodes,[rabbit@rabbitmq02,rabbit@rabbitmq03,rabbit@rabbitmq01]},
 {cluster_name,<<"rabbit@rabbitmq01">>},
 {partitions,[]},
 {alarms,[{rabbit@rabbitmq02,[nodedown]},
          {rabbit@rabbitmq03,[nodedown]},
          {rabbit@rabbitmq01,[]}]}]

RabbitMQ Web Console

http://10.10.10.10:15672
Enter admin / admin

http://allexit.blogspot.tw/2016/03/rabbitmq-docker-cluster.html
https://godleon.github.io/blog/2015/06/02/Build-RabbitMQ-Cluster-in-Ubuntu
http://www.rabbitmq.com/clustering.html#auto-config
https://hub.docker.com/_/rabbitmq/

Comments

comments powered by Disqus