Installing & Optimizing RabbitMQ on CentOS Stream 9: From Zero to Production

CentOS tutorial - IT technology blog
CentOS tutorial - IT technology blog

The Problem: Why Does Your System Need RabbitMQ?

Imagine you are running an e-commerce platform with about 1,000 orders per minute. If the system makes customers wait for a confirmation email before showing “Order Successful,” the bounce rate will skyrocket due to lag. This is where the system hits a bottleneck caused by synchronous processing.

RabbitMQ solves this problem by acting as a mediator. Instead of waiting for the email to be sent, the system simply drops a request into a queue and responds to the customer immediately. On CentOS Stream 9, installation is straightforward. However, if you choose the wrong Erlang version, you will face constant dependency errors.

Quick Start: Install RabbitMQ in 5 Minutes

If you’re in a hurry, use the script from Cloudsmith. This is the fastest way to get the official repository without manual configuration.

# 1. Update the system
sudo dnf update -y

# 2. Add repo setup scripts (Erlang and RabbitMQ)
curl -s https://setup.cloudsmith.io/rabbitmq/rabbitmq-erlang/script.rpm.sh | sudo bash
curl -s https://setup.cloudsmith.io/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash

# 3. Install RabbitMQ Server
sudo dnf install rabbitmq-server -y

# 4. Enable and start the service
sudo systemctl enable --now rabbitmq-server

Run the command sudo rabbitmqctl status to verify. If you see the version and node name information, you’re on the right track.

Why Install Erlang Separately?

Many people use the default dnf install rabbitmq-server command provided by the OS. This mistake often leaves you with outdated and incompatible Erlang versions. RabbitMQ is built on the Erlang/OTP platform. Each RabbitMQ version requires a specific range of Erlang versions to ensure stability and performance.

Step 1: Enable the Management UI

Typing commands can be tedious; RabbitMQ provides a highly intuitive Web Dashboard. Here, you can monitor real-time charts of incoming and outgoing messages.

# Enable the management plugin
sudo rabbitmq-plugins enable rabbitmq_management

# Restart to apply changes
sudo systemctl restart rabbitmq-server

Now, you can access it via port 15672. Note: The default guest user only allows logins from localhost for security reasons.

Step 2: Set Up Administrative Privileges

The first thing I always do after installation is delete the default user and create a new admin account with a strong password.

# Create a new admin user
sudo rabbitmqctl add_user tech_admin StrongPassword123!

# Assign administrator tags
sudo rabbitmqctl set_user_tags tech_admin administrator

# Grant full permissions on the default vhost
sudo rabbitmqctl set_permissions -p / tech_admin ".*" ".*" ".*"

Advanced: Securing Traffic with SSL/TLS

Sending messages over the amqp:// protocol (plaintext) is like sending a postcard that anyone can read. In production environments, sensitive data should be encrypted via SSL/TLS (port 5671).

Open the /etc/rabbitmq/rabbitmq.conf file and add the following configuration:

listeners.ssl.default = 5671

ssl_options.cacertfile = /etc/rabbitmq/certs/ca_cert.pem
ssl_options.certfile   = /etc/rabbitmq/certs/server_cert.pem
ssl_options.keyfile    = /etc/rabbitmq/certs/server_key.pem
ssl_options.verify     = verify_peer
ssl_options.fail_if_no_peer_cert = false

Don’t forget to grant RabbitMQ permission to access the certificate directory using the command chown -R rabbitmq:rabbitmq /etc/rabbitmq/certs/.

Opening Firewall Ports on CentOS Stream 9

CentOS 9 manages ports strictly via firewalld. If you don’t open the ports, your application will encounter a “Connection Refused” error.

# Open ports for AMQP and Management UI
sudo firewall-cmd --permanent --add-port={5672,5671,15672}/tcp

# Apply changes
sudo firewall-cmd --reload

Real-world Operational Experience

After years of troubleshooting Message Broker issues, here are three key points to keep in mind:

  • RAM Management: RabbitMQ will block connections by default if RAM consumption exceeds 40% of the server’s total capacity. Adjust the vm_memory_high_watermark parameter if your server has a specific configuration.
  • Disk Threshold: If the disk has less than 50MB of free space, RabbitMQ will immediately stop accepting messages. I usually raise this threshold to 2GB to avoid sudden system “clinical death.”
  • Divide Virtual Hosts (vhosts): Think of vhosts as separate databases. Never mix Dev and Production environment data on the same vhost.

If you encounter strange errors, don’t guess. Check the logs immediately at /var/log/rabbitmq/. Most startup failures on CentOS are caused by SELinux blocking file permissions or misconfigurations in the .conf file. Good luck with your deployment!

Share: