From 75b23a3fa58492ba9442b54a3a4c5efe46ed9ceb Mon Sep 17 00:00:00 2001 From: tmikulin Date: Mon, 27 Jul 2020 20:31:36 +0200 Subject: [PATCH 01/13] add named volumes to the docker-compose file --- .gitignore | 1 + README.md | 38 +++++++++++++++++++++++++++++++++++++- docker-compose.yml | 17 +++++++++++++---- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 485dee6..eea40b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +rabbitmq-data/* diff --git a/README.md b/README.md index c950507..8bc9b3c 100644 --- a/README.md +++ b/README.md @@ -1 +1,37 @@ -awesome rabbitmq in cluster docker-compose +## Description + +This docker-compose file allows you to create an robust rabbitmq cluster +It uses the [official rabbitmq docker image](https://hub.docker.com/_/rabbitmq?tab=description) + + +### * Note on features + +Starting with the rabbitmq version 3.8.1 because of its SAC capability, namely having multiple consumers on one particular queue but with only one active at a time. + +You can use this docker-compose file on macos and linux machines + +The default image is rabbitmq:3.8.1-management so that you can easily manage your cluster from the web interface + +## General Instructions + +Just clone this repo, and run the following command: + +``` +docker-compose up [-d] +``` + + + +## Release Notes + +### Latest Changes + +### 1.0.0 + +2020-07-27: + +* The starting point is with the docker-compose version 3.7 + +## License + +This project is licensed under the terms of the MIT license. diff --git a/docker-compose.yml b/docker-compose.yml index 88eb14c..9d02586 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,11 @@ -version: 3.7 +version: '3.7' services: rabbit1: image: rabbitmq:3.8.1-management + hostname: rabbit1 + container_name: rabbit1 volumes: - - $PWD/rabbitmq-data:/var/lib/rabbitmq/mnesia/ + - rabbitmq-data:/var/lib/rabbitmq/mnesia/ environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -12,8 +14,10 @@ services: - "15672:15672" rabbit2: image: rabbitmq:3.8.1-management + hostname: rabbit2 + container_name: rabbit2 volumes: - - $PWD/rabbitmq-data:/var/lib/rabbitmq/mnesia/ + - rabbitmq-data:/var/lib/rabbitmq/mnesia/ environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -22,11 +26,16 @@ services: - "15673:15672" rabbit3: image: rabbitmq:3.8.1-management + hostname: rabbit3 + container_name: rabbit3 volumes: - - $PWD/rabbitmq-data:/var/lib/rabbitmq/mnesia/ + - rabbitmq-data:/var/lib/rabbitmq/mnesia/ environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest ports: - "5674:5672" - "15674:15672" + +volumes: + rabbitmq-data: From ddf90ee930f3504771ccb2f64b63d981f856e71f Mon Sep 17 00:00:00 2001 From: tmikulin Date: Mon, 27 Jul 2020 20:51:15 +0200 Subject: [PATCH 02/13] add more info to documentation --- README.md | 7 ++++--- docker-compose.yml | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8bc9b3c..ab7c261 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,17 @@ ## Description This docker-compose file allows you to create an robust rabbitmq cluster -It uses the [official rabbitmq docker image](https://hub.docker.com/_/rabbitmq?tab=description) + +It uses the [official rabbitmq docker image](https://hub.docker.com/_/rabbitmq?tab=description) :rocket: ### * Note on features -Starting with the rabbitmq version 3.8.1 because of its SAC capability, namely having multiple consumers on one particular queue but with only one active at a time. +Starting with the **rabbitmq version 3.8.1** because of its SAC capability, namely having multiple consumers on one particular queue but with only one active at a time. You can use this docker-compose file on macos and linux machines -The default image is rabbitmq:3.8.1-management so that you can easily manage your cluster from the web interface +The default image is **rabbitmq:3.8.1-management** so that you can easily manage your cluster from the web interface ## General Instructions diff --git a/docker-compose.yml b/docker-compose.yml index 9d02586..e77b397 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ services: environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest + - RABBITMQ_ERLANG_COOKIE=asdflw23r2kemcald ports: - "5672:5672" - "15672:15672" @@ -21,6 +22,7 @@ services: environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest + - RABBITMQ_ERLANG_COOKIE=asdflw23r2kemcald ports: - "5673:5672" - "15673:15672" @@ -33,6 +35,7 @@ services: environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest + - RABBITMQ_ERLANG_COOKIE=asdflw23r2kemcald ports: - "5674:5672" - "15674:15672" From 4af3211e640e777c945e1d56aaf62a32b705ca44 Mon Sep 17 00:00:00 2001 From: tmikulin Date: Wed, 29 Jul 2020 22:10:01 +0200 Subject: [PATCH 03/13] WIP with some new files --- Dockerfile | 2 ++ README.md | 3 +++ create_cluster.sh | 25 +++++++++++++++++++ docker-compose.yml | 18 ++++++++++++++ prepare_cluster.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 Dockerfile create mode 100755 create_cluster.sh create mode 100755 prepare_cluster.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..de28edb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,2 @@ +FROM debian:buster-slim + diff --git a/README.md b/README.md index ab7c261..a4a289c 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,9 @@ You can use this docker-compose file on macos and linux machines The default image is **rabbitmq:3.8.1-management** so that you can easily manage your cluster from the web interface + - HA policy + - + ## General Instructions Just clone this repo, and run the following command: diff --git a/create_cluster.sh b/create_cluster.sh new file mode 100755 index 0000000..bd064c4 --- /dev/null +++ b/create_cluster.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +# setup the HA mode on rabbit1 (master) node +docker exec -it rabbit1 rabbitmqctl + +# these specific command are for the "slave nodes/containers" only +docker exec -it rabbit2 rabbitmqctl stop_app + +docker exec -it rabbit2 rabbitmqctl reset + +docker exec -it rabbit2 rabbitmqctl join_cluster rabbit@rabbit1 + +docker exec -it rabbit2 rabbitmqctl start_app + + + +# if I will use a side container for the cluster management part + - it will need rabbitmqctl command on different containers... + - have to wait and know when every node is up and ready for taking commands.... + +# on the master, wait until is up and add the ha mode command on it +# in the slave, wait until is up and join them to the cluster.... +# check if the slaves need to join to the cluster after... + +# or just run the script from the host machine :) diff --git a/docker-compose.yml b/docker-compose.yml index e77b397..26f415d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,9 @@ services: container_name: rabbit1 volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ + - type: bind + source: $PWD/prepare_cluster.sh + target: /prepare_cluster.sh environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -19,6 +22,9 @@ services: container_name: rabbit2 volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ + - type: bind + source: $PWD/prepare_cluster.sh + target: /prepare_cluster.sh environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -26,12 +32,17 @@ services: ports: - "5673:5672" - "15673:15672" + depends_on: + - rabbit1 rabbit3: image: rabbitmq:3.8.1-management hostname: rabbit3 container_name: rabbit3 volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ + - type: bind + source: $PWD/prepare_cluster.sh + target: /prepare_cluster.sh environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -39,6 +50,13 @@ services: ports: - "5674:5672" - "15674:15672" + depends_on: + - rabbit1 + management: + image: debian:buster-slim + hostname: side-container + container_name: side-container + tty: true volumes: rabbitmq-data: diff --git a/prepare_cluster.sh b/prepare_cluster.sh new file mode 100755 index 0000000..e78a39f --- /dev/null +++ b/prepare_cluster.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +set -e + +echo "Starting the rabbitmq server bras..." +#rabbitmq-server & + +sleep 3 + +until &>/dev/null /dev/tcp/localhost/5672 +#do +# echo "Waiting for the rabbitmq server to wake up..." +# sleep 0.5 +#done + +#for (( ; ; )) ; do +# sleep 5 +# rabbitmqctl -q node_health_check > /dev/null 2>&1 +# if [ $? -eq 0 ] ; then +# echo "$0 `date` rabbitmq is now running" +# break +# else +# echo "$0 `date` waiting for rabbitmq startup" +# fi +#done + +#echo "The rabbitmq server started..." +#sleep 10 +## setup the HA policy on the "master node/container" +## if you have a lot of slave node you may want to use ha-mode: exactly +#if [ $HOSTNAME == "rabbit1" ]; +#then +# rabbitmqctl set_policy ha-all "^ha\." '{"ha-mode":"all", "ha-sync-mode":"automatic"}' +# echo "The policy ha-mode was successfully applied to the rabbitmq cluster" +#fi + + + + +#sleep 0.5 +# +if [ $HOSTNAME != "rabbit1" ]; +then + # these specific command are for the "slave nodes/containers" only + rabbitmqctl stop_app + sleep 1 + rabbitmqctl reset + sleep 1 + rabbitmqctl join_cluster rabbit@rabbit1 + sleep 1 + rabbitmqctl start_app + echo "Successfully joined the node $HOSTNAME to the rabbitmq cluster!" +fi From 2d9670379016d83eb768d68eef0a46b2172be579 Mon Sep 17 00:00:00 2001 From: tmikulin Date: Thu, 30 Jul 2020 20:23:15 +0200 Subject: [PATCH 04/13] add the first working draft for the create_cluster script --- create_cluster.sh | 52 +++++++++++++++++++++++++--------------- docker-compose.yml | 14 ----------- prepare_cluster.sh | 60 ---------------------------------------------- 3 files changed, 33 insertions(+), 93 deletions(-) delete mode 100755 prepare_cluster.sh diff --git a/create_cluster.sh b/create_cluster.sh index bd064c4..b5f988e 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -1,25 +1,39 @@ #!/usr/bin/env bash -# setup the HA mode on rabbit1 (master) node -docker exec -it rabbit1 rabbitmqctl - -# these specific command are for the "slave nodes/containers" only -docker exec -it rabbit2 rabbitmqctl stop_app - -docker exec -it rabbit2 rabbitmqctl reset - -docker exec -it rabbit2 rabbitmqctl join_cluster rabbit@rabbit1 +set -e -docker exec -it rabbit2 rabbitmqctl start_app +# define all the slave nodes here +# just make sure you always have an quorum +# 3,5,7 of nodes including the master +slaves=(rabbit2 rabbit3) +# check until rabbit1/master is up +while ! nc -z localhost 5672; +do + echo "Waiting for rabbit1 to wake up...."; + sleep 1; +done; +echo "Rabbit1 node is up and ready for the incoming command..." -# if I will use a side container for the cluster management part - - it will need rabbitmqctl command on different containers... - - have to wait and know when every node is up and ready for taking commands.... - -# on the master, wait until is up and add the ha mode command on it -# in the slave, wait until is up and join them to the cluster.... -# check if the slaves need to join to the cluster after... - -# or just run the script from the host machine :) +# setup the HA mode on rabbit1 (master) node +docker exec -it rabbit1 rabbitmqctl set_policy ha-all "^ha\." '{"ha-mode":"all", "ha-sync-mode":"automatic"}' + +echo "The HA policy was successfully executed on the master rabbit1 node!" + +while ! (nc -z localhost 5673 && nc -z localhost 5674); +do + echo "Waiting for for the rabbit slave to wake up...." + sleep 1 +done + +# these specific commands are for the "slave nodes/containers" ONLY +for slave in ${slaves[*]}; do + docker exec -it "$slave" rabbitmqctl stop_app + sleep 1 + docker exec -it "$slave" rabbitmqctl reset + sleep 1 + docker exec -it "$slave" rabbitmqctl join_cluster rabbit@rabbit1 + sleep 2 + docker exec -it "$slave" rabbitmqctl start_app +done \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 26f415d..f38c9be 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,9 +6,6 @@ services: container_name: rabbit1 volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ - - type: bind - source: $PWD/prepare_cluster.sh - target: /prepare_cluster.sh environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -22,9 +19,6 @@ services: container_name: rabbit2 volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ - - type: bind - source: $PWD/prepare_cluster.sh - target: /prepare_cluster.sh environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -40,9 +34,6 @@ services: container_name: rabbit3 volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ - - type: bind - source: $PWD/prepare_cluster.sh - target: /prepare_cluster.sh environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -52,11 +43,6 @@ services: - "15674:15672" depends_on: - rabbit1 - management: - image: debian:buster-slim - hostname: side-container - container_name: side-container - tty: true volumes: rabbitmq-data: diff --git a/prepare_cluster.sh b/prepare_cluster.sh deleted file mode 100755 index e78a39f..0000000 --- a/prepare_cluster.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash - -set -e - -echo "Starting the rabbitmq server bras..." -#rabbitmq-server & - -sleep 3 - -until &>/dev/null /dev/tcp/localhost/5672 -#do -# echo "Waiting for the rabbitmq server to wake up..." -# sleep 0.5 -#done - -#for (( ; ; )) ; do -# sleep 5 -# rabbitmqctl -q node_health_check > /dev/null 2>&1 -# if [ $? -eq 0 ] ; then -# echo "$0 `date` rabbitmq is now running" -# break -# else -# echo "$0 `date` waiting for rabbitmq startup" -# fi -#done - -#echo "The rabbitmq server started..." -#sleep 10 -## setup the HA policy on the "master node/container" -## if you have a lot of slave node you may want to use ha-mode: exactly -#if [ $HOSTNAME == "rabbit1" ]; -#then -# rabbitmqctl set_policy ha-all "^ha\." '{"ha-mode":"all", "ha-sync-mode":"automatic"}' -# echo "The policy ha-mode was successfully applied to the rabbitmq cluster" -#fi - - - - -#sleep 0.5 -# -if [ $HOSTNAME != "rabbit1" ]; -then - # these specific command are for the "slave nodes/containers" only - rabbitmqctl stop_app - sleep 1 - rabbitmqctl reset - sleep 1 - rabbitmqctl join_cluster rabbit@rabbit1 - sleep 1 - rabbitmqctl start_app - echo "Successfully joined the node $HOSTNAME to the rabbitmq cluster!" -fi From 2d93f8e148ec3c6d809ead4e48b317f39c369a48 Mon Sep 17 00:00:00 2001 From: tmikulin Date: Thu, 30 Jul 2020 21:30:13 +0200 Subject: [PATCH 05/13] add more logic to the create cluster script --- create_cluster.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/create_cluster.sh b/create_cluster.sh index b5f988e..ec83508 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -8,14 +8,25 @@ set -e slaves=(rabbit2 rabbit3) # check until rabbit1/master is up -while ! nc -z localhost 5672; -do - echo "Waiting for rabbit1 to wake up...."; - sleep 1; -done; +#while ! nc -z localhost 15672; +#do +# echo "Waiting for rabbit1 to wake up...."; +# sleep 1; +#done; -echo "Rabbit1 node is up and ready for the incoming command..." +while : +do + echo "Checking rabbit1 for connectivity.." + if docker exec -it rabbit1 rabbitmqctl -q node_health_check; + then + echo "Rabbit1 node is up and ready for the incoming command..." + break + else + sleep 1 + fi +done +sleep 2 # setup the HA mode on rabbit1 (master) node docker exec -it rabbit1 rabbitmqctl set_policy ha-all "^ha\." '{"ha-mode":"all", "ha-sync-mode":"automatic"}' From bbe064c23ba2272c0e122763d3dff22525a92f5c Mon Sep 17 00:00:00 2001 From: tmikulin Date: Sun, 2 Aug 2020 18:20:36 +0200 Subject: [PATCH 06/13] add more concise logic to the create cluster script --- create_cluster.sh | 93 +++++++++++++++++++++++++--------------------- docker-compose.yml | 9 +++++ rabbitmq.conf | 1 + 3 files changed, 61 insertions(+), 42 deletions(-) create mode 100644 rabbitmq.conf diff --git a/create_cluster.sh b/create_cluster.sh index ec83508..71df71c 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -4,47 +4,56 @@ set -e # define all the slave nodes here # just make sure you always have an quorum -# 3,5,7 of nodes including the master -slaves=(rabbit2 rabbit3) - -# check until rabbit1/master is up -#while ! nc -z localhost 15672; -#do -# echo "Waiting for rabbit1 to wake up...."; -# sleep 1; -#done; - -while : -do - echo "Checking rabbit1 for connectivity.." - if docker exec -it rabbit1 rabbitmqctl -q node_health_check; - then - echo "Rabbit1 node is up and ready for the incoming command..." - break - else - sleep 1 - fi -done - -sleep 2 -# setup the HA mode on rabbit1 (master) node -docker exec -it rabbit1 rabbitmqctl set_policy ha-all "^ha\." '{"ha-mode":"all", "ha-sync-mode":"automatic"}' - -echo "The HA policy was successfully executed on the master rabbit1 node!" - -while ! (nc -z localhost 5673 && nc -z localhost 5674); -do - echo "Waiting for for the rabbit slave to wake up...." - sleep 1 +# 3,5,7... of nodes including the master +rabbits=(rabbit1 rabbit2 rabbit3) + +for rabbit in ${rabbits[*]}; do + while : + do + echo "Checking rabbit nodes for connectivity.." + if docker exec -it "$rabbit" rabbitmqctl -q node_health_check; + then + echo "$rabbit is up and ready for the incoming commands..." + if [ "$rabbit" == "rabbit1" ]; + then + sleep 2 + # setup the HA mode on the rabbit1 (master) node + docker exec -it "$rabbit" rabbitmqctl set_policy ha-all "^ha\." '{"ha-mode":"all", "ha-sync-mode":"automatic"}' + break + else + # join the slave nodes to the cluster + docker exec -it "$rabbit" rabbitmqctl stop_app + sleep 1 + docker exec -it "$rabbit" rabbitmqctl reset + sleep 1 + docker exec -it "$rabbit" rabbitmqctl join_cluster rabbit@rabbit1 + sleep 2 + docker exec -it "$rabbit" rabbitmqctl start_app + break + fi + else + sleep 1 + fi + done done -# these specific commands are for the "slave nodes/containers" ONLY -for slave in ${slaves[*]}; do - docker exec -it "$slave" rabbitmqctl stop_app - sleep 1 - docker exec -it "$slave" rabbitmqctl reset - sleep 1 - docker exec -it "$slave" rabbitmqctl join_cluster rabbit@rabbit1 - sleep 2 - docker exec -it "$slave" rabbitmqctl start_app -done \ No newline at end of file +#for slave in ${slaves[*]}; do +# while : +# do +# echo "Checking rabbit1 for connectivity.." +# if docker exec -it "$slave" rabbitmqctl -q node_health_check; +# then +# echo "$slave is up and ready for the incoming commands..." +# docker exec -it "$slave" rabbitmqctl stop_app +# sleep 1 +# docker exec -it "$slave" rabbitmqctl reset +# sleep 1 +# docker exec -it "$slave" rabbitmqctl join_cluster rabbit@rabbit1 +# sleep 2 +# docker exec -it "$slave" rabbitmqctl start_app +# break +# else +# sleep 1 +# fi +# done +#done diff --git a/docker-compose.yml b/docker-compose.yml index f38c9be..0503c38 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,9 @@ services: container_name: rabbit1 volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ + - type: bind + source: $PWD/rabbitmq.conf + target: /etc/rabbitmq/rabbitmq.conf environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -19,6 +22,9 @@ services: container_name: rabbit2 volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ + - type: bind + source: $PWD/rabbitmq.conf + target: /etc/rabbitmq/rabbitmq.conf environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -34,6 +40,9 @@ services: container_name: rabbit3 volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ + - type: bind + source: $PWD/rabbitmq.conf + target: /etc/rabbitmq/rabbitmq.conf environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest diff --git a/rabbitmq.conf b/rabbitmq.conf new file mode 100644 index 0000000..b377b07 --- /dev/null +++ b/rabbitmq.conf @@ -0,0 +1 @@ +cluster_partition_handling = pause_minority \ No newline at end of file From 72e292ced2a3ff00219de409f6307ba0e8de597d Mon Sep 17 00:00:00 2001 From: tmikulin Date: Mon, 3 Aug 2020 15:35:58 +0200 Subject: [PATCH 07/13] add new conf file for handling the partition failure --- .rabbitmq/rabbitmq.conf | 4 ++++ advanced.config | 8 ++++++++ create_cluster.sh | 2 +- docker-compose.yml | 13 +++++++------ rabbitmq.conf | 1 - 5 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 .rabbitmq/rabbitmq.conf create mode 100644 advanced.config delete mode 100644 rabbitmq.conf diff --git a/.rabbitmq/rabbitmq.conf b/.rabbitmq/rabbitmq.conf new file mode 100644 index 0000000..59b729f --- /dev/null +++ b/.rabbitmq/rabbitmq.conf @@ -0,0 +1,4 @@ +loopback_users.guest = false +listeners.tcp.default = 5672 +default_pass = guest +default_user = guest diff --git a/advanced.config b/advanced.config new file mode 100644 index 0000000..993cff8 --- /dev/null +++ b/advanced.config @@ -0,0 +1,8 @@ +[ + { rabbit, + [ + {cluster_partition_handling, pause_minority} + ] + } +]. + diff --git a/create_cluster.sh b/create_cluster.sh index 71df71c..c1cd09a 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -18,7 +18,7 @@ for rabbit in ${rabbits[*]}; do then sleep 2 # setup the HA mode on the rabbit1 (master) node - docker exec -it "$rabbit" rabbitmqctl set_policy ha-all "^ha\." '{"ha-mode":"all", "ha-sync-mode":"automatic"}' + docker exec -it "$rabbit" rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all", "ha-sync-mode":"automatic"}' break else # join the slave nodes to the cluster diff --git a/docker-compose.yml b/docker-compose.yml index 0503c38..44b3d0a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,11 +4,12 @@ services: image: rabbitmq:3.8.1-management hostname: rabbit1 container_name: rabbit1 + user: rabbitmq volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ - type: bind - source: $PWD/rabbitmq.conf - target: /etc/rabbitmq/rabbitmq.conf + source: $PWD/advanced.config + target: /etc/rabbitmq/advanced.config environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -23,8 +24,8 @@ services: volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ - type: bind - source: $PWD/rabbitmq.conf - target: /etc/rabbitmq/rabbitmq.conf + source: $PWD/advanced.config + target: /etc/rabbitmq/advanced.config environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest @@ -41,8 +42,8 @@ services: volumes: - rabbitmq-data:/var/lib/rabbitmq/mnesia/ - type: bind - source: $PWD/rabbitmq.conf - target: /etc/rabbitmq/rabbitmq.conf + source: $PWD/advanced.config + target: /etc/rabbitmq/advanced.config environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest diff --git a/rabbitmq.conf b/rabbitmq.conf deleted file mode 100644 index b377b07..0000000 --- a/rabbitmq.conf +++ /dev/null @@ -1 +0,0 @@ -cluster_partition_handling = pause_minority \ No newline at end of file From bdcebedad86e13333630e1dac3652f21f18ee360 Mon Sep 17 00:00:00 2001 From: tmikulin Date: Mon, 3 Aug 2020 15:47:54 +0200 Subject: [PATCH 08/13] remove redundand files and code --- Dockerfile | 2 -- create_cluster.sh | 21 --------------------- 2 files changed, 23 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index de28edb..0000000 --- a/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM debian:buster-slim - diff --git a/create_cluster.sh b/create_cluster.sh index c1cd09a..07e25c3 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -36,24 +36,3 @@ for rabbit in ${rabbits[*]}; do fi done done - -#for slave in ${slaves[*]}; do -# while : -# do -# echo "Checking rabbit1 for connectivity.." -# if docker exec -it "$slave" rabbitmqctl -q node_health_check; -# then -# echo "$slave is up and ready for the incoming commands..." -# docker exec -it "$slave" rabbitmqctl stop_app -# sleep 1 -# docker exec -it "$slave" rabbitmqctl reset -# sleep 1 -# docker exec -it "$slave" rabbitmqctl join_cluster rabbit@rabbit1 -# sleep 2 -# docker exec -it "$slave" rabbitmqctl start_app -# break -# else -# sleep 1 -# fi -# done -#done From 652718c25ba6ee3dc68c6ea1ac372645241a5183 Mon Sep 17 00:00:00 2001 From: tmikulin Date: Mon, 3 Aug 2020 16:49:39 +0200 Subject: [PATCH 09/13] update the readme with consice info --- README.md | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a4a289c..9893591 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,39 @@ ## Description -This docker-compose file allows you to create an robust rabbitmq cluster +This docker-compose file allows you to create an robust rabbitmq cluster for local development It uses the [official rabbitmq docker image](https://hub.docker.com/_/rabbitmq?tab=description) :rocket: ### * Note on features -Starting with the **rabbitmq version 3.8.1** because of its SAC capability, namely having multiple consumers on one particular queue but with only one active at a time. +The default version is the **rabbitmq version 3.8.1** because of its SAC capability, namely having multiple consumers on one particular queue but with only one active at a time. -You can use this docker-compose file on macos and linux machines +Tested on macOS Sierra (version 10.12.6) and Ubuntu 18 -The default image is **rabbitmq:3.8.1-management** so that you can easily manage your cluster from the web interface +I needed an local rabbitmq cluster with these defaults for development purposes, but they are all easily customizable: - - HA policy - - + - ha policy (mirroring of queues on all nodes) + - pause minority as the partition handling strategy (because s*** happens and you need to be prepared) + ## General Instructions -Just clone this repo, and run the following command: +Just clone this repo, and run the following commands: ``` -docker-compose up [-d] +chmod +x ./create_cluster.sh + +docker-compose up -d && ./create_cluster.sh +or +docker-compose up +./create_cluster.sh ``` +The bash script joins the slave nodes to the cluster and it just needs to run once, +on every other usage just run the compose file. +My intent was not to change the original rabbitmq docker image, but just boost it a little to create a practical rabbitmq cluster. ## Release Notes From 126b8f4591cc0541cac94234f3b6f6d95984f64a Mon Sep 17 00:00:00 2001 From: tmikulin Date: Wed, 5 Aug 2020 12:24:31 +0200 Subject: [PATCH 10/13] add the default .env file for env vars --- .env | 4 ++++ create_cluster.sh | 2 +- docker-compose.yml | 24 ++++++++++++------------ 3 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..226bc9a --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +RABBIT_VERSION=3.8.1 +RABBIT_COOKIE=asdflw23r2kemcald +RABBIT_USER=guest +RABBIT_PASS=guest diff --git a/create_cluster.sh b/create_cluster.sh index 07e25c3..fbf43d3 100755 --- a/create_cluster.sh +++ b/create_cluster.sh @@ -4,7 +4,7 @@ set -e # define all the slave nodes here # just make sure you always have an quorum -# 3,5,7... of nodes including the master +# 3,5,7... of nodes including the master node (rabbit1) rabbits=(rabbit1 rabbit2 rabbit3) for rabbit in ${rabbits[*]}; do diff --git a/docker-compose.yml b/docker-compose.yml index 44b3d0a..5a0ec94 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3.7' services: rabbit1: - image: rabbitmq:3.8.1-management + image: rabbitmq:${RABBIT_VERSION}-management hostname: rabbit1 container_name: rabbit1 user: rabbitmq @@ -11,14 +11,14 @@ services: source: $PWD/advanced.config target: /etc/rabbitmq/advanced.config environment: - - RABBITMQ_DEFAULT_USER=guest - - RABBITMQ_DEFAULT_PASS=guest - - RABBITMQ_ERLANG_COOKIE=asdflw23r2kemcald + - RABBITMQ_DEFAULT_USER=${RABBIT_USER} + - RABBITMQ_DEFAULT_PASS=${RABBIT_PASS} + - RABBITMQ_ERLANG_COOKIE=${RABBIT_COOKIE} ports: - "5672:5672" - "15672:15672" rabbit2: - image: rabbitmq:3.8.1-management + image: rabbitmq:${RABBIT_VERSION}-management hostname: rabbit2 container_name: rabbit2 volumes: @@ -27,16 +27,16 @@ services: source: $PWD/advanced.config target: /etc/rabbitmq/advanced.config environment: - - RABBITMQ_DEFAULT_USER=guest - - RABBITMQ_DEFAULT_PASS=guest - - RABBITMQ_ERLANG_COOKIE=asdflw23r2kemcald + - RABBITMQ_DEFAULT_USER=${RABBIT_USER} + - RABBITMQ_DEFAULT_PASS=${RABBIT_PASS} + - RABBITMQ_ERLANG_COOKIE=${RABBIT_COOKIE} ports: - "5673:5672" - "15673:15672" depends_on: - rabbit1 rabbit3: - image: rabbitmq:3.8.1-management + image: rabbitmq:${RABBIT_VERSION}-management hostname: rabbit3 container_name: rabbit3 volumes: @@ -45,9 +45,9 @@ services: source: $PWD/advanced.config target: /etc/rabbitmq/advanced.config environment: - - RABBITMQ_DEFAULT_USER=guest - - RABBITMQ_DEFAULT_PASS=guest - - RABBITMQ_ERLANG_COOKIE=asdflw23r2kemcald + - RABBITMQ_DEFAULT_USER=${RABBIT_USER} + - RABBITMQ_DEFAULT_PASS=${RABBIT_PASS} + - RABBITMQ_ERLANG_COOKIE=${RABBIT_COOKIE} ports: - "5674:5672" - "15674:15672" From cdca97157d96cd09c50c1de24a5b13be5074f4fd Mon Sep 17 00:00:00 2001 From: Tomislav Mikulin Date: Wed, 5 Aug 2020 12:57:44 +0200 Subject: [PATCH 11/13] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4a94a78 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Tomislav Mikulin + +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. From d4a4b7cf86d2ccc59d91c5948ab9feca4e399de1 Mon Sep 17 00:00:00 2001 From: tmikulin Date: Wed, 5 Aug 2020 13:38:47 +0200 Subject: [PATCH 12/13] remove unwanted code and refactor the README --- .gitignore | 1 - .rabbitmq/rabbitmq.conf | 4 ---- LICENSE => LICENSE.md | 0 README.md | 20 ++++++++++---------- 4 files changed, 10 insertions(+), 15 deletions(-) delete mode 100644 .rabbitmq/rabbitmq.conf rename LICENSE => LICENSE.md (100%) diff --git a/.gitignore b/.gitignore index eea40b0..485dee6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ .idea -rabbitmq-data/* diff --git a/.rabbitmq/rabbitmq.conf b/.rabbitmq/rabbitmq.conf deleted file mode 100644 index 59b729f..0000000 --- a/.rabbitmq/rabbitmq.conf +++ /dev/null @@ -1,4 +0,0 @@ -loopback_users.guest = false -listeners.tcp.default = 5672 -default_pass = guest -default_user = guest diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/README.md b/README.md index 9893591..6532408 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,18 @@ ## Description -This docker-compose file allows you to create an robust rabbitmq cluster for local development +This docker-compose file allows you to create an **rabbitmq cluster** for local development or testing It uses the [official rabbitmq docker image](https://hub.docker.com/_/rabbitmq?tab=description) :rocket: ### * Note on features -The default version is the **rabbitmq version 3.8.1** because of its SAC capability, namely having multiple consumers on one particular queue but with only one active at a time. +The default version is the **rabbitmq version 3.8.1** because of its [SAC capability](https://www.cloudamqp.com/blog/2019-04-23-rabbitmq-3-8-feature-focus-single-active-consumer.html), namely having multiple consumers on one particular queue but with only one active at a time. -Tested on macOS Sierra (version 10.12.6) and Ubuntu 18 - -I needed an local rabbitmq cluster with these defaults for development purposes, but they are all easily customizable: +The compose file is setup with sane defaults that you can change (.env file), and the `bash script + advenced.config` with the added modifications for the cluster configuration: - - ha policy (mirroring of queues on all nodes) - - pause minority as the partition handling strategy (because s*** happens and you need to be prepared) + - `ha policy` (mirroring of queues on all nodes) + - `pause minority` as the partition handling strategy (because s*** happens :fire: and you need to be prepared) ## General Instructions @@ -30,10 +28,12 @@ docker-compose up ./create_cluster.sh ``` -The bash script joins the slave nodes to the cluster and it just needs to run once, +The bash script joins the slave nodes to the cluster and it just needs to `run once` :warning:, on every other usage just run the compose file. -My intent was not to change the original rabbitmq docker image, but just boost it a little to create a practical rabbitmq cluster. +My intent was not to change the original rabbitmq docker image, but just boost it a little to create a `practical rabbitmq cluster`. + +Tested on macOS Sierra (version 10.12.6) and Ubuntu 18 ## Release Notes @@ -41,7 +41,7 @@ My intent was not to change the original rabbitmq docker image, but just boost i ### 1.0.0 -2020-07-27: +2020-08-05: * The starting point is with the docker-compose version 3.7 From 3ad4bb7c899b9100d93b4e3c36e66aa566a49f74 Mon Sep 17 00:00:00 2001 From: tmikulin Date: Wed, 5 Aug 2020 16:59:28 +0200 Subject: [PATCH 13/13] update the documentation with correct release --- README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6532408..43ed9ff 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It uses the [official rabbitmq docker image](https://hub.docker.com/_/rabbitmq?t The default version is the **rabbitmq version 3.8.1** because of its [SAC capability](https://www.cloudamqp.com/blog/2019-04-23-rabbitmq-3-8-feature-focus-single-active-consumer.html), namely having multiple consumers on one particular queue but with only one active at a time. -The compose file is setup with sane defaults that you can change (.env file), and the `bash script + advenced.config` with the added modifications for the cluster configuration: +The compose file is setup with sane defaults that you can change (.env file), and the `bash script + advanced.config` with the added modifications for the cluster configuration: - `ha policy` (mirroring of queues on all nodes) - `pause minority` as the partition handling strategy (because s*** happens :fire: and you need to be prepared) @@ -33,17 +33,22 @@ on every other usage just run the compose file. My intent was not to change the original rabbitmq docker image, but just boost it a little to create a `practical rabbitmq cluster`. -Tested on macOS Sierra (version 10.12.6) and Ubuntu 18 +Tested on macOS Sierra (version 10.12.6) and Ubuntu/Kubuntu 18 +``` +docker version 19.03.8/11 +docker-compose 1.22.0/1.25.5 +``` + ## Release Notes ### Latest Changes -### 1.0.0 +### 1.0.0-rc.1 2020-08-05: -* The starting point is with the docker-compose version 3.7 +* The starting point is with the rabbitmq version 3.8.1 ## License