Deploying RabbitMQ Cluster on Debian

This guide explains how to install RabbitMQ on multiple nodes, configure clustering using the classic config method, and ensure all nodes are correctly connected in a RabbitMQ cluster.

Install Dependencies

sudo apt install curl gnupg apt-transport-https -y

Add RabbitMQ Repositories

Create the repository file

sudo vim /etc/apt/sources.list.d/rabbitmq.list

Paste the following content

### Zakops.com
## Provides modern Erlang/OTP releases
deb [arch=amd64 trusted=yes] https://ppa1.rabbitmq.com/rabbitmq/rabbitmq-erlang/deb/debian bookworm main
deb-src [trusted=yes] https://ppa1.rabbitmq.com/rabbitmq/rabbitmq-erlang/deb/debian bookworm main

# another mirror for redundancy
deb [arch=amd64 trusted=yes] https://ppa2.rabbitmq.com/rabbitmq/rabbitmq-erlang/deb/debian bookworm main
deb-src [trusted=yes] https://ppa2.rabbitmq.com/rabbitmq/rabbitmq-erlang/deb/debian bookworm main

## Provides RabbitMQ
deb [arch=amd64 trusted=yes] https://ppa1.rabbitmq.com/rabbitmq/rabbitmq-server/deb/debian bookworm main
deb-src [trusted=yes] https://ppa1.rabbitmq.com/rabbitmq/rabbitmq-server/deb/debian bookworm main

# another mirror for redundancy
deb [arch=amd64 trusted=yes] https://ppa2.rabbitmq.com/rabbitmq/rabbitmq-server/deb/debian bookworm main
deb-src [trusted=yes] https://ppa2.rabbitmq.com/rabbitmq/rabbitmq-server/deb/debian bookworm main

Update and Install Erlang & RabbitMQ

sudo apt update -y
sudo apt upgrade -y

Install Erlang

sudo apt install -y erlang-base \
                        erlang-asn1 erlang-crypto erlang-eldap erlang-ftp erlang-inets \
                        erlang-mnesia erlang-os-mon erlang-parsetools erlang-public-key \
                        erlang-runtime-tools erlang-snmp erlang-ssl \
                        erlang-syntax-tools erlang-tftp erlang-tools erlang-xmerl

Install RabbitMQ

sudo apt install rabbitmq-server -y --fix-missing

Set Hostname Resolution

Edit the /etc/hosts file on all nodes

sudo vim /etc/hosts

Add the following

192.168.100.1    rabbit-1
192.168.100.2    rabbit-2
192.168.100.3    rabbit-3

On the first node

cat /var/lib/rabbitmq/.erlang.cookie

Example

AKOSMIUZADXDWQUEPTWL

Copy this to all nodes

echo "AKOSMIUZADXDWQUEPTWL" | sudo tee /var/lib/rabbitmq/.erlang.cookie
sudo chmod 400 /var/lib/rabbitmq/.erlang.cookie
sudo chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie

Configure the Cluster

sudo vim /etc/rabbitmq/rabbitmq.conf

Add this to all nodes

cluster_formation.peer_discovery_backend = classic_config
cluster_formation.classic_config.nodes.1 = rabbit@rabbit-1
cluster_formation.classic_config.nodes.2 = rabbit@rabbit-2
cluster_formation.classic_config.nodes.3 = rabbit@rabbit-3

Configure the Firewall

Open the following ports in the firewall

5672
25672
4369
15672

Incorrect firewall changes can lead to service disruptions or security breaches.

Join the Cluster

On each node, one at a time

sudo rabbitmqctl stop_app
sudo rabbitmqctl reset
sudo rabbitmqctl start_app

Done!

Your RabbitMQ cluster should now be up and running. Verify it using:

sudo rabbitmqctl cluster_status
Updated on