You have one RabbitMQ broker, or none yet, and you need message queues that keep working when a server goes down. A single broker cannot give you that, because its queues live on one machine. The answer is a cluster of three nodes with quorum queues, a queue type that keeps a copy of every message on several nodes. The steps below install RabbitMQ on AlmaLinux 9, check one node on its own, then grow it into a three-node cluster with a load balancer in front.
What you’ll accomplish
- Three RabbitMQ nodes (
rabbit-01,rabbit-02,rabbit-03) running as one cluster. - Quorum queues as the default type for new queues, so one node can fail without losing confirmed messages.
- An administrator account that replaces the default
guestuser. - HAProxy in front of the messaging port, and the management UI served over HTTPS by nginx.
Prerequisites
- Three AlmaLinux 9 servers on a private network, with
sudoaccess. The examples use10.10.0.11,10.10.0.12and10.10.0.13. - A fourth host for HAProxy (
10.10.0.10here). - A DNS name for the management UI, such as
mq.example.com, pointing at the public address ofrabbit-01. - A current RabbitMQ release. As of November 2026, the 4.3 and 4.4 series receive community support, and both need Erlang 27 or newer. The release information page has the current list.
The commands were written for RabbitMQ 4.3 and later. On Ubuntu, only the package step differs: follow installing RabbitMQ on Ubuntu, then come back to step 4.
How it works
A cluster shares two kinds of data. The first is metadata: users, virtual hosts, exchanges, bindings, queue definitions and policies. RabbitMQ stores it in Khepri, its built-in metadata store, and copies it to every node. Khepri replaced the older Mnesia store and is the only one supported from RabbitMQ 4.3.
The second kind is the messages themselves. A classic queue keeps its messages on one node. A quorum queue keeps a copy on three nodes by default and uses Raft, a consensus protocol in which a write counts only once a majority of copies have it. With three nodes, the majority is two, so one node can fail and the queue stays available. Classic mirrored queues, the older way to replicate, were removed in RabbitMQ 4.0.
Khepri uses Raft too. A cluster therefore needs a majority of its nodes online to change metadata or to restart fully.
Nodes recognise each other by a shared secret called the Erlang cookie, a small text file. They address each other by node name, such as rabbit@rabbit-01, so every node must resolve the hostnames of the others.
Step-by-step
-
Set hostnames and name resolution on all three nodes. Run the first line with the right name on each node, then add the same three entries everywhere:
sudo hostnamectl set-hostname rabbit-01 echo "10.10.0.11 rabbit-01" | sudo tee -a /etc/hosts echo "10.10.0.12 rabbit-02" | sudo tee -a /etc/hosts echo "10.10.0.13 rabbit-03" | sudo tee -a /etc/hostsFrom
rabbit-01,ping -c 1 rabbit-02must get a reply. If the name does not resolve, fix/etc/hostsor DNS before going further. -
Open the cluster ports between the nodes. Nodes talk to each other on 4369 (epmd, the Erlang port mapper) and 25672 (node-to-node traffic). Clients and the load balancer use 5672. On each node:
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.10.0.0/24" port port="4369" protocol="tcp" accept' sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.10.0.0/24" port port="25672" protocol="tcp" accept' sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.10.0.0/24" port port="5672" protocol="tcp" accept' sudo firewall-cmd --reloadEach command prints
success. Do not open 4369 or 25672 to the internet. -
Install Erlang and RabbitMQ on all three nodes. The distribution’s repositories do not offer an Erlang recent enough for current RabbitMQ, so use the RabbitMQ team’s repositories. Import the signing keys:
sudo rpm --import 'https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc' sudo rpm --import 'https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key' sudo rpm --import 'https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key'Create
/etc/yum.repos.d/rabbitmq.repowith this content. It is the file from the official RPM install guide for the RHEL 9 family, and it serves x86-64 packages only:[modern-erlang] name=modern-erlang-el9 baseurl=https://yum1.rabbitmq.com/erlang/el/9/$basearch https://yum2.rabbitmq.com/erlang/el/9/$basearch repo_gpgcheck=1 enabled=1 gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key gpgcheck=1 sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 pkg_gpgcheck=1 autorefresh=1 type=rpm-md [modern-erlang-noarch] name=modern-erlang-el9-noarch baseurl=https://yum1.rabbitmq.com/erlang/el/9/noarch https://yum2.rabbitmq.com/erlang/el/9/noarch repo_gpgcheck=1 enabled=1 gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc gpgcheck=1 sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 pkg_gpgcheck=1 autorefresh=1 type=rpm-md [rabbitmq-el9] name=rabbitmq-el9 baseurl=https://yum2.rabbitmq.com/rabbitmq/el/9/$basearch https://yum1.rabbitmq.com/rabbitmq/el/9/$basearch repo_gpgcheck=1 enabled=1 gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc gpgcheck=1 sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 pkg_gpgcheck=1 autorefresh=1 type=rpm-md [rabbitmq-el9-noarch] name=rabbitmq-el9-noarch baseurl=https://yum2.rabbitmq.com/rabbitmq/el/9/noarch https://yum1.rabbitmq.com/rabbitmq/el/9/noarch repo_gpgcheck=1 enabled=1 gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc gpgcheck=1 sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 pkg_gpgcheck=1 autorefresh=1 type=rpm-mdThen install the packages:
sudo dnf install -y logrotate sudo dnf install -y erlang rabbitmq-serverThe RPM does not start the service, which is what you want here. Do not start it yet.
-
Write the same configuration on all three nodes. Create
/etc/rabbitmq/rabbitmq.conf:cluster_formation.peer_discovery_backend = classic_config cluster_formation.classic_config.nodes.1 = rabbit@rabbit-01 cluster_formation.classic_config.nodes.2 = rabbit@rabbit-02 cluster_formation.classic_config.nodes.3 = rabbit@rabbit-03 default_queue_type = quorum queue_leader_locator = balanced management.tcp.ip = 127.0.0.1 management.tcp.port = 15672The first four lines are peer discovery: a brand-new node reads the list and joins the first node it can reach.
default_queue_typemakes a queue declared without a type a quorum queue.queue_leader_locator = balancedspreads queue leaders across nodes. The last two lines keep the management UI on the loopback address, so only nginx on the same host can reach it.Enable the management plugin so it loads at first start:
sudo rabbitmq-plugins enable --offline rabbitmq_management -
Start the first node and check it on its own. On
rabbit-01:sudo systemctl enable --now rabbitmq-server sudo rabbitmq-diagnostics check_running sudo rabbitmq-diagnostics server_version sudo rabbitmq-diagnostics erlang_version sudo rabbitmqctl cluster_statuscheck_runningmust succeed, andcluster_statuslists one node underRunning Nodes. No peer was reachable, so the node started as a standalone broker. That is expected.Create an administrator and remove the default account. The
guestuser can only connect from localhost, so it is no use to remote clients.add_userprompts for the password:sudo rabbitmqctl add_user admin sudo rabbitmqctl set_user_tags admin administrator sudo rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*" sudo rabbitmqctl delete_user guestYou now have a working single-node broker. The next two steps turn it into a cluster.
-
Copy the Erlang cookie to the other two nodes. RabbitMQ created the cookie on
rabbit-01at first start. Copy/var/lib/rabbitmq/.erlang.cookieto a temporary file onrabbit-02andrabbit-03over SSH, then install it there with the right owner and mode:sudo install -o rabbitmq -g rabbitmq -m 0400 /tmp/erlang.cookie /var/lib/rabbitmq/.erlang.cookie sudo shred -u /tmp/erlang.cookieThe cookie is a password for the whole cluster. If you use a configuration management tool, store it there as a secret.
-
Start the second and third nodes, one at a time. On
rabbit-02, then onrabbit-03:sudo systemctl enable --now rabbitmq-server sudo rabbitmqctl cluster_statusExample output (excerpt), once all three have joined:
Running Nodes rabbit@rabbit-01 rabbit@rabbit-02 rabbit@rabbit-03If a node lists only itself, it was started before the configuration or the cookie was in place. The Debian and Ubuntu packages do this, because they start the service at install time. Put the cookie in place with the service stopped, start it, then join by hand:
sudo rabbitmqctl join_cluster rabbit@rabbit-01Joining erases the data on the node that joins. Since RabbitMQ 4.1,
join_clusterno longer needsstop_appandresetfirst. The RabbitMQ documentation recommends peer discovery over manual joins for production clusters. -
Put HAProxy in front of port 5672. On the load balancer host, add to
/etc/haproxy/haproxy.cfg(see installing HAProxy for the package):frontend amqp_front bind *:5672 mode tcp default_backend amqp_back backend amqp_back mode tcp balance leastconn option tcp-check tcp-check connect port 5672 server rabbit-01 10.10.0.11:5672 check inter 5s server rabbit-02 10.10.0.12:5672 check inter 5s server rabbit-03 10.10.0.13:5672 check inter 5sRun
sudo haproxy -c -f /etc/haproxy/haproxy.cfg, thensudo systemctl reload haproxy. Applications now connect to10.10.0.10:5672and reach whichever node is healthy. -
Serve the management UI through nginx with a Let’s Encrypt certificate. The management plugin shows the whole cluster from any node, so one node is enough. On
rabbit-01, install nginx and Certbot (Certbot comes from the EPEL repository):sudo dnf install -y epel-release sudo dnf install -y nginx certbot python3-certbot-nginx sudo setsebool -P httpd_can_network_connect 1 sudo firewall-cmd --permanent --add-service=http --add-service=https sudo firewall-cmd --reloadThe
setseboolline lets nginx open connections to a local port under SELinux. Without it, nginx answers502 Bad Gateway. Create/etc/nginx/conf.d/rabbitmq-ui.conf:server { listen 80; server_name mq.example.com; location / { proxy_pass http://127.0.0.1:15672; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }Keep
proxy_passfree of a trailing slash. The UI puts the default virtual host/in its URLs as%2F, and a trailing slash makes nginx rewrite it. Then start nginx and request the certificate:sudo nginx -t sudo systemctl enable --now nginx sudo certbot --nginx -d mq.example.com sudo systemctl enable --now certbot-renew.timer sudo certbot renew --dry-runCertbot asks for a contact address, then adds the HTTPS listener and the certificate paths to the server block. The timer handles renewal, and the dry run confirms renewal will work. Open
https://mq.example.com/and sign in asadmin.
Validate it works
Check that every node is running and reachable on its ports. Run this on each node:
sudo rabbitmq-diagnostics check_running
sudo rabbitmq-diagnostics check_port_connectivity
Then run a failover test with PerfTest, the RabbitMQ team’s load tool. From a host with Docker that can reach the load balancer (replace PASSWORD):
docker run -it --rm pivotalrabbitmq/perf-test:latest \
--uri amqp://admin:PASSWORD@10.10.0.10:5672 \
--quorum-queue --queue qq-failover \
--producers 1 --consumers 1 --rate 100 --confirm 50
While it runs, look at the queue from any node:
sudo rabbitmq-queues quorum_status qq-failover
The table lists three members: one leader and two followers. Now stop one node with sudo systemctl stop rabbitmq-server. PerfTest should keep publishing, after a short reconnect if its connection was on that node. Run quorum_status again from a running node: the queue still has a leader, on one of the two nodes that are up. Start the stopped node again and its copy catches up from the leader.
The cluster is ready when all three nodes appear under Running Nodes, the test survives the loss of one node, and the UI loads over HTTPS.
Troubleshooting
- A node logs “Authentication failed (rejected by the remote node), please check the Erlang cookie”. The cookie differs between nodes, or its owner or mode is wrong.
sudo rabbitmq-diagnostics erlang_cookie_sourcesshows which file is in use. Repeat step 6 with the service stopped. - A node starts alone instead of joining. Peer discovery only runs on a node with an empty data directory. Check name resolution and ports 4369 and 25672, then use
join_clusteras in step 7. - Declaring a queue fails after you changed the default type. A queue’s type cannot change after it is created, and a policy cannot set it either. An application that redeclares an existing classic queue as quorum gets an error. Declare a new queue name, or keep
x-queue-typeexplicit in the application. - A new fourth node holds no queue data. RabbitMQ does not move quorum queue members to a new node by itself. Add them with
sudo rabbitmq-queues grow rabbit@rabbit-04 all.rabbitmq-queues rebalance quorumonly moves leaders between existing members. - A dead node still shows in the cluster. With that node stopped for good, run
sudo rabbitmqctl forget_cluster_node rabbit@rabbit-03on a healthy node. This also removes its quorum queue members.
Three more things to keep in mind once the cluster is in service:
- Keep the same RabbitMQ and Erlang versions on all nodes outside of a rolling upgrade. After an upgrade, run
sudo rabbitmqctl enable_feature_flag all. - The RabbitMQ documentation recommends at least 65536 open files for production. Set
LimitNOFILE=65536under[Service]in/etc/systemd/system/rabbitmq-server.service.d/limits.conf, then restart the node. Check it withsystemctl show rabbitmq-server -p LimitNOFILE. - Save the cluster’s users, queues and policies with
sudo rabbitmqctl export_definitions /root/definitions.json, and copy the file off the node. It holds no messages.
When this is the wrong approach
RabbitMQ clustering is designed for a local network with fast, stable links between nodes. When the round trip between sites is above 100 ms, or the link drops packets, the RabbitMQ documentation recommends connecting separate clusters with Federation or Shovel instead. Two nodes are no better than one for quorum queues, because losing either one loses the majority. If you run RabbitMQ 3.13 with classic mirrored queues, move to quorum queues before you upgrade. On Kubernetes, use the Kubernetes peer discovery plugin, not a node list in a file. The RabbitMQ clustering guide covers those cases.
If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.