How to Install RabbitMQ on Ubuntu 20.04

Install RabbitMQ on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure RabbitMQ on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

RabbitMQ is open-source message-broker software that originally implemented the Advanced Message Queuing Protocol and has since been extended with a plug-in architecture to support Streaming Text Oriented Messaging Protocol, MQ Telemetry Transport, and other protocols. Let’s get started by installing RabbitMQ on our Ubuntu-based machine.

Install RabbitMQ on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install RabbitMQ on the Ubuntu system.

Now we creating a bash script for the automated installation of RabbitMQ. We will create a bash script file with the name rabbitmq.sh:

sudo nano rabbitmq.sh

Next, copy the below script and paste it into the favorite editor:

#!/bin/sh
## If sudo is not available on the system,
## uncomment the line below to install it
# apt-get install -y sudo

sudo apt update -y

## Install prerequisites
sudo apt install curl gnupg -y

## Install RabbitMQ signing key
curl -fsSL https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc | sudo apt-key add -

## Install apt HTTPS transport
sudo apt install apt-transport-https

## Add Bintray repositories that provision latest RabbitMQ and Erlang 21.x releases
sudo tee /etc/apt/sources.list.d/bintray.rabbitmq.list <<EOF

## Installs the latest Erlang 23.x release.
## Change component to "erlang-22.x" to install the latest 22.x version.
## "bionic" as distribution name should work for any later Ubuntu or Debian release.
## See the release to distribution mapping table in RabbitMQ doc guides to learn more.
deb https://dl.bintray.com/rabbitmq-erlang/debian bionic erlang

deb https://dl.bintray.com/rabbitmq/debian bionic main
EOF

## Update package indices
sudo apt update -y

## Install rabbitmq-server and its dependencies
sudo apt install rabbitmq-server -y --fix-missing

Save and then run the script using the following commands below:

sh rabbitmq.sh

After installation, the RabbitMQ service is started and enabled to start on boot. To check the status, run:

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

Step 3. Configure RabbitMQ.

When the server first starts running and detects that its database is uninitialized or has been deleted, it initializes a fresh database with the following resources:

#Create a new user. Replace rabbituser and PASSWORD as par your choice.
sudo rabbitmqctl add_user rabbituser PASSWD

# Add Administrative Rights
rabbitmqctl set_user_tags rabbituser administrator

# Grant necessary permissions
sudo rabbitmqctl set_permissions -p / rabbituser ".*" ".*" ".*"

# Verify permissions
sudo rabbitmqctl list_permissions

########################################################################

# It is danger for default user and default password for remote access
# In order to change password 
rabbitmqctl change_password guest NEWPASSWORD

# For Deleting guest User
rabbitmqctl delete_user guest

Step 4. Enable RabbitMQ Management Dasboard.

To enable RabbitMQ Management Console, run the following command:

# enable rabbitmq management plugin
sudo rabbitmq-plugins enable rabbitmq_management

# To restart the service:
sudo systemctl restart rabbitmq-server

Step 5. Configure Firewall.

If you have an active UFW firewall, open both ports 5672 and 15672:

sudo ufw allow proto tcp from any to any port 5672,15672

Step 6. Accessing RabbitMQ.

The RabbitMQ management dashboard will be live at URL : http://your-ip-address:15672. For using this dashboard we will use the username: guest and password: guest for the first time login, so we can configure (add) another user and setting their privileges.

Install RabbitMQ on Ubuntu 20.04

That’s all you need to do to install RabbitMQ on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on RabbitMQ, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.