RabbitMQ: Create a Cluster On a Single Machine

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 –

  1. To run commands as root enter –

    sudo -i

  2. 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.
  3. 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
  4. 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' ...

    Start up information was displayed but my prompt did not return, so I just pressed Ctrl-C to get the prompt back.

  5. The hare instance should be running –

    rabbitmqctl -n hare status

    Output –

    Status of node 'hare@mymachine' ...
         [{rabbitmq_management,"RabbitMQ Management Console","3.0.1"},
  6. Stop hare RabbitMQ application but leave Erlang node running –

    rabbitmqctl -n hare stop_app

    Output –

    Stopping node 'hare@mymachine' ...
  7. Reset hare

    rabbitmqctl -n hare reset

    Output –

    Resetting node 'hare@mymachine' ...
  8. Join hare to cluster –

    rabbitmqctl -n hare join_cluster rabbit@`hostname -s`

    Output –

    Clustering node 'hare@mymachine' with 'rabbit@mymachine' ...
  9. Restart the hare RabbitMQ application

    rabbitmqctl -n hare start_app

    Output –

    Starting node 'hare@mymachine' ...
    ** Found 0 name clashes in code paths
  10. Check the status of the cluster –

    rabbitmqctl cluster_status

    Output –

    Cluster status of node 'rabbit@mymachine' ...

That’s it! Now you can play with your shiny new cluster. Take a look at the RabbitMQ Clustering Guide for further information.


One thought on “RabbitMQ: Create a Cluster On a Single Machine

  1. Pingback: RabbitMQ cluster on a single machine | alex.theedom

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s