How to install and Configure RabbitMQ Server in Ubuntu 22.04

In this guide we will explore how to install the latest release of RabbitMQ in Ubuntu 22.04 Server or Workstation

RabbitMQ is an open source message broker software that implements the Advanced Message Queuing Protocol (AMQP). RabbitMQ works by receiving messages from publishers (applications that publish them) and routes them to consumers (applications that process them).

# Prerequisites

To follow along, ensure you have the following

  • An updated Ubuntu Server/workstation
  • Access to the internet
  • Root access or user with Sudo access

# Table of Content

  1. Updating the system
  2. Installing Erlang
  3. Installing RabbitMQ
  4. Starting and enabling rabbitmq-server service
  5. Optional: Enabling RabbitMQ Dashboard
  6. Basic RabbitMQ User Management Commands

# 1. Updating the system

Before proceeding, ensure that the server packages are up to date. Use this command to achieve that:

sudo apt update
sudo apt upgrade -y

# 2. Installing Erlang

The RabbitMQ package is found in the default OpenSUSE repos. Install it using this command:

sudo apt install -y erlang

# 4. Installing Rabbitmq

RabbitMQ can be found in the default Ubuntu repos. Install using this command:

sudo apt install -y rabbitmq-server

Package details can be queried using apt-cache command with the option policy.

$ apt-cache policy rabbitmq-server
rabbitmq-server:
  Installed: 3.9.13-1
  Candidate: 3.9.13-1
  Version table:
 *** 3.9.13-1 500
        500 http://europe-west1.gce.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
        100 /var/lib/dpkg/status

# 5. Starting and enabling rabbitmq-server service

Start the service

sudo systemctl start rabbitmq-server

Then check the status to confirm its running

$ sudo systemctl status rabbitmq-server
● rabbitmq-server.service - RabbitMQ Messaging Server
     Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-10-19 19:47:36 UTC; 24s ago
   Main PID: 40139 (beam.smp)
      Tasks: 21 (limit: 4392)
     Memory: 88.8M
        CPU: 6.681s
     CGroup: /system.slice/rabbitmq-server.service
             ├─40139 /usr/lib/erlang/erts-12.2.1/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sbwtdcpu none -sbwtdio none -- -root /usr/lib/erlang -progname erl -- -home /var/lib/rabbitmq -- -pa "" -noshell -noinput -s rabbit boot -boot start_sasl -syslog logger "[]" -syslog syslog_error_logger false
             ├─40150 erl_child_setup 65536
             ├─40206 inet_gethost 4
             └─40207 inet_gethost 4

Oct 19 19:47:29 unstable-ubuntusrv systemd[1]: Starting RabbitMQ Messaging Server...
Oct 19 19:47:36 unstable-ubuntusrv systemd[1]: Started RabbitMQ Messaging Server.

Now you can enable it on boot

sudo systemctl enable rabbitmq-server

You can get status of rabbitmq internals:

$ sudo rabbitmqctl status

# 6. Optional: Enabling RabbitMQ Dashboard

Use the rabbitmq-plugins enable command to enable the management dashboard:

$ sudo rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@unstable-ubuntusrv:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@unstable-ubuntusrv...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

started 3 plugins.

The web service is up listening on port 15672

$ ss -tunlp | grep 15672
tcp   LISTEN 0      1024          0.0.0.0:15672      0.0.0.0:*

Access it by opening the URL http://[server IP]:15672 like http://127.0.0.1:15672

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

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

$ sudo rabbitmqctl add_user admin Secr3t
Adding user "admin" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.

$ sudo rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...

Login with this admin username and the password assigned. You should see an interface similar to below:

citizix - Rabbitmq Dashboard

citizix – Rabbitmq Dashboard

# 7. Basic RabbitMQ User Management Commands

Delete User:

sudo rabbitmqctl delete_user user

Change User Password:

sudo rabbitmqctl change_password user strongpassword

Create new Virtualhost:

sudo rabbitmqctl add_vhost /my_vhost

List available Virtualhosts:

sudo rabbitmqctl list_vhosts

Delete a virtualhost:

sudo rabbitmqctl delete_vhost /myvhost

Grant user permissions for vhost:

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

List vhost permissions:

sudo rabbitmqctl list_permissions -p /myvhost

To list user permissions:

rabbitmqctl list_user_permissions user

Delete user permissions:

rabbitmqctl clear_permissions -p /myvhost user

# Conclusion

In this guide we managed to install and set up RabbitMQ. We also learnt how to create users and vhosts.

Last updated on Mar 20, 2024 17:19 +0300
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy