Rabbitmq Cluster on CentOS 7

Step 0. Prelimenaries

Run yum update

$ sudo yum update

Stop the firewall

To make the ports accessible i.e. for clustering nodes use 5672, 4369, and 25672.
$ sudo systemclt stop firewall-cmd

Disable SELinux

$ sudo setenforce 0
The above command will disable SELinux for the session i.e. until next reboot – to permanently disable it set SELINUX=disabled in /etc/selinux/config file.

Set host names

Doing so later will most probably break the installation.
We’ll name the nodes/VMs as rabbit1 ( and rabbit2 ( – the default is localhost.

On first node/VM
$ sudo hostnamectl set-name rabbit1
On the second node/VM
$  hostnamectl set-name rabbit2

Resolve host names

Use Local host files (e.g. /etc/hosts) to resolve hostnames. Open the hosts file:
sudo vi /etc/hosts
In rabbit1’s hosts file add  rabbit2
In rabbit2’s hosts file add  rabbit1

Test the network

From rabbit1
$ ping rabbit2
The output:
Ping rabbti2
From rabbit2
$ ping rabbit1
The output:
ping rabbit1

Reboot machines

Reboot machines as hostname changes, may create problems sometimes, if you don’t reboot.

Step 1. Installation

Perform the following steps (installation) on both the nodes/VMs i.e. rabbit1 and rabbit2 (or as many nodes you have for your cluster setup).

Add the EPEL repository

$ sudo yum -y install epel-release

Install Rabbitmq server

$ sudo yum install rabbitmq-server -y
The RabbitMQ service will get started automatically on the server upon installation (default port 5672).

Rabbitmq server config

By default, the guest user is prohibited from connecting to the broker remotely; it can only connect over a loopback interface (i.e. localhost). This applies both to AMQP and to any other protocols enabled via plugins. Any other users you create will not (by default) be restricted in this way.
In rabbitmq.config – uncomment the {loopback_users, []}, and remove the trailing comma.
$ sudo vi /etc/rabbitmq/rabbitmq.config
Rabitmq config

Restart and enable rabbitmq-server

$ sudo systemctl restart rabbitmq-server
$ sudo systemctl enable rabbitmq-server


$ sudo rabbitmqctl status
The output:
Rabbitmq status

Step 3 – Copy The Erlang cookie

This Erlang cookie is used by all the nodes of the cluster to authenticate to each other – it has to be matched on all the nodes. Copy the Erlang cookie from any node to all the other nodes. Copy the Erlang cookie from rabbit1 to rabbit2 (or, to as much as nodes you have).
$ sudo scp /var/lib/rabbitmq/.erlang.cookie root@rabbit2:/var/lib/rabbitmq/
Erlang cookie

Step 4  – Creating the cluster

Just to give an idea – in order to link up our three nodes in a cluster, we tell two of the nodes, say rabbit@rabbit2 and rabbit@rabbit3, to join the cluster of the third, say rabbit@rabbit1. Perform the following steps on rabbi2 (or, all the other nodes except rabbit1, in case you have more than 2 nodes).

Stop the rabbit2 node

sudo rabbitmqctl stop_app
The output:
rabbitmqctl stop app

Join the rabbit1 (master node)

sudo rabbitmqctl join_cluster rabbit@rabbit1
The output:
rabbitmqctl join cluster

Start rabbit2

 sudo rabbitmqctl start_app
The output:
rabbitmqclt start app

Cluster status

We can see that the two nodes are joined in a cluster by running the cluster_status command on either of the nodes.
sudo rabbitmqctl cluster_status
The output on rabbit1:
cluster status
The output on rabbit2:
cluster status

Step 5 – HA configuration (Optional)

The weird thing here is, by default the rabbitmq cluster won’t have the HA (high-availability) mode set On. The following command will make the exchanges, queues, synced on all the nodes, and all the queues will come back even after a full cluster reboot (all the nodes, including the master i.e. rabbit1).
sudo rabbitmqctl set_policy ha-all "" '{"ha-mode":"all","ha-sync-mode":"automatic"}'
The output:
HA Config

Step 6 – Enable the Rabbitmq management portal (optional)

$ sudo rabbitmq-plugins enable rabbitmq_management
The output:
rabbitmq management portal

Restart rabbitmq-server

$ sudo systemctl restart rabbitmq-server
Access the management portal on port 15672 (default) – http://localhost:15672 or remotely http://<IP>:15672 – using the default username ‘guest‘, and password ‘guest‘.
rabbitmq management portal
The homepage:

Leave a Reply

Your email address will not be published. Required fields are marked *