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).

Related Content:

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

Updating the system

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

1
2
sudo apt update
sudo apt upgrade -y

Installing Erlang

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

1
sudo apt install -y erlang

Installing Rabbitmq

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

1
sudo apt install -y rabbitmq-server

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

1
2
3
4
5
6
7
8
9
$ 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

Starting and enabling rabbitmq-server service

Start the service

1
sudo systemctl start rabbitmq-server

Then check the status to confirm its running

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
$ 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

1
sudo systemctl enable rabbitmq-server

You can get status of rabbitmq internals:

1
sudo rabbitmqctl status

6. Optional: Enabling RabbitMQ Dashboard

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$ 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

1
2
$ 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:

1
2
3
4
5
6
7
8
$ 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 admin interface.

Delete User:

1
sudo rabbitmqctl delete_user user

Change User Password:

1
sudo rabbitmqctl change_password user strongpassword

Create new Virtualhost:

1
sudo rabbitmqctl add_vhost /my_vhost

List available Virtualhosts:

1
sudo rabbitmqctl list_vhosts

Delete a virtualhost:

1
sudo rabbitmqctl delete_vhost /myvhost

Grant user permissions for vhost:

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

List vhost permissions:

1
sudo rabbitmqctl list_permissions -p /myvhost

To list user permissions:

1
rabbitmqctl list_user_permissions user

Delete user permissions:

1
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 Oct 14, 2024 11:46 +0300
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy