Setup RabbitMQ Cluster on Ubuntu 18.045 min read

RabbitMQ is one of the most widely deployed open source message brokers. It is an implementation of the Advanced Message Queuing Protocol (AMQP) and Streaming Text Oriented Messaging Protocol, Message Queueing Telemetry transport and other protocols via a plugin.RabbitMQ is written in the Erlang programming language, it offers support for client interfaces and libraries for all major programming languages including Python, NodeJS, Java, PHP etc.

Now let’s see how to set up a RabbitMQ Cluster on Ubuntu Server.



We need three Ubuntu 18.04 servers, let the IP and hostname be like below.

  • rabbitmq-server01
  • rabbitmq-server02
  • rabbitmq-server03

All these server need root privileges.

Setup Hosts File

In all the three servers we will edit “/etc/hosts” file and map each server IP address as a hostname.

sudo vim /etc/hosts rabbitmq-server01 rabbitmq-server02 rabbitmq-server03

Install RabbitMQ Server

Let’s update all the servers before installing RabbitMQ,run the below command


sudo apt update


Now let’s install RabbitMQ Server using below command.

sudo apt install rabbitmq-server -y

After installing, let’s start and enable the Rabbit MQ Service.


sudo systemctl start rabbitmq-server
sudo systemctl enable rabbitmq-server

Enable RabbitMQ Management Plugins

Let’s enable Rabbit MQ Management plugins that allow us to monitor and handle RabbitMQ server from the web browser, it will be running on 15672 default port.

sudo rabbitmq-plugins enable rabbitmq_management

Make sure there is no error and after that restart the rabbitmq server

sudo systemctl restart rabbitmq-server

Setup UFW Firewall or Open port in Security Groups

Add ssh,tcp ports ‘5672,15672,4369,25672’ and enable firewall service

sudo ufw allow ssh
sudo ufw enable
sudo ufw allow 5672,15672,4369,25672/tcp
Now check the status

sudo ufw status

If we are using Cloud server open these ports between these servers.

Setup RabbitMQ Cluster

We need to make sure the ‘.erlang.cookie’ file is same on all  servers. We will copy the ‘.erlang.cookie’ file on the ‘/var/lib/rabbitmq’ directory from ‘rabbitmq-server01’ to other node ‘rabbitmq-server02’ and ‘rabbitmq-server03’.

scp /var/lib/rabbitmq/.erlang.cookie root@rabbitmq-server02:/var/lib/rabbitmq/
scp /var/lib/rabbitmq/.erlang.cookie root@rabbitmq-server03:/var/lib/rabbitmq/

Now lets join ‘rabbitmq-server02’ and ‘rabbitmq-server03’ into cluster

We will restart RabbitMQ server in both ‘rabbitmq-server02’ and ‘rabbitmq-server03’ and stop the app.

sudo systemctl restart rabbitmq-server
sudo rabbitmqctl stop_app

Now we will join both ‘rabbitmq-server02’ and ‘rabbitmq-server03’  to the cluster ‘rabbitmq-server01’ and start the app.

sudo rabbitmqctl join_cluster rabbit@rabbitmq-server01
sudo rabbitmqctl start_app

Now lets check the status of the RabbitMQ cluster.

sudo rabbitmqctl cluster_status

RabbitMQ Cluster has been created, with rabbitmq-server01, rabbitmq-server02, and rabbitmq-server03 as members.

Setup New Administrator User

Lets create a new admin user for our RabbitMQ server and delete the default ‘guest’ user. New user will be creating from ‘rabbitmq-server01’, and it will be automatically replicated to all nodes on the cluster.

Add a new user named ‘techrunnruser’ with password ‘Qwerty@54321’.

sudo rabbitmqctl add_user techrunnruser Qwerty@54321

Setup the ‘techrunnruser’ user as an administrator.

sudo rabbitmqctl set_user_tags techrunnruser administrator

And grant the ‘techrunnruser’ user permission to modify, write, and read all

sudo rabbitmqctl set_permissions -p / techrunnruser ".*" ".*" ".*"

Now delete the default ‘guest’ user.

sudo rabbitmqctl delete_user guest

And check all available users.

sudo rabbitmqctl list_users

Listing users ...

techrunnrusr	[administrator]
monitoruser	[monitoring]

New RabbitMQ administrator user has been created, and the default ‘guest’ user is deleted.

RabbitMQ HA Policies

By default, contents of a queue within a RabbitMQ cluster are located on a single node (the node on which the queue was declared).

To make all queues HA run this command at master. With this policy enabled RabbitMQ sync all queues to all nodes.

sudo rabbitmqctl set_policy ha-all ".*" '{"ha-mode":"all"}'

Setup ha policy named ‘ha-two’ which all queue name start with ‘two.’ will be mirroring to the two nodes on the cluster.

sudo rabbitmqctl set_policy ha-two "^two\." \

Setup a high availability policy named ‘ha-nodes’ which will contain all queues where the name starts with ‘nodes.’ We will be mirroring to two specific nodes ‘rabbitmq-server02’ and ‘rabbitmq-server03’ in the cluster

sudo rabbitmqctl set_policy ha-nodes "^nodes\." \
   '{"ha-mode":"nodes","ha-params":["rabbit@rabbitmq-server02", "rabbit@rabbitmq-server03"]}'

RabbitMQ list ha policies.

sudo rabbitmqctl list_policies;

RabbitMQ delete specific ha policy.

sudo rabbitmqctl clear_policy ha-two

Now Open in Browser and type the IP address of the server with port “15672”

Now provide the username password.


rabbitmq cluster


Rabbit MQ Server Dashboard

The installation and configuration of RabbitMQ Cluster on Ubuntu 18.04 servers have been completed successfully.

RabbitMQ server setup for Standalone server,visit the below link.
How to install RabbitMQ Server On Ubuntu 18.04

Devops Engineer
Sorry! The Author has not filled his profile.
follow me
We need your support!!
Other Amount:
Questions Answered
Articles Written
Overall Points

Praseeb K Das

Techinal engineer,who works with passion what he does and ready to leran more and share the knoweldge. Keep learning.....

You may also like...

Leave a Reply