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.
- 10.0.0.1 rabbitmq-server01
- 10.0.0.2 rabbitmq-server02
- 10.0.0.3 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.
Install RabbitMQ Server
Let’s update all the servers before installing RabbitMQ,run the below command
Now let’s install RabbitMQ Server using below command.
After installing, let’s start and enable the Rabbit MQ Service.
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.
Make sure there is no error and after that restart the rabbitmq server
Setup UFW Firewall or Open port in Security Groups
Add ssh,tcp ports ‘5672,15672,4369,25672’ and enable firewall service
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’.
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.
Now we will join both ‘rabbitmq-server02’ and ‘rabbitmq-server03’ to the cluster ‘rabbitmq-server01’ and start the app.
Now lets check the status of the RabbitMQ cluster.
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’.
Setup the ‘techrunnruser’ user as an administrator.
And grant the ‘techrunnruser’ user permission to modify, write, and read all
Now delete the default ‘guest’ user.
And check all available users.
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.
Setup ha policy named ‘ha-two’ which all queue name start with ‘two.’ will be mirroring to the two nodes on the cluster.
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
RabbitMQ list ha policies.
RabbitMQ delete specific ha policy.
Now Open in Browser and type the IP address of the server with port “15672”
Now provide the username password.
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