Sometimes it’s useful to be able to play around with a simple RabbitMQ cluster on a single machine. After trying to follow the instructions in the RabbitMQ Clustering Guide and running into a couple of issues, I ended up doing the following to get a working two node cluster up and running on my laptop.
The machine used was a laptop running Ubuntu 12.04.1 LTS (32-bit), RabbitMQ 3.0.1 and Erlang R14B04. These are the steps I took using the Terminal –
- To run commands as root enter –
sudo -i
- Make sure that you don’t have a /etc/rabbitmq/rabbitmq.config file because it caused errors for me by applying the settings from the file to both nodes that I started irrespective of command line arguments. I renamed my rabbitmq.config file to rabbitmq.config.bak.
- Start the first RabbitMQ instance if it is not already running. In my case it is the default instance named ‘rabbit‘ –
invoke-rc.d rabbitmq-server start
Output –
* Starting message broker rabbitmq-server
- Start a second RabbitMQ instance called ‘hare‘ on port 5673 as a background task. I have the Management plugin installed so also set the port for that –
RABBITMQ_NODE_PORT=5673 RABBITMQ_SERVER_START_ARGS="-rabbitmq_management listener [{port,15673}]" RABBITMQ_NODENAME=hare rabbitmq-server &
Output –
Status of node 'hare@mymachine' ... [{pid,14524}, {running_applications, ...
Start up information was displayed but my prompt did not return, so I just pressed Ctrl-C to get the prompt back.
- The hare instance should be running –
rabbitmqctl -n hare status
Output –
Status of node 'hare@mymachine' ... [{pid,14524}, {running_applications, [{rabbitmq_management,"RabbitMQ Management Console","3.0.1"}, ...
- Stop hare RabbitMQ application but leave Erlang node running –
rabbitmqctl -n hare stop_app
Output –
Stopping node 'hare@mymachine' ... ...done.
- Reset hare –
rabbitmqctl -n hare reset
Output –
Resetting node 'hare@mymachine' ... ...done.
- Join hare to cluster –
rabbitmqctl -n hare join_cluster rabbit@`hostname -s`
Output –
Clustering node 'hare@mymachine' with 'rabbit@mymachine' ... ...done.
- Restart the hare RabbitMQ application
rabbitmqctl -n hare start_app
Output –
Starting node 'hare@mymachine' ... ** Found 0 name clashes in code paths ...
- Check the status of the cluster –
rabbitmqctl cluster_status
Output –
Cluster status of node 'rabbit@mymachine' ... [{nodes,[{disc,['hare@mymachine','rabbit@mymachine']}]}, {running_nodes,['hare@mymachine','rabbit@mymachine']}, {partitions,[]}] ...done.
That’s it! Now you can play with your shiny new cluster. Take a look at the RabbitMQ Clustering Guide for further information.