How to Install RabbitMQ on Ubuntu 22.04: Step-by-Step Guide

How to Install RabbitMQ on Ubuntu 22.04: Step-by-Step Guide

RabbitMQ is an open-source message broker that uses the Advanced Message Queuing Protocol (AMQP). It is widely used to handle message queueing and asynchronous tasks. Installing RabbitMQ on Ubuntu 22.04 is a straightforward process and here in this tutorial we cover how to install RabbitMQ on Ubuntu 22.04 server or desktop system.

To install RabbitMQ on Ubuntu 22.04, you must add the official RabbitMQ repository and install several packages. This ensures you get the latest version and updates. Once the necessary repositories are added, a few simple commands will complete the installation process.

RabbitMQ can help manage and scale messaging tasks efficiently. Whether you’re running a complex microservice architecture or just need reliable message queuing, RabbitMQ provides powerful features to meet these needs.

Preparing for Installation

Source: YouTube, channel Tommy NGO

Before installing RabbitMQ on Ubuntu 22.04, it is important to gather necessary information and ensure the system meets specific requirements. Configuring the environment for security will also help with a smooth installation process.

System Requirements and Prerequisites

To install RabbitMQ, the system must meet several key requirements. Ubuntu 22.04 should be up to date, so it is crucial to run:

sudo apt-get update

Next, ensure you have Erlang installed because RabbitMQ depends on it. Install Erlang packages:

sudo apt-get install erlang

It is also essential to add RabbitMQ’s repository signing keys:

wget -O- https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo apt-key add -

The machine should have a stable internet connection and adequate system resources, avoiding high system load during installation. Users should have sudo privileges to execute administrative commands.

Securing the Installation Environment

Installing RabbitMQ on Ubuntu requires a secure environment. Begin by creating a non-privileged user to handle RabbitMQ operations, keeping root access limited:

sudo adduser rabbitmq_user

Properly configure firewall settings to allow RabbitMQ’s default ports (5672 for AMQP):

sudo ufw allow 5672

Always verify repository signing keys to ensure the authenticity of the packages being installed. Set appropriate permissions and policies to limit access and strengthen security against potential threats.

Installing and Configuring RabbitMQ

Source: YouTube, channel ProgrammingKnowledge

Installing RabbitMQ on Ubuntu 22.04 involves adding the official repository, performing setup tasks, and starting the daemon. Configuration and basic operations are also covered to ensure the broker runs smoothly.

Adding the RabbitMQ Repository and Installation

First, ensure your system is up to date. Use this command:

sudo apt update

Add the RabbitMQ signing key using:

curl -fsSL https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey | sudo apt-key add -

Add the Erlang repository:

echo "deb https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/deb/ubuntu $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list

Next, add the RabbitMQ repository:

echo "deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list

Update the package list and install rabbitmq-server:

sudo apt update
sudo apt install rabbitmq-server -y

Post-Installation Setup and Configuration

Once installed, enable the RabbitMQ management plugin:

sudo rabbitmq-plugins enable rabbitmq_management

Create an admin user and set permissions:

sudo rabbitmqctl add_user admin password
sudo rabbitmqctl set_user_tags admin administrator
sudo rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"

To access the management console, go to http://localhost:15672 in a web browser. Log in using the credentials set above.

Starting and Verifying the Broker

Start RabbitMQ as a daemon using:

sudo systemctl start rabbitmq-server

Enable it to start on boot:

sudo systemctl enable rabbitmq-server

Check the status to ensure it’s running:

sudo systemctl status rabbitmq-server

You should see that the RabbitMQ service is active and running. If needed, restart it with:

sudo systemctl restart rabbitmq-server

Basic Operational Commands

Add a new virtual host:

sudo rabbitmqctl add_vhost my_vhost

To list all virtual hosts:

sudo rabbitmqctl list_vhosts

To delete a virtual host:

sudo rabbitmqctl delete_vhost my_vhost

Check the enabled plugins:

sudo rabbitmq-plugins list

To stop the RabbitMQ server:

sudo systemctl stop rabbitmq-server

To reboot the RabbitMQ server:

sudo systemctl restart rabbitmq-server

This ensures RabbitMQ runs smoothly and is configured properly for your environment.

Share this article: