Operations 12 min read

How to Build a High‑Availability RabbitMQ Cluster on CentOS with Docker

This guide walks through the full process of analyzing requirements, selecting self‑hosted servers, preparing CentOS nodes, installing Docker and Docker‑Compose, configuring RabbitMQ, and deploying a three‑node high‑availability RabbitMQ cluster with detailed commands and configuration files.

Raymond Ops
Raymond Ops
Raymond Ops
How to Build a High‑Availability RabbitMQ Cluster on CentOS with Docker

Basic Requirement Analysis

During the RabbitMQ deployment we examined existing connection data (631 connections) and queue count (80,418 queues). The highest‑tier Tencent Cloud offering could not satisfy the required queue volume and would be costly, so we decided to build a self‑hosted three‑node cluster using servers with 8 CPU cores, 16 GB RAM, 100 GB storage, and 5 Mbps bandwidth.

Self‑Hosted Service Specification

Three identical standard SA5 instances are planned, each costing 2,485.2 CNY per month. The key performance limits for each node are:

Message TPS (produce + consume): 4,200 ~ 7,000

Maximum queues: 300

Maximum connections: 4,000

These specifications meet the business growth expectations.

RabbitMQ Cluster Setup

All nodes run CentOS 7.9. The following steps are performed on each server:

Set hostname and run the init.sh initialization script.

Install required tools, disable firewalld and SELinux, increase file descriptor limits, and apply kernel optimisations.

Format and mount the data disk, creating a standard directory layout ( /data/apd, /data/logs, /data/prog, etc.).

Install Docker 18.03.1 and Docker‑Compose 1.29.2, configure a Docker registry mirror, and enable the Docker service.

RabbitMQ is deployed using the rabbitmq:3.8-management image (the Alpine variant is avoided due to known vulnerabilities). The configuration file rabbitmq.conf disables the guest user, sets the default TCP listener, and defines the classic‑config cluster formation with the three nodes:

loopback_users.guest = false
listeners.tcp.default = 5672
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config
cluster_formation.classic_config.nodes.1 = rabbit@pos_rabbitmq_1
cluster_formation.classic_config.nodes.2 = rabbit@pos_rabbitmq_2
cluster_formation.classic_config.nodes.3 = rabbit@pos_rabbitmq_3

Each node’s docker‑compose.yml maps the host IPs, mounts the data and configuration directories, and sets environment variables, including RABBITMQ_VM_MEMORY_HIGH_WATERMARK=0.7 to raise the memory usage limit to 70% of total RAM.

After pulling the images on all three hosts, the cluster is started with docker‑compose up -d. Logs confirm successful startup of all plugins.

High‑Availability Configuration

On any node, the HA policy is applied:

rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'

This mirrors queues across all three nodes, ensuring data redundancy.

Testing

The three nodes form a functional cluster, verified by creating queues and observing HA replication. Memory usage is limited to 70% of the 8 GB RAM (approximately 5.2 GB) per node, as shown in the monitoring screenshots.

Additional Resources

Images illustrate the cluster topology, HA verification, and memory statistics. The article also provides QR codes for a WeChat group, blog links, and other community resources.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Dockerhigh availabilityMessage QueueRabbitMQClusterDocker Compose
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.