How to Install RabbitMQ on Ubuntu Server 20.04 (Tutorial)

How to Install RabbitMQ on Ubuntu Server 20.04. In recent times top companies prefer to have a tool that works as a messenger without an extra charge. There is one particular tool that offers unlimited message sending services within the organizations, popularly known as RabbitMQ.

What is RabbitMQ?

RabbitMQ is a widely used and open source message broker software application. The RabbitMQ software is built on the advanced message queuing protocol (AMQP) and extended by using plugin architecture to support streaming text oriented messenger services throughout the business organizations. It provides a common platform to send and receive a message and also facilitates encryption services to maintain confidentiality. RabbitMQ is mainly used by large companies within the industries, an example for the companies which have already adopted RabbitMQ applications are Zalando, Boomerang, WeWork, WunderList and many more.

The RabbitMQ is written using the Erlang programming language, the RabbitMQ server is built based on the “Open telecom platform framework” for clustering message requests from the client. The RabbitMQ executable source codes are released under “Mozilla Public license”.

How Does RabbitMQ Work?

In this section, we will be explaining how the RabbitMQ Server software sends and receives messages within the organizations. Here is an image that illustrates the overview of the RabbitMQ:

RabbitMQ features 

  • In the above figure, RabbitMQ acts as a middleware for various services like Web Applications, API applications, and etc. They can also be used to reduce the data load and delivery times of the web applications while taking up the resources from third parties.
  • In this example, we have taken an example of a web application that allows users to upload information to the websites. Later on, a piece of uploaded information will be generated in the form of a PDF and emailed back to the users. This kind of task required a lot of time while exchanging the information and generating them in PDF formats, so to overcome this issue, a message queue will be used.
  • The basic architecture of the RabbitMQ is very simple, the client side application is called a “producer” that creates messages, then delivers these messages into the “broker”. The server side application is known as a “consumer” that connects to the queue and is subscribed to get proceeds.
  • All the messages are placed onto a “queue” that is stored until the consumer retrieves them to perform further tasks.
  • An exchange messenger accepts the PDF format messages from the producers and routes them into the PDF creations or performs corrections.
  • There are four types of message exchanges available; Direct, Fanout, Topic and Headers.

Benefits of RabbitMQ

  • The RabbitMQ allows users to set up a sophisticated rule for message exchange or message delivery.
  • This type of messenger application supports STOMP, MQTT, WebSockets, and others.
  • It has the capability to vary point-to-point, request/ reply, and publish/subscribe messaging.
  • Offers string authentication and expression-based authorization.
  • RabbitMQ is a queue, so messages are done away with once consumed, and acknowledgment is also provided.
  • In RabbitMQ, you can specify message priorities, and consume messages with high priority at the onset.
  • This software has come up with a variety of advanced features such as persistence, performance reliability, publisher confirms, delivery acknowledgment service provider, and high availability.
  • RabbitMQ’s producer does not charge anything to send the messages.
  • This tool is good for simple use cases and offers flexible routing options.

In this post, we will show you how to install RabbitMQ on Ubuntu 20.04 server.

Install Erlang

Before starting, you will need to install Erlang on your server. First, install the required dependencies with the following command:

					apt-get install software-properties-common curl gnupg2 apt-transport-https

Next, import the Erlang GPG key using the following command:

					wget -O- | apt-key add -

Next, add the Erlang repository with the following command:

					echo "deb focal contrib" | tee /etc/apt/sources.list.d/erlang.list

Finally, update the repository and install Erlang with the following command:

					apt-get update -y
apt-get install erlang -y

To verify the Erlang installation, run the following command:

					erl -v

You will get the Erlang shell in the following output:

					Erlang/OTP 24 [erts-12.1.5]  [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [jit]

Eshell V12.1.5  (abort with ^G)


Press CTRL+G then type q to exit from the Erlang shell.

Install RabbitMQ on Ubuntu 20.04

By default, RabbitMQ is not available in the Ubuntu 20.04 default repository. So you will need to install the RabbitMQ repository to your system. Run the following command to install the RabbitMQ repository:

					curl -s | bash

Now, update the repository and install the RabbitMQ with the following command:

					apt-get update -y
apt-get install rabbitmq-server -y

You can check the status of the RabbitMQ using the following command:

					systemctl status  rabbitmq-server

You will get the following output:

					● rabbitmq-server.service - RabbitMQ broker
     Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-12-02 09:17:12 UTC; 12s ago
   Main PID: 19117 (beam.smp)
      Tasks: 22 (limit: 2353)
     Memory: 87.0M
     CGroup: /system.slice/rabbitmq-server.service
             ├─19117 /usr/lib/erlang/erts-12.1.5/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 10485>
             ├─19128 erl_child_setup 32768
             ├─19168 /usr/lib/erlang/erts-12.1.5/bin/epmd -daemon
             ├─19188 inet_gethost 4
             └─19189 inet_gethost 4

Dec 02 09:17:09 server rabbitmq-server[19117]:   Doc guides:
Dec 02 09:17:09 server rabbitmq-server[19117]:   Support:
Dec 02 09:17:09 server rabbitmq-server[19117]:   Tutorials:
Dec 02 09:17:09 server rabbitmq-server[19117]:   Monitoring:
Dec 02 09:17:09 server rabbitmq-server[19117]:   Logs: /var/log/rabbitmq/rabbit@server.log
Dec 02 09:17:09 server rabbitmq-server[19117]:         /var/log/rabbitmq/rabbit@server_upgrade.log
Dec 02 09:17:09 server rabbitmq-server[19117]:         <stdout>
Dec 02 09:17:09 server rabbitmq-server[19117]:   Config file(s): (none)
Dec 02 09:17:12 server rabbitmq-server[19117]:   Starting broker... completed with 0 plugins.
Dec 02 09:17:12 server systemd[1]: Started RabbitMQ broker.


Create an Administrative User

By default, RabbitMQ can be connected without any username or password. So it is a good idea to set an admin user and password to connect to the RabbitMQ.

You can create an administrator user, set a password, set an administrator tag and set permission using the following commands:

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

You can list all users permission using the following command:

					rabbitmqctl list_permissions -p /

You will get the following output:

					Listing permissions for vhost "/" ...
user	configure	write	read
guest	.*	.*	.*
admin	.*	.*	.*


Enable RabbitMQ Web UI

RabbitMQ provides a web based interface to manage the RabbitMQ instance. To access the RabbitMQ web interface, you will need to enable it first.

Run the following command to enable the RabbitMQ web interface:

					rabbitmq-plugins enable rabbitmq_management

You will get the following output:

					Enabling plugins on node rabbit@server:
The following plugins have been configured:
Applying plugin configuration to rabbit@server...
The following plugins have been enabled:

started 3 plugins.

By default, the RabbitMQ web interface listens on port 15672. You can check it using the following command:

					ss -tunelp | grep 15672

You will get the following output:

					tcp   LISTEN 0      1024                 *                                                                                users:(("beam.smp",pid=19117,fd=35)) uid:118 ino:57672 sk:19 <->               

Access RabbitMQ Web Interface

Now, open your web browser and access the RabbitMQ web interface using the URL http://your-server-ip:15672. You should see the RabbitMQ login page:

Provide your admin username, password and click on the Login button. You will be redirected to the RabbitMQ dashboard:

How to Install RabbitMQ on Ubuntu Server 20.04. Conclusion

In this post, we talked about what is RabbitMQ message broker and how to install it on Ubuntu 20.04 server. We also explained how to set an Admin user and enable the RabbitMQ Web UI. You can now deploy the RabbitMQ on a production environment and integrate it with your application.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x