edan.uk
Posted on
Linux

Step-by-Step Installation of RabbitMQ on Ubuntu 24.04

Author
Step-by-Step Installation of RabbitMQ on Ubuntu 24.04

RabbitMQ serves as a powerful open-source message broker that facilitates seamless communication between various distributed systems. With support for multiple messaging protocols and a highly extensible architecture, it enhances the reliability and responsiveness of applications while enabling quick integration and deployment. The following instructions will take you through the process of installing RabbitMQ on an Ubuntu 24.04 server, ensuring it is properly secured for use.

Prerequisites

Before starting the installation, prepare the following:

  • An active Ubuntu 24.04 instance.
  • A domain A record that points to the server's IP address (e.g., rabbitmq.example.com).
  • SSH access to the server as a non-root user with sudo privileges.

Installing RabbitMQ

RabbitMQ is included in the default Ubuntu package repositories. Start by installing the necessary Erlang and GnuPG packages, along with RabbitMQ itself:

  1. Check the available RabbitMQ package details:

    sudo apt-cache policy rabbitmq-server
    
  2. Install the required dependencies:

    sudo apt install gnupg erlang -y
    
  3. Install RabbitMQ:

    sudo apt install rabbitmq-server -y
    

Managing the RabbitMQ Service

After installation, RabbitMQ runs as a system service. Use the commands below to manage its operations:

  1. Ensure the RabbitMQ service starts automatically on boot:

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

    sudo systemctl start rabbitmq-server
    
  3. Confirm that the RabbitMQ service is running properly:

    sudo systemctl status rabbitmq-server
    

You should see output indicating that the service is active and running.

Configuring RabbitMQ

The RabbitMQ management plugin allows access to a web-based interface. Follow these steps to enable the plugin and create an admin user:

  1. Activate the RabbitMQ management plugin:

    sudo rabbitmq-plugins enable rabbitmq_management
    
  2. Create a new admin user with a strong password. Replace admin and StrongPassword with your desired credentials:

    sudo rabbitmqctl add_user admin StrongPassword
    
  3. Assign administrator privileges to this user:

    sudo rabbitmqctl set_user_tags admin administrator
    
  4. Grant full permissions to the user:

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

Securing RabbitMQ

RabbitMQ listens by default on port 15672. To enhance security, set up Nginx as a reverse proxy:

Setting Up Nginx

  1. Install Nginx:

    sudo apt install nginx -y
    
  2. Enable Nginx to run on startup:

    sudo systemctl enable nginx
    
  3. Start the Nginx service:

    sudo systemctl start nginx
    
  4. Remove the default Nginx configuration:

    sudo rm /etc/nginx/sites-enabled/default
    
  5. Create a new configuration file for RabbitMQ:

    sudo nano /etc/nginx/sites-available/rabbitmq.conf
    
  6. Input the following configuration, replacing rabbitmq.example.com with your own domain:

    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;
        }
    }
    
  7. Enable the new Nginx configuration:

    sudo ln -s /etc/nginx/sites-available/rabbitmq.conf /etc/nginx/sites-enabled/
    
  8. Test the Nginx configuration for correctness:

    sudo nginx -t
    
  9. Restart Nginx to apply the new configuration:

    sudo systemctl restart nginx
    
  10. Allow HTTP connections through the firewall:

    sudo ufw allow 80/tcp
    sudo ufw reload
    

Securing the Connection with SSL

Use Let's Encrypt to secure your RabbitMQ console with SSL:

  1. Install Certbot:

    sudo snap install certbot --classic
    
  2. Obtain the SSL certificate via the following command. Replace the domain and email with your actual details:

    certbot --nginx -d rabbitmq.example.com -m [email protected] --agree-tos
    
  3. Restart Nginx to implement the SSL configuration:

    sudo systemctl restart nginx
    
  4. Allow HTTPS connections through the firewall:

    sudo ufw allow 443/tcp
    sudo ufw reload
    
  5. Optionally, restart the RabbitMQ service:

    sudo systemctl restart rabbitmq-server
    

Accessing the RabbitMQ Console

Once everything is set up, visit your domain through a web browser:

https://rabbitmq.example.com

Log in with the admin credentials you created previously. From there, you can access the RabbitMQ management interface and monitor node statistics.

Conclusion

The RabbitMQ installation on Ubuntu 24.04 has been completed successfully, and the application is now secured for handling messages between your applications. For further details or customization, refer to the official RabbitMQ documentation.