Saturday, January 18, 2025
Google search engine
HomeGuest BlogsDeploy 3 Node RabbitMQ Cluster on Rocky Linux 8|AlmaLinux 8

Deploy 3 Node RabbitMQ Cluster on Rocky Linux 8|AlmaLinux 8

.tdi_3.td-a-rec{text-align:center}.tdi_3 .td-element-style{z-index:-1}.tdi_3.td-a-rec-img{text-align:left}.tdi_3.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_3.td-a-rec-img{text-align:center}}

RabbitMQ is an open-source, and lightweight message-queueing software/message broker written in Erlang. It can be deployed easily on-premises and in the cloud. RabbitMQ can be used to implement the Advanced Message Queuing Protocol (AMQP) since it acts as message-oriented middleware. This middleware can be used on different services such as web applications where it reduces the loads and delivery times of the web application.

There are many features associated with RabbitMQ. These include:

  • Reliability – It offers innumerable features including persistence, publisher confirms, delivery acknowledgments, high availability e.t.c.
  • Clustering – several instances can be clustered on a local network to form a robust logical broker.
  • Multi-protocol – It supports several messaging protocols
  • Management UI – It provides an easy-to-use UI that allows one to monitor and control aspects of the message broker.
  • Flexible Routing – The messages are routed through exchanges before they arrive at queues.
  • Commercial support – It offers training and consultations from Pivotal
  • Large Community – It has a large community around the world producing all sorts of clients, plugins, and guides to help improve the functionality of this tool.

Many developers around the world today build applications using microservice architecture as opposed to the monolithic system. By doing so, they highly consider message Queuing and its benefits. One of the tools used here is RabbitMQ as the message broker.

.tdi_2.td-a-rec{text-align:center}.tdi_2 .td-element-style{z-index:-1}.tdi_2.td-a-rec-img{text-align:left}.tdi_2.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_2.td-a-rec-img{text-align:center}}

RabbitMQ can be run on a single node or be joined into a cluster. Clustering is required when your application needs additional delivery guarantees that can only be provided by highly available queues. You can also set up a cluster when you want to deploy RabbitMQ as a central messaging hub for many applications.

This guide provides steps on how to deploy 3 Node RabbitMQ Cluster on Rocky Linux 8 | AlmaLinux 8.

Requirements

For this guide, we will use 3 Rocky Linux 8 | AlmaLinux 8 provisioned as below:

HOSTNAME TASK IP ADDRESS
rabbitmq_01 RabbitMQ node1 192.168.205.2
rabbitmq_02 RabbitMQ node2 192.168.205.3
rabbitmq_03 RabbitMQ node3 192.168.205.4

Set the hostname on all the 3 nodes:

##On Node1
sudo hostnamectl set-hostname rabbitmq_01.geeksforgeeks.org

##On Node2
sudo hostnamectl set-hostname rabbitmq_02.geeksforgeeks.org

##On Node3
sudo hostnamectl set-hostname rabbitmq_03.geeksforgeeks.org

Add the hostnames to /etc/hosts on all the 3 nodes:

$ sudo vim /etc/hosts
192.168.205.2   rabbitmq_01.geeksforgeeks.org  rabbitmq_01
192.168.205.3   rabbitmq_02.geeksforgeeks.org  rabbitmq_02
192.168.205.4   rabbitmq_03.geeksforgeeks.org  rabbitmq_03

#1. Install RabbitMQ on Rocky Linux 8 | AlmaLinux 8

To perform RabbitMQ clustering, it is required that all the nodes have RabbitMQ installed and running.

Begin by adding the required repositories to the systems.

##Add the EPEL repository
sudo yum -y install epel-release

##Add the RabbitMQ repository
curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash

##Add the Erlang repository
curl -s https://packagecloud.io/install/repositories/rabbitmq/erlang/script.rpm.sh | sudo bash

Once the repositories have been added, RabbitMQ can be installed on Rocky Linux 8 | AlmaLinux 8 using the command:

sudo yum install rabbitmq-server erlang

Dependency Tree:

Dependencies resolved.
================================================================================
 Package            Arch      Version         Repository                   Size
================================================================================
Installing:
 erlang             x86_64    25.0.2-1.el8    rabbitmq_erlang              20 M
 rabbitmq-server    noarch    3.10.5-1.el8    rabbitmq_rabbitmq-server     14 M

Transaction Summary
================================================================================
Install  2 Packages

Total download size: 34 M
Installed size: 55 M
Is this ok [y/N]: y

#2. Configure RabbitMQ on Rocky Linux 8 | AlmaLinux 8

Once installed, start and enable the service on all the nodes:

sudo systemctl enable --now rabbitmq-server

Check the status of the service:

$ systemctl status rabbitmq-server
 rabbitmq-server.service - RabbitMQ broker
   Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-06-24 05:57:57 EDT; 5s ago
 Main PID: 3659 (beam.smp)
    Tasks: 22 (limit: 23682)
   Memory: 95.5M
   CGroup: /system.slice/rabbitmq-server.service
           ├─3659 /usr/lib64/erlang/erts-13.0.2/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048>
           ├─3673 erl_child_setup 32768
           ├─3698 /usr/lib64/erlang/erts-13.0.2/bin/epmd -daemon
           ├─3715 /usr/lib64/erlang/erts-13.0.2/bin/inet_gethost 4
           └─3716 /usr/lib64/erlang/erts-13.0.2/bin/inet_gethost 4

Allow the port through the firewall:

sudo firewall-cmd --add-port=5672/tcp --permanent
sudo firewall-cmd --reload

Add a user to RebbitMQ since the default user can only log in to localhost.

$ sudo rabbitmqctl add_user admin StrongPassword
Adding user "admin" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.

Assign administrator permissions to the created user

sudo rabbitmqctl set_user_tags admin administrator

You can set new password for admin RabbitMQ user with the following command:

sudo rabbitmqctl change_password username NewStrongPassword

Once created, you can list users with the command:

$ sudo rabbitmqctl list_users
Listing users ...
user	tags
admin	[]
admin	[administrator]
guest	[administrator]

You also need to add a virtual host to be able to use RabbitMQ

$ sudo rabbitmqctl add_vhost /new_vhost
Adding vhost "/new_vhost" ...

List the virtual host:

$ sudo rabbitmqctl list_vhosts
Listing vhosts ...
name
/new_vhost
/

Now grant the user permissions for the Virtualhost:

$ sudo rabbitmqctl set_permissions -p /new_vhost admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/new_vhost" ...

List the user permissions.

$ sudo rabbitmqctl list_user_permissions admin
Listing permissions for user "admin" ...
vhost	configure	write	read
/new_vhost	.*	.*	.*

#3. Configure RabbitMQ Clustering

Once RabbitMQ has been installed and configured on all the 3 nodes, you can now configure clustering.

First, enable the required ports through the firewall.

sudo firewall-cmd --add-port={4369/tcp,25672/tcp} --permanent
sudo firewall-cmd --reload

Next, you need to put the same cookie on all the nodes. So we can copy the cookie on node1 to the other nodes:

$ sudo cat /var/lib/rabbitmq/.erlang.cookie; echo
MJRCZUCLEBOWRGTLYWEU

Now paste the cookie on nodes 2 and node 3

$ sudo vim /var/lib/rabbitmq/.erlang.cookie
MJRCZUCLEBOWRGTLYWEU

Save the file and restart the service on nodes 2 and 3

sudo systemctl restart rabbitmq-server

Stop the RabbitMQ application and reset the server.

  • On node2 and node3
$ sudo rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbitmq_02 ...

$ sudo rabbitmqctl reset
Resetting node rabbit@rabbitmq_02 ...

Now join the RabbitMQ instances on nodes 2 and 3 to node1(rabbitmq_01)

On node2 and node3

sudo rabbitmq-server -detached
sudo rabbitmqctl join_cluster rabbit@rabbitmq_01

In the above command, remember to use the hostname only, not with FQDN specified. For example rabbitmq_01

Now start the application:

sudo rabbitmqctl start_app

Check the cluster status:

sudo rabbitmqctl cluster_status

Sample Output:

Deploy 3 Node RabbitMQ Cluster on Rocky Linux

From the above output, we can all agree that we have the RabbitMQ cluster running with 3 nodes.

#4. Configure RabbitMQ HA Policy

The HA Policy enables queue mirroring on all the nodes in the cluster. This can be set using the command:

$ sudo rabbitmqctl set_policy ha-all "." '{"ha-mode":"all"}'
Setting policy "ha-all" for pattern "." to "{"ha-mode":"all"}" with priority "0" for vhost "/" ...

Verify the policy has been created.

[alma@rabbitmq_02 ~]$ sudo rabbitmqctl list_policies
[sudo] password for alma: 
Listing policies for vhost "/" ...
vhost	name	pattern	apply-to	definition	priority
/	ha-all	.	all	{"ha-mode":"all"}	0

#5. Enable the RabbitMQ web UI

The RabbitMQ web UI offers an easy way to manage/monitor the RabbitMQ instances. Enable the RabbitMQ web UI on all the 3 nodes with the command:

sudo rabbitmq-plugins enable rabbitmq_management
sudo systemctl restart rabbitmq-server

Allow the required ports through the firewall:

sudo firewall-cmd --zone=public --permanent --add-port=5671-5672/tcp --add-port=15672/tcp  --add-port=61613-61614/tcp --add-port=1883/tcp --add-port=8883/tcp
sudo firewall-cmd --reload

Now access the web UI on one of the nodes, using the URL http://IP_address:15672

Deploy 3 Node RabbitMQ Cluster on Rocky Linux AlmaLinux 1

On this page, log in with the user-created earlier. On successful login, you will see the below dashboard with all the nodes displayed.

Deploy 3 Node RabbitMQ Cluster on Rocky Linux AlmaLinux 3

Now let’s test the replication by creating a queue on this node:

Deploy 3 Node RabbitMQ Cluster on Rocky Linux AlmaLinux 2

Once created, the queue can be seen on any other node in the cluster, say node2

Deploy 3 Node RabbitMQ Cluster on Rocky Linux AlmaLinux 4

From the above output, we can all agree that we have successfully set up a 3 node RabbitMQ Cluster on Rocky Linux 8 | AlmaLinux 8. I hope this was helpful.

Related posts:

Books To Learn Rabbitmq/Activemq/Zeromq

How To Install RabbitMQ on RHEL 8 / CentOS 8

How to Setup RabbitMQ Cluster on Ubuntu

.tdi_4.td-a-rec{text-align:center}.tdi_4 .td-element-style{z-index:-1}.tdi_4.td-a-rec-img{text-align:left}.tdi_4.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_4.td-a-rec-img{text-align:center}}

RELATED ARTICLES

Most Popular

Recent Comments