How to Install RabbitMQ on Debian 12
Introduction
RabbitMQ is a popular, lightweight, open-source message broker that implements the Advanced Message Queuing Protocol (AMQP). It enables applications to exchange messages asynchronously, decouple them from each other and improve scalability.
This article explains how to install RabbitMQ on Debian 12.
Prerequisites
Before you begin:
- Deploy a Debian 12 instance on Vultr.
- Create a new domain A record pointing to the instance's IP address. For example,
rabbitmq.example.com
. - Access the server using SSH as a non-root user with sudo privileges
Install RabbitMQ
Erlang is a RabbitMQ dependency package required on a server. asdf is a CLI tool that can manage language runtime versions on a per-project basis and enables the smooth installation of Erlang. Follow the steps below to enable all dependency packages and install RabbitMQ on your server.
Install all required asdf dependencies.
console$ sudo apt install curl git -y
Download asdf using the official project repository.
console$ git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
Open the
.bashrc
file in your environment.console$ nano ~/.bashrc
Add the following directives at the end of the file.
ini. "$HOME/.asdf/asdf.sh" . "$HOME/.asdf/completions/asdf.bash"
Save and lose the file.
Reload the
.bashrc
file in your session.console$ source ~/.bashrc
View the asdf version on your server.
console$ asdf --version
Output:
version: v0.14.0-ccdd47d ...
Install the
asdf-erlang
plugin.console$ asdf plugin add erlang https://github.com/asdf-vm/asdf-erlang.git
Install all necessary Erlang dependencies.
console$ sudo apt-get -y install build-essential autoconf m4 libncurses-dev libwxgtk3.2-dev libwxgtk-webview3.2-dev libgl1-mesa-dev libglu1-mesa-dev libpng-dev libssh-dev unixodbc-dev xsltproc fop libxml2-utils openjdk-17-jdk
Create a new environment variable to skip Java dependency warnings during installation.
console$ export KERL_CONFIGURE_OPTIONS="--disable-debug --without-javac"
Install the Erlang version
26.1.2
console$ asdf install erlang 26.1.2
Set the global Erlang version to use on the server.
console$ asdf global erlang 26.1.2
Access the Erlang shell to verify your installation.
console$ erl
Output:
Erlang/OTP 26 [erts-14.1.1] [source] [64-bit] [smp:1:1] [ds:1:1:10] [async-threads:1] [jit:ns] Eshell V14.1.1 (press Ctrl+G to abort, type help(). for help) 1>
Enter A and press Enter to exit the Erlang shell.
Install the RabbitMQ Package
Install RabbitMQ.
console$ sudo apt install rabbitmq-server -y --fix-missing
The above command installs the latest version of RabbitMQ server package and fixes any broken dependencies on your server.
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 (/lib/systemd/system/rabbitmq-server.service; enabled; preset: enabled) Active: active (running) since Mon 2024-08-26 09:35:15 UTC; 25s ago Main PID: 50330 (beam.smp) Tasks: 22 (limit: 2299) Memory: 97.4M CPU: 3.131s
Enable the RabbitMQ service to automatically start at system boot.
console$ sudo systemctl enable rabbitmq-server
Start the RabbitMQ service.
console$ sudo systemctl start rabbitmq-server
Configure RabbitMQ
Follow the steps below to configure RabbitMQ on your server.
List all RabbitMQ virtual hosts.
console$ sudo rabbitmqctl list_vhosts
Create a new RabbitMQ virtual host to use in your applications. Replace
myhost
with your desired virtual host.console$ sudo rabbitmqctl add_vhost myhost
Create a new RabbitMQ user and assign the user a strong password.
console$ sudo rabbitmqctl add_user example-user strong-password
Grant the user administrative privileges to use RabbitMQ.
console$ sudo rabbitmqctl set_user_tags example-user administrator
Grant the user full permissions to all RabbitMQ virtual hosts, exchanges, queues, bindings, and routing keys.
console$ sudo rabbitmqctl set_permissions -p myhost example-user ".*" ".*" ".*"
Secure RabbitMQ
Follow the steps below to disable the guest user and secure the RabbitMQ web management console with trusted SSL certificates on your server.
Disable the RabbitMQ guest user profile.
console$ sudo rabbitmqctl delete_user guest
Open the main RabbitMQ configuration file to enable user authentication.
console$ sudo nano /etc/rabbitmq/rabbitmq.conf
Add the following directive at the end of the file.
iniauth_backends.1 = internal
Save and close the file.
Restart RabbitMQ to apply changes.
console$ sudo systemctl restart rabbitmq-server
Install the Nginx web server to work as a reverse proxy with RabbitMQ.
console$ sudo apt install nginx -y
Create a new Nginx virtual host configuration for RabbitMQ.
console$ sudo nano /etc/nginx/sites-available/rabbitmq.conf
Add the following configurations to the file. Replace
rabbitmq.example.com
with your actual domain.nginxserver { listen 80; listen [::]:80; server_name rabbitmq.example.com; location / { proxy_pass http://localhost: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 X-Forwarded-Proto $scheme; } location /mqtt { proxy_pass http://localhost:15675; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; 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 X-Forwarded-Proto $scheme; } }
Save and close the file.
The above Nginx configuration listens for incoming network connections on the HTTP port
80
to serve the RabbitMQ console from port15672
and the/mqtt
path for web socket connections.Disable the default virtual host configuration.
console$ sudo rm /etc/nginx/sites-enabled/default
Create a new symbolic link to the
/sites-enabled
directory to enable the virtual host configuration.console$ sudo ln -s /etc/nginx/sites-available/rabbitmq.conf /etc/nginx/sites-enabled/
Test the Nginx configuration for errors.
console$ sudo nginx -t
Output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Restart the Nginx service.
console$ sudo systemctl restart nginx
Install the Certbot Let's Encrypt client plugin for Nginx.
console$ sudo apt install python3-certbot-nginx certbot -y
Allow network connections on the HTTP port
80
through the firewall to enable Let's Encrypt validations.console$ sudo ufw allow 80/tcp
Restart UFW to apply changes.
console$ sudo ufw reload
Generate a new SSL certificate to use with your Nginx virtual host and RabbitMQ domain
rabbitmq.example.com
. Replacehello@example.com
with your actual email.console$ sudo certbot --nginx -d rabbitmq.example.com -m hello@example.com --agree-tos
Your output should be similar to the one below when successful.
Successfully received certificate. Certificate is saved at: /etc/letsencrypt/live/rabbitmq.example.com/fullchain.pem Key is saved at: /etc/letsencrypt/live/rabbitmq.example.com/privkey.pem Deploying certificate Successfully deployed certificate for rabbitmq.example.com to /etc/nginx/sites-enabled/rabbitmq.conf Congratulations! You have successfully enabled HTTPS on https://rabbitmq.example.com
Restart Nginx to apply the SSL configuration changes.
console$ sudo systemctl restart nginx
Allow HTTPS connections on port
443
through the firewall.console$ sudo ufw allow 443/tcp
Restart UFW to apply changes.
console$ sudo ufw reload
Access the RabbitMQ Console
You can access the RabbitMQ console to monitor and manage your server functionalities. Follow the steps below to enable the RabbitMQ management plugin, and access the web administration console to perform tasks such as queue monitoring.
Enable the RabbitMQ management plugin.
console$ sudo rabbitmq-plugins enable rabbitmq_management
Output:
The following plugins have been enabled: rabbitmq_management rabbitmq_management_agent rabbitmq_web_dispatch started 3 plugins.
View all RabbitMQ plugins and verify that the management plugin is active.
console$ sudo rabbitmq-plugins list | grep management
Output:
[ ] rabbitmq_federation_management 3.10.8 [E*] rabbitmq_management 3.10.8 [e*] rabbitmq_management_agent 3.10.8 [ ] rabbitmq_shovel_management 3.10.8 [ ] rabbitmq_stream_management 3.10.8
Based on the above output, the web administration management plugin is enabled based on the
[E]
prompt.Access your RabbitMQ domain using a web browser such as Chrome to access the web administration console.
https://rabbitmq.example.com
Enter your administrative RabbitMQ user and password details you created earlier to log in to the console.
Use the RabbitMQ management interface to view active nodes, users, virtual hosts, queues, exchanges, and perform management tasks on the server.
Conclusion
You have installed RabbitMQ on a Debian 12 server and secured access to the web administration console. RabbitMQ implements message-based architectures, microservices, and distributed systems you can use with existing applications on your server. For more information and configuration options, visit the RabbitMQ documentation.