RabbitMQ Setup on Ubuntu 24.04 with Comprehensive Steps

Posted on

RabbitMQ Setup on Ubuntu 24.04 with Comprehensive Steps

RabbitMQ Setup on Ubuntu 24.04 with Comprehensive Steps

This tutorial provides a comprehensive guide to performing a RabbitMQ Setup on Ubuntu 24.04. RabbitMQ is a powerful message broker that facilitates communication between different applications or services by enabling them to exchange messages. Think of it as a digital post office: one service sends a message to RabbitMQ, and RabbitMQ ensures that message is delivered to the correct recipient. This asynchronous communication paradigm is invaluable for building scalable, resilient, and decoupled systems. It ensures that messages are reliably delivered, even if the sender and receiver are not online simultaneously or are running on different machines. This contributes significantly to improved system efficiency and overall reliability.

You can now proceed to the guide steps below on the Orcacore website to get started with RabbitMQ Setup on Ubuntu 24.04.

Before you begin your RabbitMQ Setup on Ubuntu 24.04, ensure you have the following prerequisites: SSH access to your Ubuntu 24.04 system as a non-root user with sudo privileges. You can refer to guides on "Adding a Sudo User on Ubuntu 24.04" and "Basic UFW Firewall Configuration on Ubuntu 24.04" for assistance. Also, you need a domain name that is pointed to your server’s IP address. Now follow the steps below to get started with RabbitMQ setup on Ubuntu 24.04.

You can also check for the Video Tutorial Here:

1. Install RabbitMQ Server with Cloudsmith Mirror

Cloudsmith mirrors offer a reliable way to access RabbitMQ’s external dependencies. They ensure that these dependencies are readily available, well-maintained, and up-to-date, contributing to improved performance and reliability of RabbitMQ deployments.

In this article, we will use Cloudsmith Mirror to set up RabbitMQ server on Ubuntu 24.04. To set up dependencies, run the following curl command:

curl -1sLf 'https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/setup.deb.sh' | sudo -E bash

Once it is completed, you will get the following output:

Set up RabbitMQ with Cloudsmith Mirror on Ubuntu

Then, use the following command to install RabbitMQ server on Ubuntu:

sudo apt install rabbitmq-server -y

2. Start and Enable RabbitMQ System Service

After the installation is complete, you must start and enable the RabbitMQ service on Ubuntu 24.04 with the commands below:

# sudo systemctl start rabbitmq-server
# sudo systemctl enable rabbitmq-server

Verify that the RabbitMQ service is active and running on your Ubuntu system with the command below:

sudo systemctl status rabbitmq-server
Start and Enable RabbitMQ System Service

Also, you can check for the default port of RabbitMQ server which is ‘5672’:

sudo ss -tulpn
default port of RabbitMQ server

3. Configure RabbitMQ Plugins and Admin Account

RabbitMQ uses a management plugin to enable access to the web management panel. Enable the plugin using the command below:

sudo rabbitmq-plugins enable rabbitmq_management

In your output, you will see:

Enable RabbitMQ Plugins

Now you must create an Admin account for RabbitMQ with a strong password. To do this, run the command below:

sudo rabbitmqctl add_user <mark><strong>adminuser</strong></mark> <strong><mark>StrongPassword</mark></strong>

We create the Orca user:

Create Admin account for RabbitMQ

Next, grant the user administrative privileges to your admin account. To do this, run the command below:

sudo rabbitmqctl set_user_tags <mark><strong>adminuser</strong></mark> administrator
<strong><mark>Output:
</mark></strong>Setting tags for user "orca" to [administrator] ...

Finally, grant the user full permissions to all RabbitMQ resources on the server with the command below:

sudo rabbitmqctl set_permissions -p / <mark><strong>adminuser</strong></mark> ".*" ".*" ".*"
<strong><mark>Output:
</mark></strong>Setting permissions for user "orca" in vhost "/" ...

4. Set up Nginx Reverse Proxy for RabbitMQ

In this step, we configure Nginx as a reverse proxy for the RabbitMQ server on Ubuntu 24.04. To do this, install Nginx, start, and enable it using the commands below:

# sudo apt install nginx -y
# sudo systemctl start nginx
# sudo systemctl enable nginx

Then, disable or remove the default Nginx configuration file with the following command:

sudo rm /etc/nginx/sites-enabled/default

Now you must create a new Nginx server block for RabbitMQ. To do this, you can use your desired text editor like Vi Editor or Nano Editor:

sudo vi /etc/nginx/sites-available/rabbitmq.conf

Add the following configuration to the file with your actual domain name:

server {
listen 80;
server_name  <mark>example.com</mark>;

   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;
   }
}

Once you are done, save and close the file.

Next, enable your created Nginx config file with the following command:

sudo ln -s /etc/nginx/sites-available/rabbitmq.conf /etc/nginx/sites-enabled/

Check for Nginx syntax error:

sudo nginx -t

If everything is ok, you will see:

Check Nginx config file for RabbitMQ server

Finally, restart Nginx to apply the changes:

sudo systemctl restart nginx

Also, remember to allow port 80 through your UFW firewall on Ubuntu 24.04:

# sudo ufw allow 80
# sudo ufw reload

5. SSL Configuration for RabbitMQ Server (RabbitMQ Web Console Security)

Now for more security of the RabbitMQ server, you can use certbot to generate SSL certificates for your domain name. To do this, install certbot with the following command:

sudo snap install certbot --classic
<strong><mark>Output:
</mark></strong>certbot 3.2.0 from Certbot Project (certbot-eff&acirc;&#156;&#147;) installed

Then, get your SSL certificates from Let’s Encrypt using your domain available in the Nginx virtual host configuration:

sudo certbot --nginx -d <mark><strong>example.com</strong></mark>

Answer the question, such as email address, accept the terms of services, once it is completed, you will get the following output:

SSL Configuration for RabbitMQ Server
RabbitMQ Web Console Security with SSL Certificates

You can also set up auto renewal SSL certificates with the command below:

sudo certbot renew --dry-run

Then, restart Nginx to apply the changes:

sudo systemctl restart nginx

Next, allow incoming connections to the HTTPS port 443:

# sudo ufw allow 443
# sudo ufw reload

Finally, restart RabbitMQ server to apply the changes:

sudo systemctl restart rabbitmq-server

6. Access RabbitMQ Web Console

At this point, you can access your RabbitMQ web dashboard on Ubuntu 24.04 by following the URL below in your web browser:

https://<mark>your-domain.com</mark>

You will see the RabbitMQ login console. Enter your Admin user credentials you have created above and click Login.

RabbitMQ Login Console

Now you should see your RabbitMQ web console on Ubuntu 24.04. You can click on Nodes to view your active node statistics.

RabbitMQ web console on Ubuntu 24.04

That’s it, you are done with RabbitMQ Setup on Ubuntu 24.04. For more information, you can check the Official RabbitMQ Docs page.

Conclusion

At this point, you have learned to install and configure RabbitMQ on Ubuntu 24.04 and secure the web console access by generating the SSL certificate from Let’s Encrypt. Hope you enjoy it, please subscribe to us on Facebook, YouTube, and X.

Also, you may like to read the following articles:

Install Samba File Share on Ubuntu 24.04

Best Linux Desktop Distros for Teams to Access Remotely

Linux kernel 6.14 Release Date and Download

Details about Claude 3.7 Sonnet Hybrid Reasoner Model

Alternative Solutions for RabbitMQ Setup

While the above method using Cloudsmith and Nginx reverse proxy is a valid approach, there are alternative ways to achieve the same goal of installing and securing RabbitMQ on Ubuntu 24.04. Here are two different methods:

1. Using the Official RabbitMQ APT Repository

Instead of relying on Cloudsmith, you can directly use the official RabbitMQ APT repository. This method simplifies the dependency management and reduces reliance on third-party mirrors. It’s a more direct approach that can be faster and potentially more stable.

Explanation:

The official RabbitMQ repository provides direct access to the necessary Erlang dependencies and the RabbitMQ server package. By adding this repository to your system’s APT sources, you can install RabbitMQ and its dependencies using the standard apt package manager. This ensures that you are getting the software directly from the source and that updates are managed consistently with your system’s other packages.

Code Example:

First, add the RabbitMQ signing key:

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates
wget -O- https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey | sudo apt-key add -

Next, add the official RabbitMQ APT repository:

echo "deb https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu/ jammy main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list

Update the package lists and install RabbitMQ:

sudo apt-get update
sudo apt-get install rabbitmq-server -y

The remaining steps, starting from starting and enabling the RabbitMQ service, configuring plugins and admin accounts, and setting up SSL with Certbot, would remain largely the same as in the original guide.

2. Using Docker Compose

Docker Compose provides a containerized solution, abstracting away much of the underlying OS configuration. This approach is excellent for ensuring consistency across different environments and simplifying deployment.

Explanation:

Docker Compose allows you to define and manage multi-container Docker applications. By creating a docker-compose.yml file, you can specify the RabbitMQ image, its dependencies, and any necessary configuration. This approach encapsulates the entire RabbitMQ setup within a container, making it portable and easy to deploy on any system with Docker installed.

Code Example:

Create a docker-compose.yml file with the following content:

version: "3.8"
services:
  rabbitmq:
    image: rabbitmq:3.9-management
    ports:
      - "5672:5672"
      - "15672:15672"
    environment:
      RABBITMQ_DEFAULT_USER: admin
      RABBITMQ_DEFAULT_PASS: StrongPassword
    volumes:
      - rabbitmq_data:/var/lib/rabbitmq

volumes:
  rabbitmq_data:

This docker-compose.yml file defines a single service, rabbitmq, which uses the rabbitmq:3.9-management Docker image. It exposes ports 5672 (for AMQP) and 15672 (for the management UI). It also sets the default username and password for the RabbitMQ instance and defines a volume for persistent storage of RabbitMQ data.

To start the RabbitMQ container, run the following command:

docker-compose up -d

This command will download the RabbitMQ image (if it’s not already present), create a container from the image, and start the container in detached mode.

You can then access the RabbitMQ management UI by navigating to http://localhost:15672 in your web browser, using the username "admin" and the password "StrongPassword".

Securing with SSL in Docker:

To secure the Docker deployment with SSL, you’d need to modify the docker-compose.yml file and potentially create a custom Dockerfile to copy SSL certificates into the container and configure RabbitMQ to use them. This involves a more complex setup but provides a fully containerized and secured RabbitMQ instance. The RabbitMQ Setup on Ubuntu 24.04 can be simplified this way.

These alternative solutions provide different approaches to achieving the same goal: a functional and secure RabbitMQ installation on Ubuntu 24.04. The choice of method depends on your specific needs and preferences, but understanding these alternatives can help you make an informed decision.

Leave a Reply

Your email address will not be published. Required fields are marked *