RabbitMQ Cluster Installation and Configuration Guide
This guide explains how to install RabbitMQ, set up a three-node Erlang-based cluster on CentOS, configure hostnames, Erlang cookies, designate disk and RAM nodes, manage services, enable mirrored queues, and verify cluster status using command‑line tools.
RabbitMQ Overview
RabbitMQ is an open‑source AMQP implementation written in Erlang. It supports many client libraries (Python, Ruby, .NET, Java, etc.) and is used for storing and forwarding messages in distributed systems, offering ease of use, scalability and high availability.
AMQP (Advanced Message Queuing Protocol) is an open standard application‑layer protocol for message‑oriented middleware, enabling decoupled communication between components.
Key AMQP features include messaging, queues, routing (point‑to‑point and publish/subscribe), reliability and security.
Cluster Overview
RabbitMQ clusters are built using Erlang’s distributed capabilities; each node is a peer providing service to clients. Nodes replicate queue structures via HA (mirrored) queues. In this guide a three‑node cluster of disk nodes is deployed, where any node can serve clients.
Environment
VMware version: 12.0.0
CentOS version: 7.3.1611
RabbitMQ version: 3.6
VM IPs: 192.168.252.101, 192.168.252.102, 192.168.252.103
Installation
Single‑machine installation
Install Erlang and RabbitMQ Server on all three hosts.
Cluster Configuration
Modify hostname
Temporarily set hostname on each node:
hostname <new hostname>Example commands:
192.168.252.101 $ hostname node1
192.168.252.102 $ hostname node2
192.168.252.103 $ hostname node3Edit /etc/hosts
Add the following lines on each machine:
192.168.252.101 node1
192.168.252.102 node2
192.168.252.103 node3Set Erlang cookie
Copy the .erlang.cookie file from node1 to node2 and node3, adjust permissions to 400 after copying, and set correct ownership.
chmod 777 /var/lib/rabbitmq/.erlang.cookie # temporary
scp /var/lib/rabbitmq/.erlang.cookie node2:/var/lib/rabbitmq/
scp /var/lib/rabbitmq/.erlang.cookie node3:/var/lib/rabbitmq/
chmod 400 /var/lib/rabbitmq/.erlang.cookie
chown rabbitmq /var/lib/rabbitmq/.erlang.cookie
chgrp rabbitmq /var/lib/rabbitmq/.erlang.cookieStop RabbitMQ service
service rabbitmq-server stopJoin nodes to the cluster
node2 $ rabbitmqctl stop_app
node2 $ rabbitmqctl join_cluster rabbit@node1
node2 $ rabbitmqctl start_app
node3 $ rabbitmqctl stop_app
node3 $ rabbitmqctl join_cluster rabbit@node1
node3 $ rabbitmqctl start_appConfigure RAM or disk nodes
By default nodes are disk nodes. To make a node a RAM node:
node2 $ rabbitmqctl change_cluster_node_type ramTo revert to a disk node:
node2 $ rabbitmqctl change_cluster_node_type discCheck cluster status
rabbitmqctl cluster_statusThe output lists disc nodes, running nodes, partitions and alarms.
Mirrored queue policy
Enable a policy that mirrors all queues matching a pattern (e.g., names starting with “message”):
rabbitmqctl set_policy -p / ha-allqueue "^message" '{"ha-mode":"all"}'Adjust the pattern to match the desired queues.
Cluster restart
Force‑boot the first node, then start the RabbitMQ service on the remaining nodes:
rabbitmqctl force_boot
service rabbitmq-server start # on other nodesVerify the cluster status on each node after restart.
Contact
Author: Peng Lei
Source: http://www.ymq.io/2017/08/17/rabbit-install-cluster
Email: [email protected]
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.