RabbitMQ is a popular open-source message broker software that implements the Advanced Message Queuing Protocol (AMQP). It allows applications to communicate with each other by sending and receiving messages. In this article, we will learn how to install and configure RabbitMQ on Ubuntu 20.04.
Prerequisites
Before we begin, make sure that you have a clean installation of Ubuntu 20.04 and a user with sudo privileges. You will also need to have the following packages installed:
- Erlang: RabbitMQ is written in the Erlang programming language, so you will need to have Erlang installed on your system.
- apt-transport-https: This package is required to add the RabbitMQ signing key to your system.
To check if Erlang is installed on your system, run the following command:
erl
If Erlang is installed, you should see the Erlang shell. To exit the shell, press CTRL+C
twice. If you see a message saying that the erl
command is not found, then you will need to install Erlang.
To install Erlang, run the following commands:
sudo apt update
sudo apt install erlang
To check if the apt-transport-https
package is installed, run the following command:
dpkg -s apt-transport-https
If the package is installed, you should see a message saying Status: install ok installed
. If the package is not installed, you will need to install it by running the following command:
sudo apt install apt-transport-https
Installing RabbitMQ
To install RabbitMQ, we will first add the RabbitMQ signing key to our system. This ensures that the packages we download are authentic and have not been tampered with.
To add the signing key, run the following command:
wget -O- <https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc> | sudo apt-key add -
Next, we will add the RabbitMQ repository to our system. This repository contains the packages for RabbitMQ.
To add the repository, run the following command:
sudo apt-add-repository "deb <https://dl.bintray.com/rabbitmq/debian> bionic main"
Now, we can install RabbitMQ by running the following commands:
sudo apt update
sudo apt install rabbitmq-server
The installation process will take a few minutes to complete. Once the installation is finished, you can verify that RabbitMQ is installed and running by running the following command:
rabbitmqctl status
You should see a message saying that the RabbitMQ service is running.
Configuring RabbitMQ
Now that RabbitMQ is installed, we can configure it to meet our needs.
To manage RabbitMQ, we will use the rabbitmqctl
command. This command allows us to add and remove users, enable and disable plugins, and perform other administrative tasks.
First, we will add a new user to RabbitMQ. This user will be used to access the RabbitMQ management interface, which allows us to monitor and manage RabbitMQ from a web browser.
To add a new user, run the following command:
rabbitmqctl add_user <username> <password>
Replace <username>
and <password>
with the desired username and password for the new user.
Next, we will grant the new user the necessary permissions to access the management interface. To do this, run the following command:
rabbitmqctl set_user_tags <username> administrator
Replace <username>
with the username of the user you just added. This will grant the user the administrator
tag, which gives them access to the management interface.
Now, we will enable the management plugin. This plugin provides the web-based management interface for RabbitMQ. To enable the plugin, run the following command:
rabbitmq-plugins enable rabbitmq_management
Once the plugin is enabled, you can access the management interface by opening a web browser and going to the following URL:
<http://localhost:15672/>
You will be prompted to enter the username and password for the user you created earlier. Once you have logged in, you will see the RabbitMQ management interface.
Conclusion
In this article, we learned how to install and configure RabbitMQ on Ubuntu 20.04. We added a new user and granted them the necessary permissions to access the management interface, and we enabled the management plugin to allow us to monitor and manage RabbitMQ from a web browser. Now that RabbitMQ is installed and configured, you can start using it to send and receive messages between applications.