You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

RabbitMQ is an open source message broker software that implements the Advanced Message Queuing Protocol (AMQP) and Streaming Text Oriented Messaging Protocol, Message Queuing Telemetry Transport, and other protocols via a Plugins.

The work of a Messaging broker is to receive messages from publishers (applications that publish them) and route them to consumers (applications that process them). AMQP is a messaging protocol that enables conforming client applications to communicate with conforming messaging middleware brokers.

Follow the steps below to install RabbitMQ Server on Ubuntu 20.04 | 18.04 LTS.

Step 1: Install Erlang/OTP

RabbitMQ requires Erlang to be installed first before it can run. Install Erlang on Ubuntu 18.04 system using our previous guide:

How to install Latest Erlang on Ubuntu

Once Erlang has been installed, proceed to step 2.

Step 2: Add RabbitMQ Repository to Ubuntu

Import RabbitMQ:

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

Now add RabbitMQ Repository To Ubuntu 20.04|18.04:

echo "deb https://dl.bintray.com/rabbitmq/debian bionic main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list

Step 2: Install RabbitMQ Server Ubuntu 20.04 | 18.04 LTS

To install RabbitMQ Server Ubuntu 18.04, update apt list, then install rabbitmq-server package:

sudo apt update
sudo apt install rabbitmq-server

Hit the y key to start the installation.

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  socat
The following NEW packages will be installed:
  rabbitmq-server soca
0 upgraded, 2 newly installed, 0 to remove and 27 not upgraded.
Need to get 12.3 MB of archives.
After this operation, 15.3 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

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

$ systemctl status  rabbitmq-server.service 
● rabbitmq-server.service - RabbitMQ broker
     Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2020-05-17 22:00:58 EAT; 6s ago
   Main PID: 18023 (beam.smp)
     Status: "Initialized"
      Tasks: 85 (limit: 2344)
     Memory: 74.6M
     CGroup: /system.slice/rabbitmq-server.service
             ├─18023 /usr/lib/erlang/erts-10.7.1/bin/beam.smp -W w -A 64 -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 ->
             ├─18134 /usr/lib/erlang/erts-10.7.1/bin/epmd -daemon
             ├─18277 erl_child_setup 32768
             ├─18302 inet_gethost 4
             └─18303 inet_gethost 4

May 17 22:00:57 ubuntu20 rabbitmq-server[18023]:   Doc guides: https://rabbitmq.com/documentation.html
May 17 22:00:57 ubuntu20 rabbitmq-server[18023]:   Support:    https://rabbitmq.com/contact.html
May 17 22:00:57 ubuntu20 rabbitmq-server[18023]:   Tutorials:  https://rabbitmq.com/getstarted.html
May 17 22:00:57 ubuntu20 rabbitmq-server[18023]:   Monitoring: https://rabbitmq.com/monitoring.html
May 17 22:00:57 ubuntu20 rabbitmq-server[18023]:   Logs: /var/log/rabbitmq/[email protected]
May 17 22:00:57 ubuntu20 rabbitmq-server[18023]:         /var/log/rabbitmq/[email protected]_upgrade.log
May 17 22:00:57 ubuntu20 rabbitmq-server[18023]:   Config file(s): (none)
May 17 22:00:58 ubuntu20 rabbitmq-server[18023]:   Starting broker...systemd unit for activation check: "rabbitmq-server.service"
May 17 22:00:58 ubuntu20 systemd[1]: Started RabbitMQ broker.
May 17 22:00:58 ubuntu20 rabbitmq-server[18023]:  completed with 0 plugins.

You can confirm if the service is configured to start on boot using the command:

$ systemctl is-enabled rabbitmq-server.service 
enabled

If it returns disabled, enable it by running:

sudo systemctl enable rabbitmq-server

Step 3: Enable the RabbitMQ Management Dashboard (Optional)

You can optionally enable the RabbitMQ Management Web dashboard for easy management.

sudo rabbitmq-plugins enable rabbitmq_management

The Web service should be listening on TCP port 15672

# ss -tunelp | grep 15672
tcp   LISTEN  0       128                    0.0.0.0:15672        0.0.0.0:*      users:(("beam.smp",pid=9525,fd=71)) uid:111 ino:39934 sk:9 <->

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

Access it by opening the URL http://[server IP|Hostname]:15672

By default, the guest user exists and can connect only from localhost. You can login with this user locally with the password “guest”

To be able to login on the network, create an admin user like below:

rabbitmqctl add_user admin StrongPassword
rabbitmqctl set_user_tags admin administrator

Login with this admin username and the password assigned.

Step 4: Set RabbitMQ Cluster (Optional)

If you need to achieve high availability and higher throughput, consider configuring RabbitMQ cluster on your Ubuntu 18.04 servers by following the guide below:

How to Configure RabbitMQ Cluster on Ubuntu 18.04 LTS

RabbitMQ User Management Commands

Delete User:

rabbitmqctl delete_user user

Change User Password:

rabbitmqctl change_password user strongpassword

Create new Virtualhost:

rabbitmqctl add_vhost /my_vhost

List available Virtualhosts:

rabbitmqctl list_vhosts

Delete a virtualhost:

rabbitmqctl delete_vhost /myvhost

Grant user permissions for vhost:

rabbitmqctl set_permissions -p /myvhost user ".*" ".*" ".*"

List vhost permissions:

rabbitmqctl list_permissions -p /myvhost

To list user permissions:

rabbitmqctl list_user_permissions user

Delete user permissions:

rabbitmqctl clear_permissions -p /myvhost user

The next article to read is:

How to Backup and Restore RabbitMQ Data & Configurations

To install RabbitMQ on CentOS 7 / CentOS 6 server, see:

Installing RabbitMQ on CentOS 6 and CentOS 7

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF