How to Install RabbitMQ on Ubuntu 24.04

Updated on August 16, 2024
How to Install RabbitMQ on Ubuntu 24.04 header image

Introduction

RabbitMQ is an open-source message and streaming broker that enables efficient communication between distributed systems. It's highly extensible with plugins and supports multiple messaging protocols that improve application reliability while enabling fast deployment and integration with other systems.

This article explains how to Install RabbitMQ on Ubuntu 24.04 and secure it on the server.

Prerequisites

Before you begin:

Install RabbitMQ

RabbitMQ is available in the default repositories on Ubuntu 24.04. Follow the steps below to install the Erlang dependency package and RabbitMQ on your server.

  1. View the available RabbitMQ APT repository information.

    console
    $ sudo apt-cache policy rabbitmq-server
    

    Output:

    rabbitmq-server:
      Installed: (none)
      Candidate: 3.12.1-1ubuntu1
      Version table:
         3.12.1-1ubuntu1 500
            500 http://archive.ubuntu.com/ubuntu noble/main amd64 Packages
            500 http://ubuntu.mirror.constant.com noble/main amd64 Packages
            500 http://us.archive.ubuntu.com/ubuntu noble/main amd64 Packages
  2. Install the erlang and gnupg dependency packages.

    console
    $ sudo apt install gnupg erlang -y
    
  3. Install RabbitMQ.

    console
    $ sudo apt install rabbitmq-server -y
    

Manage the RabbitMQ System Service

RabbitMQ uses the rabbitmq-server system service to run and manage the application processes on your server. Follow the steps below to manage the RabbitMQ system service.

  1. Enable the RabbitMQ service to start at boot time.

    console
    $ sudo systemctl enable rabbitmq-server
    
  2. Start the RabbitMQ service.

    console
    $ sudo systemctl start rabbitmq-server
    
  3. View the RabbitMQ service status and verify that it's running.

    console
    $ sudo systemctl status rabbitmq-server
    

    Output:

    ● rabbitmq-server.service - RabbitMQ Messaging Server
    Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; preset: enabled)
    Active: active (running) since Fri 2024-07-05 15:42:24 UTC; 26s ago
    Main PID: 4122 (beam.smp)
       Tasks: 24 (limit: 9438)
    Memory: 98.8M (peak: 106.2M)
       CPU: 4.186s

Configure RabbitMQ

RabbitMQ uses a management plugin to enable access to the web management panel. Follow the steps below to enable the RabbitMQ plugin, create an administrative user account, and grant the user full permissions to the application processes.

  1. Enable the RabbitMQ management plugin.

    console
    $ sudo rabbitmq-plugins enable rabbitmq_management
    
  2. Create a new administrative user account with a strong password. Replace admin with your actual user and StrongPassword with your desired user password.

    console
    $ sudo rabbitmqctl add_user admin StrongPassword
    
  3. Grant the user administrative privileges.

    console
    $ sudo rabbitmqctl set_user_tags admin administrator
    
  4. Grant the user full permissions to all RabbitMQ resources on the server.

    console
    $ sudo rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"
    

    Within the above command:

    • .*: Grants configuration privileges to the user.
    • .*: Grants write privileges to the user on any resource.
    • .*: Grants read privileges to the user read.

Secure RabbitMQ

RabbitMQ listens for incoming connection requests on the default TCP port 15672 on your server. Set up a reverse proxy such as Nginx to secure the RabbitMQ port and process connection requests using a custom port such as the HTTP port 80. In addition, secure RabbitMQ connection using valid SSL certificates to enable HTTPS connections on the server as described in the following sections.

Set Up Nginx as a Reverse Proxy to Expose RabbitMQ

  1. Install Nginx.

    console
    $ sudo apt install nginx -y
    
  2. Enable Nginx to start at boot time.

    console
    $ sudo systemctl enable nginx
    
  3. Start the Nginx service.

    console
    $ sudo systemctl start nginx
    
  4. Disable the default Nginx configuration file.

    console
    $ sudo rm /etc/nginx/sites-enabled/default
    
  5. Create a new Nginx virtual host configuration such as rabbitmq.conf using a text editor such as nano.

    console
    $ sudo nano /etc/nginx/sites-available/rabbitmq.conf
    
  6. Add the following contents to the file. Replace rabbitmq.example.com with your actual domain.

    nginx
    server {
    listen 80;
    server_name  rabbitmq.example.com;
    
       location / {
               proxy_pass http://127.0.0.1:15672;
               proxy_set_header Host        $host;
               proxy_set_header X-Real-IP     $remote_addr;
               proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
               proxy_set_header Upgrade $http_upgrade;
               proxy_set_header Connection "upgrade";
               proxy_redirect off;
               proxy_http_version 1.1;
               proxy_max_temp_file_size 0;
               proxy_cache_bypass $http_upgrade;
       }
    }
    

    Save and close the file.

    The above Nginx configuration creates a new virtual host profile that listens for incoming connections on the HTTP port 80 using your domain rabbitmq.example.com and forwards all connection requests to the RabbitMQ localhost port 15672.

  7. Enable the virtual host configuration.

    console
    $ sudo ln -s /etc/nginx/sites-available/rabbitmq.conf /etc/nginx/sites-enabled/
    
  8. Test the Nginx configuration for errors.

    console
    $ sudo nginx -t
    
  9. Restart the Nginx service to apply the configuration changes.

    console
    $ sudo systemctl restart nginx
    
  10. Allow incoming connections to the HTTP port 80 through the default UFW firewall configuration.

    console
    $ sudo ufw allow 80
    
  11. Reload UFW to apply your configuration changes.

    console
    $ sudo ufw reload
    

Secure the RabbitMQ Console with Trusted SSL Certificates

  1. Install the Certbot Let's Encrypt Client tool.

    console
    $ sudo snap install certbot --classic
    
  2. Generate a new SSL certificate using your domain available in the Nginx virtual host configuration. Replace rabbitmq.example.com and admin@example.com with your actual details.

    console
    $ certbot --nginx -d rabbitmq.example.com -m admin@example.com --agree-tos
    
  3. Restart the Nginx service to apply your SSL configuration changes.

    console
    $ systemctl restart nginx
    
  4. Allow incoming connections to the HTTPS port 443 through the default UFW firewall configuration.

    console
    $ sudo ufw allow 443
    
  5. Reload UFW to apply your configuration changes.

    console
    $ sudo ufw reload
    
  6. Restart the RabbitMQ service.

    console
    $ systemctl restart rabbitmq-server
    

Access the RabbitMQ Console

  1. Access your domain using a web browser such as Chrome to access the RabbitMQ web administration console.

    https://your-domain.com

    Log in to the RabbitMQ Console using the admin user credentials you created earlier when prompted.

    RabbitMQ Login Page

  2. Click Nodes within the RabbitMQ console to view your active node statistics.

    RabbitMQ Administrative Interface

Conclusion

You installed RabbitMQ on a Ubuntu 24.04 server and secured the application to enable message streaming between applications. For more information, visit the RabbitMQ documentation.