0
0
RabbitMQdevops~7 mins

RabbitMQ cluster formation - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you run multiple RabbitMQ servers, you can connect them to work together as a cluster. This helps share the load and keep messages safe if one server stops working.
When you want to handle more messages than a single RabbitMQ server can manage.
When you need your messaging system to keep working even if one server crashes.
When you want to spread message queues across several servers for better performance.
When you want to add or remove RabbitMQ servers without stopping the whole system.
When you want to manage RabbitMQ servers as a single group instead of individually.
Config File - rabbitmq.conf
rabbitmq.conf
cluster_formation.peer_discovery_backend = classic_config
cluster_formation.classic_config.nodes.1 = rabbit@rabbit1
cluster_formation.classic_config.nodes.2 = rabbit@rabbit2
cluster_formation.classic_config.nodes.3 = rabbit@rabbit3

# Enable the management plugin for monitoring
management.load_definitions = /etc/rabbitmq/definitions.json

# Set node name for each server (example for rabbit1)
# This line should be set in each node's environment or advanced.config
# node.name = rabbit@rabbit1

This configuration file tells RabbitMQ how to find other nodes to form a cluster using the classic config method. It lists the nodes by their names so they can connect.

The management plugin is enabled for monitoring the cluster status.

Each node must have its own name set in its environment or advanced config to identify itself in the cluster.

Commands
Stop the RabbitMQ application on the node to prepare it for clustering commands.
Terminal
rabbitmqctl stop_app
Expected OutputExpected
Stopping rabbit application ...
Reset the node to clear any previous cluster data and prepare it to join a new cluster.
Terminal
rabbitmqctl reset
Expected OutputExpected
Resetting node ...
Join this node to the cluster where rabbit@rabbit1 is the main node already running the cluster.
Terminal
rabbitmqctl join_cluster rabbit@rabbit1
Expected OutputExpected
Clustering node with rabbit@rabbit1 ...
Start the RabbitMQ application again so the node can run as part of the cluster.
Terminal
rabbitmqctl start_app
Expected OutputExpected
Starting rabbit application ...
Check the current status of the cluster to verify all nodes are connected.
Terminal
rabbitmqctl cluster_status
Expected OutputExpected
Cluster status of node rabbit@rabbit2 ... [{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2]}]}]
Key Concept

If you remember nothing else from this pattern, remember: you must stop the RabbitMQ app, reset the node, join the cluster, then start the app again to form a cluster.

Common Mistakes
Trying to join a cluster without stopping the RabbitMQ application first.
The node will reject the join request because it is still running and has old data.
Always run 'rabbitmqctl stop_app' before 'rabbitmqctl join_cluster'.
Not resetting the node before joining the cluster.
Old cluster data can cause conflicts and prevent the node from joining properly.
Run 'rabbitmqctl reset' after stopping the app and before joining the cluster.
Using incorrect node names or forgetting to set the node name in the environment.
Nodes won't recognize each other and fail to form a cluster.
Ensure each node has a unique name like 'rabbit@rabbit1' set properly before clustering.
Summary
Stop the RabbitMQ app on the node before making cluster changes.
Reset the node to clear old cluster data.
Join the node to the cluster using the main node's name.
Start the RabbitMQ app again to run the node in the cluster.
Check cluster status to confirm all nodes are connected.