bolt Valebyte VPS desde $4/mes — NVMe, despliegue en 60s.

Obtener VPS arrow_forward
eco Principiante Tutorial/Cómo hacer

Installing and Configuring RabbitMQ

calendar_month Jul 30, 2026 schedule 22 min de lectura visibility 19 vistas
Установка и настройка RabbitMQ на VPS для асинхронной обработки задач
info

¿Necesitas un servidor para esta guía? Ofrecemos servidores dedicados y VPS en más de 50 países con configuración instantánea.

¿Necesitas un VPS para esta guía?

Explore otras opciones de servidores dedicados en

Installing and Configuring RabbitMQ on a VPS for Asynchronous Task Processing

TL;DR

In this detailed guide, we will set up RabbitMQ step-by-step on a clean VPS server. RabbitMQ is a popular message broker that allows applications to interact asynchronously, process background tasks, build fault-tolerant systems, and distribute load. You will learn how to prepare the server, install all necessary components, configure RabbitMQ, secure it, and create a backup system for the stable operation of your applications.

  • VPS preparation: basic security (SSH, sudo, UFW, Fail2Ban) and system update.
  • Installation of RabbitMQ and Erlang from official repositories, current for 2026.
  • Configuration of virtual hosts, users, and permissions for secure operation.
  • Enabling and securing the RabbitMQ management web interface (Management UI) using TLS/HTTPS.
  • Creating a simple script for automatic backup of RabbitMQ configuration and data.
  • Recommendations for monitoring, scaling, and troubleshooting common issues.

What we are configuring and why

Diagram: What we are configuring and why
Diagram: What we are configuring and why

In the modern world, web applications and microservices often face the need to perform tasks that can take a long time or require processing large volumes of data without an immediate response to the user. This is where message brokers like RabbitMQ come to the rescue. RabbitMQ is one of the most popular and reliable open-source message brokers, implementing the Advanced Message Queuing Protocol (AMQP).

We will be configuring RabbitMQ on our own Virtual Private Server (VPS) to create a flexible and scalable messaging system. Ultimately, you will have a fully functional message broker that you can integrate with your applications for the following purposes:

  • Asynchronous Task Processing: Sending tasks to a queue (e.g., image processing, email sending, report generation) so that the main application is not blocked.
  • Distributed Systems: Exchanging messages between various microservices running on different servers or in different containers.
  • Fault Tolerance: Messages are stored in the queue even if the consumer is temporarily unavailable, guaranteeing their delivery upon recovery.
  • Load Balancing: Distributing tasks among multiple handler instances, increasing throughput.

Alternatives and choosing self-hosted on a VPS

There are several approaches to managing a message broker. You can use cloud-managed services, such as Amazon SQS/SNS, Google Cloud Pub/Sub, Azure Service Bus, or deploy the broker yourself (self-hosted) on a VPS or dedicated server.

Cloud solutions offer convenience, automatic scaling, and minimal administration. They are ideal for startups with limited DevOps resources or for companies already deeply integrated into a specific cloud provider's ecosystem. However, they can be more expensive at large volumes, tied to a specific provider (vendor lock-in), and offer less flexibility in fine-tuning.

Self-hosted RabbitMQ on a VPS, which is what we will be configuring, provides full control over the environment, configuration, and security. This is an excellent choice for:

  • Data Control: If you have strict requirements for data sovereignty or location.
  • Cost Optimization: For large volumes of traffic or stable loads, your own VPS often proves more economical than cloud alternatives.
  • Flexibility: The ability to install specific plugins, fine-tune performance, and integrate with existing infrastructure.
  • Learning and Experimentation: Understanding the internal workings of the system, which is useful for developers and system administrators.

By choosing a self-hosted approach on a VPS, you gain a powerful tool for building scalable and fault-tolerant applications with full control over the infrastructure.

What VPS configuration is needed for this task

Diagram: What VPS configuration is needed for this task
Diagram: What VPS configuration is needed for this task

Choosing the right VPS configuration for RabbitMQ depends on the anticipated load: the number of messages per second, their size, the number of queues, and connected clients. However, for most typical asynchronous processing tasks, you can start with reasonable minimum requirements.

Minimum Requirements for RabbitMQ (for ~100-500 messages/sec)

  • CPU: 2 vCPU. RabbitMQ is single-threaded for message processing in a queue but multi-threaded for network operations, TLS, and plugins. Two cores will provide sufficient performance for most scenarios.
  • RAM: 4 GB. RabbitMQ stores messages in RAM (if they are not persistent or do not exceed threshold values). For stable operation and handling peak loads, 4 GB of RAM is a good start. Less is possible, but you will need to carefully monitor memory and disk space usage.
  • Disk: 80-100 GB SSD. RabbitMQ actively uses the disk for persistent messages, queue indexes, and swap files. SSD is critically important for performance. A volume of 80-100 GB will provide space for the operating system, RabbitMQ, and a sufficient buffer for data growth.
  • Network: 100 Mbps or 1 Gbps. For most tasks, 100 Mbps will be sufficient, but if you plan to transfer large volumes of data or have many connections, 1 Gbps will be preferable. Channel stability is important.

Recommended VPS Plan to Start (for ~500-2000 messages/sec)

For more serious tasks, or if you don't want to worry about upgrading anytime soon, consider the following configuration:

  • CPU: 4 vCPU.
  • RAM: 8 GB.
  • Disk: 160-200 GB NVMe SSD (or fast SATA SSD).
  • Network: 1 Gbps.

This configuration will ensure comfortable operation with RabbitMQ, allowing you to process significant volumes of messages and have a safety margin. You can rent a VPS with the specified characteristics to get started.

When a dedicated server is needed, not a VPS

A dedicated server becomes necessary when:

  • Very High Load: Thousands or tens of thousands of messages per second, especially if they are large in volume.
  • Strict Performance Requirements: The need for guaranteed performance without "noisy neighbors," which sometimes occurs on a VPS.
  • Large Data Volume: If you plan to store a very large number of persistent messages on disk.
  • Complex Clustering: For building highly available and fault-tolerant RabbitMQ clusters with many nodes, where each node requires significant resources.
  • Security Requirements: Full physical control over the hardware.

For most projects, especially at the start, a VPS is more than sufficient. The transition to a dedicated server usually occurs as the project grows and the load increases.

VPS Location: What it affects

The choice of VPS location directly impacts the latency between your application and the message broker. It is desirable for the RabbitMQ VPS to be as close as possible to the servers that will send and receive messages. This minimizes ping and improves overall system performance.

  • If your main applications are located in Europe, choose a European data center.
  • If users are distributed worldwide, you might need multiple RabbitMQ instances in different geographical locations or use a CDN for the frontend, and place the backend in a central location.
  • For testing and development, location usually does not have critical importance.

Server Preparation

Diagram: Server Preparation
Diagram: Server Preparation

Before installing RabbitMQ, you need to perform basic setup and security hardening for a fresh VPS. We will use Ubuntu Server 24.04 LTS, as it is one of the most popular and well-supported operating systems for servers.

1. SSH Connection and System Update

First, connect to your new VPS as the root user (if the provider granted root access) or as the user specified by the provider.


ssh root@YOUR_VPS_IP_ADDRESS

After a successful login, update the package list and installed packages to their latest versions. This is important for security and stability.


sudo apt update && sudo apt upgrade -y

2. Creating a New User with Sudo Privileges

Working as the root user is unsafe. Let's create a new user and grant them sudo privileges.


sudo adduser username_admin # Replace username_admin with your desired username

Follow the on-screen instructions to set a password and other information (you can leave it blank). Then, add the user to the sudo group:


sudo usermod -aG sudo username_admin

Now you can switch to this user or open a new SSH session as them. For further actions, use

sudo
.


su - username_admin

3. Configuring SSH Keys (Recommended)

To enhance security, it is recommended to use SSH keys instead of passwords. Generate a key on your local machine (if you haven't already):


ssh-keygen -t rsa -b 4096

Copy your public key to your VPS:


ssh-copy-id username_admin@YOUR_VPS_IP_ADDRESS

After this, disable password login for root and allow login only with keys. Edit the SSH configuration file:


sudo nano /etc/ssh/sshd_config

Find and change the following lines (or add them if they are missing):


# Disable root login
PermitRootLogin no

# Allow key authentication
PubkeyAuthentication yes

# Disable password authentication (after you ensure key login works!)
PasswordAuthentication no

Save the file (Ctrl+O, Enter) and exit (Ctrl+X). Restart the SSH service:


sudo systemctl restart sshd

IMPORTANT: Before closing the current SSH session, open a new session and ensure you can log in as

username_admin
using your SSH key. If login fails, do not close the current session and fix the errors.

4. Firewall Configuration (UFW)

Uncomplicated Firewall (UFW) is an easy-to-use interface for iptables. We will configure it to allow only the necessary ports.

Install UFW if it's not already installed:


sudo apt install ufw -y

Allow SSH (port 22), HTTP (port 80), HTTPS (port 443), and RabbitMQ ports:


sudo ufw allow OpenSSH
sudo ufw allow http
sudo ufw allow https
sudo ufw allow 5672/tcp  # Standard AMQP port for clients
sudo ufw allow 15672/tcp # Management UI port (HTTP)
sudo ufw allow 25672/tcp # Port for cluster node communication (Erlang distribution)
sudo ufw allow 4369/tcp  # Port for cluster node communication (Erlang Port Mapper Daemon)

Enable the firewall:


sudo ufw enable

Check the firewall status:


sudo ufw status verbose

5. Installing Fail2Ban

Fail2Ban scans logs and blocks IP addresses that show signs of malicious attacks (e.g., multiple failed SSH login attempts).


sudo apt install fail2ban -y

After installation, Fail2Ban starts working automatically. You can configure it by copying the main configuration file:


sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo nano /etc/fail2ban/jail.local

In the

jail.local
file, you can modify parameters such as
bantime
(ban time) and
maxretry
(number of attempts). Ensure that the
sshd
jail is enabled:


[sshd]
enabled = true

Save and close the file, then restart Fail2Ban:


sudo systemctl restart fail2ban

Your server is now ready for RabbitMQ installation with basic security measures.

Software Installation — Step-by-Step

Diagram: Software Installation — Step-by-Step
Diagram: Software Installation — Step-by-Step

RabbitMQ installation consists of two main steps: first, installing Erlang (on which RabbitMQ is written), and then RabbitMQ itself. We will use official repositories for Ubuntu to ensure up-to-date versions and easy updates.

1. Adding Official Erlang and RabbitMQ Repositories

As of 2026, the most stable and up-to-date versions of Erlang and RabbitMQ for Ubuntu 24.04 LTS (Noble Numbat) can be obtained from official repositories. This ensures you receive the latest security patches and functional updates.

Adding Erlang Solutions Repository

RabbitMQ requires a specific version of Erlang/OTP. It is recommended to use packages from Erlang Solutions, as they are often more up-to-date than those available in standard Ubuntu repositories.


# Install necessary utilities for working with HTTPS repositories
sudo apt install -y curl gnupg apt-transport-https

# Add Erlang Solutions GPG key
curl -fsSL https://packages.erlang-solutions.com/ubuntu/erlang_solutions.asc | sudo gpg --dearmor -o /usr/share/keyrings/erlang-solutions.gpg

# Add Erlang Solutions repository for Ubuntu 24.04
echo "deb [signed-by=/usr/share/keyrings/erlang-solutions.gpg] https://packages.erlang-solutions.com/ubuntu noble contrib" | sudo tee /etc/apt/sources.list.d/erlang-solutions.list > /dev/null

# Update package list
sudo apt update
Adding RabbitMQ Repository

Similarly, let's add the official RabbitMQ repository.


# Add RabbitMQ GPG key
curl -fsSL https://www.rabbitmq.com/rabbitmq-release-signing-key.asc | sudo gpg --dearmor -o /usr/share/keyrings/rabbitmq.gpg

# Add RabbitMQ repository for Ubuntu 24.04
echo "deb [signed-by=/usr/share/keyrings/rabbitmq.gpg] https://packagecloud.io/rabbitmq/rabbitmq-server/ubuntu noble main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list > /dev/null

# Update package list again
sudo apt update

2. Installing Erlang/OTP

Now that the repositories are added, you can install Erlang. Erlang/OTP version 26.0 (or newer, current as of 2026) is recommended for RabbitMQ 3.13.0+.


# Install Erlang/OTP
sudo apt install -y erlang-nox

Ensure Erlang is installed correctly and check its version:


erl -version
# The expected output will be similar to: Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 14.0.5 (or similar for OTP 26.x)

3. Installing RabbitMQ Server

After installing Erlang, you can proceed with installing RabbitMQ.


# Install RabbitMQ Server
sudo apt install -y rabbitmq-server

After installation, the RabbitMQ server should start automatically. You can check its status with the following command:


sudo systemctl status rabbitmq-server

You should see the status

active (running)
.

4. Enabling RabbitMQ Management Plugin

The management plugin provides a convenient web interface for monitoring and administering RabbitMQ. This is very useful for visualizing queues, exchanges, connections, and users.


# Enable RabbitMQ management plugin
sudo rabbitmq-plugins enable rabbitmq_management

After enabling the plugin, the web interface will be available at

http://YOUR_VPS_IP_ADDRESS:15672/
. By default, there is no access to it until we create a user.

5. Adding a User and Setting Permissions

By default, RabbitMQ creates a

guest
user with password
guest
, but this user can only connect from
localhost
. To access the Management UI and for client applications from outside, you need to create a new user with appropriate permissions.


# Create a new user (replace myuser and mypassword with your values)
sudo rabbitmqctl add_user myuser mypassword

# Grant administrator rights to the user for Management UI access
sudo rabbitmqctl set_user_tags myuser administrator

# Set permissions for the default virtual host "/"
# This grants the user myuser full access to the default virtual host
sudo rabbitmqctl set_permissions -p / myuser "." "." "."

Now you can try to log in to the web interface at

http://YOUR_VPS_IP_ADDRESS:15672/
, using
myuser
and
mypassword
.

6. Verifying Functionality

You can check if RabbitMQ is running and listening on ports using

netstat
(or
ss
).


# Install net-tools if not already installed
sudo apt install -y net-tools

# Check RabbitMQ open ports
sudo netstat -tulnp | grep LISTEN | grep -E '5672|15672|25672|4369'

You should see entries for ports 5672 (AMQP), 15672 (Management UI), 25672, and 4369 (Erlang distribution). This confirms that RabbitMQ is successfully installed and running.

Configuration

Diagram: Configuration
Diagram: Configuration

RabbitMQ has many configuration parameters that allow fine-tuning its behavior, security, and performance. The main configuration files are located in the

/etc/rabbitmq/
directory.

1. Main RabbitMQ Configuration File

The main RabbitMQ configuration file is

rabbitmq.conf
. By default, it may not exist, and RabbitMQ uses its internal settings. To make changes, create or edit this file.


sudo nano /etc/rabbitmq/rabbitmq.conf

Example of a basic configuration that can be added to improve security and performance:


# /etc/rabbitmq/rabbitmq.conf

## Increase file descriptors (important for a large number of connections)
# rabbitmq.server.fd_limit = 1048576

## Memory policy settings (if RAM is less than 8GB, it can be reduced)
# Default 40% RAM. An absolute value can be set, e.g., 2GB
# vm_memory_high_watermark.absolute = 2GB
vm_memory_high_watermark.relative = 0.6 # Use 60% RAM if you have 4GB RAM or more

## Disk policy settings (when RabbitMQ starts blocking publications)
# disk_free_limit.absolute = 50MB # Block if disk space remaining is less than 50MB
disk_free_limit.relative = 2.0 # Block if free space is less than 2x RAM

## Logging settings
log.console = false
log.file = rabbit@%h.log
log.file.level = info
log.dir = /var/log/rabbitmq

## Disable guest user from external access
# If you have created a separate user for access, it's better to disable the guest user
loopback_users.guest = false

## Increase maximum number of channels (default 2047)
# channel_max = 1024

## Heartbeat timeouts for detecting dead connections
# heartbeat = 60

After changing the configuration file, you need to restart RabbitMQ:


sudo systemctl restart rabbitmq-server

2. Managing Virtual Hosts

Virtual hosts (vhosts) in RabbitMQ provide a way to isolate environments for different applications or teams, which is very useful for security and organization. By default, there is one virtual host

/
.

Let's create a new virtual host for your application:


# Create a new virtual host
sudo rabbitmqctl add_vhost /my_app_vhost

Now let's create a user specific to this virtual host and grant them the appropriate permissions:


# Create a user for the application
sudo rabbitmqctl add_user app_user app_password

# Set permissions for the new virtual host
# Syntax: set_permissions [-p vhost] user conf write read
# conf: configure exchanges and queues (create/delete)
# write: publish messages
# read: consume messages
sudo rabbitmqctl set_permissions -p /my_app_vhost app_user "." "." "."

You can check the list of virtual hosts and their permissions via the Management UI or by command:


sudo rabbitmqctl list_vhosts
sudo rabbitmqctl list_permissions -p /my_app_vhost

3. Securing the Management UI with TLS/HTTPS (via Caddy)

Accessing the Management UI over HTTP (port 15672) is insecure, as credentials are transmitted in plain text. It is recommended to use HTTPS. We will set up a reverse proxy with Caddy, which automatically manages Let's Encrypt certificates.

Installing Caddy

Caddy is a powerful web server with automatic HTTPS. Its installation is simple:


# Install necessary packages
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https

# Add Caddy GPG key
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg

# Add Caddy repository
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list

# Update package list and install Caddy
sudo apt update
sudo apt install -y caddy
Configuring Caddyfile

Edit the Caddy configuration file:

/etc/caddy/Caddyfile
.


sudo nano /etc/caddy/Caddyfile

Remove all content and add the following block. Replace

rabbitmq.yourdomain.com
with your actual domain that points to your VPS IP. Make sure the DNS record for this domain is already configured.


rabbitmq.yourdomain.com {
    reverse_proxy localhost:15672
    # Optional: basic authentication for additional protection
    # basicauth {
    #     username_for_caddy JCRYPTED_PASSWORD_HASH
    # }
}

If you want to add basic authentication at the Caddy level, generate a password hash using

caddy hash-password
(you will need to install
caddy
locally or on the server without
sudo
).


# On your local machine or server (if caddy is already installed)
caddy hash-password --plaintext your_caddy_password
# Copy the resulting hash and paste it into the Caddyfile

Save

Caddyfile
and check its syntax:


sudo caddy validate --config /etc/caddy/Caddyfile

If everything is in order, restart Caddy:


sudo systemctl reload caddy

Now you can access the Management UI at

https://rabbitmq.yourdomain.com
. Caddy will automatically obtain and renew the Let's Encrypt certificate.

4. Secrets via Environment Variables

Instead of hardcoding sensitive data (passwords, keys) in configuration files, it is recommended to use environment variables. For RabbitMQ, this can be done by creating the file

/etc/rabbitmq/rabbitmq-env.conf
.


sudo nano /etc/rabbitmq/rabbitmq-env.conf

Add environment variables, for example:


# /etc/rabbitmq/rabbitmq-env.conf
RABBITMQ_NODE_IP_ADDRESS=0.0.0.0 # Listen on all interfaces
RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS="+P 1048576" # Increase Erlang process limit

This is not for RabbitMQ passwords directly (they are managed via

rabbitmqctl
), but for other settings that might be sensitive or vary depending on the environment. For RabbitMQ user passwords, use
rabbitmqctl
and store them in a secure password manager, not in files on the server.

5. Verifying Functionality

After all configurations, it is important to ensure that RabbitMQ is working correctly.

Checking RabbitMQ Status

sudo rabbitmqctl status

This command will show detailed information about the RabbitMQ node's status, including Erlang version, ports used, number of queues, connections, etc.

Checking Management UI Connection

Open your browser and go to

https://rabbitmq.yourdomain.com
(or
http://YOUR_VPS_IP_ADDRESS:15672/
, if you haven't configured Caddy). Log in with credentials
myuser
/
mypassword
(or
app_user
/
app_password
for the respective vhost).

Checking via curl (for advanced users)

You can use

curl
to check the Management UI API:


# Check node information
curl -u myuser:mypassword https://rabbitmq.yourdomain.com/api/nodes
# Check virtual host information
curl -u myuser:mypassword https://rabbitmq.yourdomain.com/api/vhosts

These commands should return JSON responses with information about your RabbitMQ server, confirming its functionality and API availability.

Backups and Maintenance

Diagram: Backups and Maintenance
Diagram: Backups and Maintenance

Regular backups and proper maintenance are critically important for ensuring the reliability and long-term stability of your RabbitMQ installation. Data loss or incorrect broker operation can lead to serious problems in your applications.

What to Back Up for RabbitMQ

In the context of RabbitMQ, "data" does not always mean the messages themselves in queues (many of them are temporary). The most important items for backup are:

  1. RabbitMQ Definitions: These are metadata such as virtual hosts, users, their permissions, queues, exchanges, and bindings. This is critically important for restoring the broker's structure.
  2. Configuration Files: Any modified files in
    /etc/rabbitmq/
    , such as
    rabbitmq.conf
    ,
    rabbitmq-env.conf
    , as well as certificate files if you are using TLS for AMQP connections.
  3. Persistent Message Data: If you use persistent queues and messages, RabbitMQ stores them on disk in
    /var/lib/rabbitmq/mnesia/
    . Backing up this directory can be complex, as RabbitMQ must be stopped to create a consistent snapshot. For active systems, it is often preferable to restore persistent messages from the source systems rather than from a RabbitMQ backup.

For most scenarios, backing up definitions and configuration files is sufficient.

Simple RabbitMQ Definitions Auto-Backup Script

We will create a script that will export RabbitMQ definitions to a JSON file and save it. For storage, you can use S3-compatible storage or another VPS.


#!/bin/bash

# Directory for storing backups on the server
BACKUP_DIR="/var/backups/rabbitmq"
DATE=$(date +%Y%m%d%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/rabbitmq_definitions_${DATE}.json"
CONFIG_FILES="/etc/rabbitmq/rabbitmq.conf /etc/rabbitmq/rabbitmq-env.conf" # Add other important configs here, e.g., certificates

# Create backup directory if it doesn't exist
mkdir -p "${BACKUP_DIR}"

echo "Starting RabbitMQ definitions backup..."

# Export RabbitMQ definitions
sudo rabbitmqctl export_definitions "${BACKUP_FILE}"

# Check if export was successful
if [ $? -eq 0 ]; then
    echo "RabbitMQ definitions exported to ${BACKUP_FILE}"
    
    # Copying configuration files
    for file in ${CONFIG_FILES}; do
        if [ -f "${file}" ]; then
            cp "${file}" "${BACKUP_DIR}/$(basename ${file})_${DATE}"
            echo "Copied ${file} to ${BACKUP_DIR}/$(basename ${file})_${DATE}"
        else
            echo "Warning: Configuration file ${file} not found."
        fi
    done

    # Clean up old backups (keep last 7 days)
    find "${BACKUP_DIR}" -type f -name "rabbitmq_definitions_*.json" -mtime +7 -delete
    find "${BACKUP_DIR}" -type f -name "*_${DATE}" -mtime +7 -delete # For configs, if they have the same date in the name
    echo "Old backups cleaned up."

    # Optional: upload to S3-compatible storage (requires awscli or s3cmd)
    # aws s3 cp "${BACKUP_FILE}" s3://your-s3-bucket/rabbitmq/definitions/
    # aws s3 cp "${BACKUP_DIR}/rabbitmq.conf_${DATE}" s3://your-s3-bucket/rabbitmq/configs/

else
    echo "ERROR: Failed to export RabbitMQ definitions."
    exit 1
fi

echo "RabbitMQ backup script finished."

Save this script, for example, as

/usr/local/bin/backup_rabbitmq.sh
, and make it executable:


sudo nano /usr/local/bin/backup_rabbitmq.sh
sudo chmod +x /usr/local/bin/backup_rabbitmq.sh

Then add it to

cron
for daily execution:


sudo crontab -e

Add the following line to execute the script daily at 03:00 AM:


0 3 * * * /usr/local/bin/backup_rabbitmq.sh >> /var/log/rabbitmq_backup.log 2>&1

Where to Store Backups

Storing backups on the same server as the main service is highly discouraged. In case of server failure, you will lose both data and backups. Options:

  • Cloud Storage (S3-compatible): Amazon S3, DigitalOcean Spaces, Backblaze B2. This is an economical and reliable option. Use
    awscli
    or
    s3cmd
    for automatic uploads.
  • Separate VPS: A small VPS with a large disk, configured as a backup storage (e.g., using
    rsync
    or
    borgbackup
    over SSH).
  • Local NAS/Server: If you have your own infrastructure, you can use it.

Restoring from Backup

To restore RabbitMQ definitions:

  1. Install RabbitMQ on a new server.
  2. Stop RabbitMQ:
    sudo systemctl stop rabbitmq-server
    .
  3. Copy your
    rabbitmq_definitions_*.json
    backup to the server.
  4. Restore definitions:
    sudo rabbitmqctl import_definitions /path/to/rabbitmq_definitions.json
    .
  5. Copy configuration files from the backup to
    /etc/rabbitmq/
    .
  6. Start RabbitMQ:
    sudo systemctl start rabbitmq-server
    .

Updates: rolling vs maintenance window

Updating RabbitMQ and Erlang is an important part of maintenance. The approach depends on whether you are using a cluster or a single node.

  • Single Node: A maintenance window will be required, as RabbitMQ will be unavailable during the update. Schedule the update during periods of minimal load.
  • Cluster (rolling upgrade): In a clustered configuration, a rolling upgrade can be performed, where each node is updated in turn while other nodes continue to serve requests. This ensures high availability but requires more complex setup and planning.

Always test updates in a staging environment before applying them to production. A full backup is recommended before updating.


# Update packages
sudo apt update
sudo apt upgrade -y

# After updating Erlang or RabbitMQ, always restart the service
sudo systemctl restart rabbitmq-server

Regularly check official RabbitMQ and Erlang announcements for information on new versions and important changes.

Troubleshooting + FAQ

Various issues can arise when working with RabbitMQ. In this section, we will cover typical scenarios and provide answers to frequently asked questions.

Cannot connect to RabbitMQ from a client, or Management UI is unavailable. What to do?

What to check:

  1. Firewall (UFW): Ensure that RabbitMQ ports (5672 for AMQP, 15672 for Management UI) are open on your VPS. Use
    sudo ufw status verbose
    .
  2. RabbitMQ Service Status: Check if RabbitMQ is running with the command
    sudo systemctl status rabbitmq-server
    . If it's inactive, try starting it:
    sudo systemctl start rabbitmq-server
    .
  3. RabbitMQ Logs: Check the logs in
    /var/log/rabbitmq/rabbit@YOUR_HOSTNAME.log
    or
    /var/log/rabbitmq/rabbitmqctl.log
    for startup errors.
  4. Is RabbitMQ listening on the correct ports: Use
    sudo netstat -tulnp | grep LISTEN | grep -E '5672|15672'
    . If the ports are not displayed, RabbitMQ might not be running or is configured incorrectly.
  5. User Permissions: Ensure that the user you are using to connect has the appropriate permissions on the virtual host. Check in the Management UI or with the command
    sudo rabbitmqctl list_permissions -p / your_user
    .
  6. Caddy/Reverse Proxy: If you are using Caddy for HTTPS, ensure that Caddy is running (
    sudo systemctl status caddy
    ) and its configuration (
    /etc/caddy/Caddyfile
    ) is correct.

RabbitMQ is running slowly or consuming too many resources. How to optimize?

What to check:

  1. RAM and Disk Usage: In the Management UI, on the "Overview" tab, look at the memory and disk usage graphs. If RAM is consistently near its maximum, RabbitMQ starts flushing messages to disk, which slows down performance.
  2. Message Persistence: If you have many persistent messages, they are actively written to disk. Ensure your disk is fast enough (SSD/NVMe).
  3. Number of Queues and Messages: Too many queues or very large queues can consume a lot of resources. Consider consolidating queues or implementing a more aggressive message expiration policy (TTL).
  4. vm_memory_high_watermark
    and
    disk_free_limit
    settings:
    Adjust these parameters in
    /etc/rabbitmq/rabbitmq.conf
    according to your resources.
  5. Heartbeats: Ensure that clients are using Heartbeats. This helps RabbitMQ detect "dead" connections faster and free up resources.
  6. Erlang/RabbitMQ Version: Ensure you are using up-to-date versions, as new versions often contain performance improvements.

How to reset the password for a RabbitMQ user?

If you have forgotten the password for a RabbitMQ user, you can reset (or change) it using

rabbitmqctl
:


sudo rabbitmqctl change_password myuser new_strong_password

Replace

myuser
with the username for which you want to change the password, and
new_strong_password
with the new password.

What is the minimum VPS configuration suitable for RabbitMQ?

For small projects or development, handling up to 100-200 messages per second, a VPS with 2 vCPU, 2-4 GB RAM, and 50-80 GB SSD will be minimally suitable. However, for stable operation and a small margin of safety, especially if moderate load or persistent queues are planned, 2 vCPU, 4 GB RAM, and 80-100 GB SSD are recommended. A fast disk (SSD) is crucial for RabbitMQ performance, especially when dealing with persistent messages.

What to choose — VPS or dedicated for this task?

For most beginner and medium-sized projects, a VPS will be the optimal choice. It offers a good price-to-performance ratio, sufficient flexibility, and ease of management. A dedicated server becomes preferable when your project reaches very large scales (thousands of messages per second, multi-node clustering), requires maximum stable and predictable performance without "noisy neighbor" effects, or has strict requirements for physical isolation and security. It's always best to start with a VPS and scale up to a dedicated server as needs grow.

Messages accumulate in queues but are not processed.

What to check:

  1. Consumers: Ensure that your consumer applications are running and connected to RabbitMQ. Check their logs for errors.
  2. Consumer Throughput: Consumers might not be processing messages as quickly as they arrive. Consider increasing the number of consumer instances or optimizing their code.
  3. Prefetch count: The
    prefetch_count
    setting on the consumer side can affect processing speed. If it's too low, consumers might be idle. If it's too high, one consumer might take too many messages, while others wait.
  4. Message Errors: Some messages might cause errors in consumers and be constantly returned to the queue (requeue), creating a "poison pill" scenario. Check consumer logs for recurring errors.

How to monitor RabbitMQ?

The Management UI provides excellent graphs and statistics for monitoring. For more advanced monitoring and alerts, you can use:

  • Prometheus + Grafana: The RabbitMQ Management Plugin exports metrics that Prometheus can collect, and Grafana can visualize.
  • Logs: Regularly review RabbitMQ logs for warnings and errors.
  • System Metrics: Monitoring CPU, RAM, disk I/O on the VPS.

Conclusions and Next Steps

Diagram: Conclusions and Next Steps
Diagram: Conclusions and Next Steps

We have successfully installed and configured RabbitMQ on a VPS, preparing a reliable foundation for asynchronous task processing and building distributed systems. You have learned how to ensure basic server security, install necessary components, configure the message broker, and plan for backup and maintenance. Now you have a powerful tool that will allow your applications to operate more efficiently, scalably, and resiliently.

Further steps to optimize and expand your infrastructure may include:

  1. Integration with Applications: Start connecting your services to RabbitMQ using client libraries for your programming language (e.g., Pika for Python, amqplib for Node.js, RabbitMQ .NET client for C#).
  2. Monitoring and Alerts: Set up a comprehensive monitoring system (e.g., Prometheus + Grafana) to track key RabbitMQ metrics and receive notifications about potential issues.
  3. Clustering: To enhance fault tolerance and throughput, consider creating a RabbitMQ cluster by deploying multiple nodes on different VPS or dedicated servers.
  4. Performance Optimization: As the load grows, delve into fine-tuning RabbitMQ, exploring queue policies, lazy queues, federation, and Shovel for more complex scenarios.

¿Te fue útil esta guía?

Tus comentarios nos ayudan a mejorar nuestras guías.

Compartir esta publicación:

Envía esta guía a alguien a quien pueda resultarle útil.

Telegram VKVK WhatsApp Facebook LinkedIn XX

Installation and configuration of RabbitMQ on VPS for asynchronous task processing
support_agent
Valebyte Support
Usually replies within minutes
Hi there!
Send us a message and we'll reply as soon as possible.