Amazon EC2

This guide assumes familiarity with the general clustering guide.


Using RabbitMQ on EC2 is quite similar running it on other platforms. However, the are certain minor aspects to EC2 that need to be accounted for. They primarily have to do with hostnames and their resolution.

This guide uses traditional RabbitMQ clustering. It is worth noting that alternative solutions are available and can be more suitable for automation:

RabbitMQ Chef cookbook and RabbitMQ Puppet module can help with automating cluster provisioning.


Pivotal currently does not provide AMI images with RabbitMQ pre-provisioned. RabbitMQ works well on up-to-date Ubuntu and CentOS AMIs.

Choose instance type

First, you need to choose what instance type to run. RabbitMQ will work on every instance type, but there are a few considerations worth bearing in mind:

  • RabbitMQ will work on 32-bit operating system, but for production usage we recommend 64-bit instances.
  • RabbitMQ by default will take advantage of all the processors in the system. However a single strong CPU configuration might behave slightly better than a collection of weak processors.
  • In some cases RabbitMQ requires substantial amounts of memory. Make sure that your host does have enough RAM and always have at least a few gigabytes of swap space enabled.

Choose operating system

Although RabbitMQ is tested with most major Linux distributions, Ubuntu support for Amazon EC2 seems to be strongest. You can get the list of Ubuntu AMI images here:
You may find more information in Ubuntu EC2 Starters Guide.

Install RabbitMQ

Ubuntu ships with RabbitMQ but it's often not the latest version. If you want the recent version, you may use our Debian repository. Here is a shell script that automates RabbitMQ installation on Ubuntu:

cat <<EOF > /etc/apt/sources.list.d/rabbitmq.list
deb testing main

curl -o /tmp/rabbitmq-signing-key-public.asc
apt-key add /tmp/rabbitmq-signing-key-public.asc
rm /tmp/rabbitmq-signing-key-public.asc

apt-get -qy update
apt-get -qy install rabbitmq-server

Instead of running it manually, you can tell the instance to run this script automatically during the first start. You can do it using the user-data-file command line option for the ec2-run-instances command. For example:

$ ec2-run-instances ami-XXX \
    --key ${EC2_KEYPAIR} \
    --instance-type m1.large \
    --region eu-west-1 \
Put your chosen AMI id in the place of ami-XXX. The string ${EC2_KEYPAIR} should be replaced with the public ssh keypair name that is going to be used to log in to the instance. You can find more information about ec2-run-instances command in EC2 Getting Started Guide.

Persistent data on EBS device

RabbitMQ writes data to the following directories on Ubuntu:

  • /var/lib/rabbitmq/ to store persistent data like the messages or queues
  • /var/log/rabbitmq/ to store logs

If you want to use EBS block device to store RabbitMQ data, just link these directories to your EBS device. Stop RabbitMQ before making any changes to the data directory:

$ /etc/init.d/rabbitmq-server stop

Default user access

The broker creates a user guest with password guest. Unconfigured clients will in general use these credentials. By default, these credentials can only be used when connecting to the broker as localhost so you will need to take action before connecting fromn any other machine.

See the documentation on access control for information on how to create more users, delete the guest user, or allow remote access to the guest user.

Hostname Changes

RabbitMQ nodes use hostnames to communicate with each other. Therefore, all node names must be able to resolve names of all cluster peers. This is also true for tools such as rabbitmqctl.

In addition to that, by default RabbitMQ names the database directory using the current hostname of the system. If the hostname changes, a new empty database is created. To avoid data loss it's crucial to set up a fixed and resolvable hostname. Whenever the hostname changes you should restart RabbitMQ:

$ /etc/init.d/rabbitmq-server restart

A similar effect can be achieved by using rabbit@localhost as the broker nodename. The impact of this solution is that clustering will not work, because the chosen hostname will not resolve to a routable address from remote hosts. The rabbitmqctl command will similarly fail when invoked from a remote host. A more sophisticated solution that does not suffer from this weakness is to use DNS, e.g. Amazon Route 53 if running on EC2. If you want to use the full hostname for your nodename (RabbitMQ defaults to the short name), and that full hostname is resolveable using DNS, you may want to investigate setting the environment variable RABBITMQ_USE_LONGNAME=true.

See the hostname resolution guide for more information.

Firewalled nodes

The case for firewalled clustered nodes exists when nodes are in a data center or on a reliable network, but separated by firewalls. Again, clustering is not recommended over a WAN or when network links between nodes are unreliable.

In the most common configuration you will need to open ports 4369 and 25672 for clustering to work.

Erlang makes use of a Port Mapper Daemon (epmd) for resolution of node names in a cluster. The default epmd port is 4369, but this can be changed using the ERL_EPMD_PORT environment variable. All nodes must use the same port. For further details see the Erlang epmd manpage.

Once a distributed Erlang node address has been resolved via epmd, other nodes will attempt to communicate directly with that address using the Erlang distributed node protocol. The default port for this traffic in RabbitMQ is 20000 higher than RABBITMQ_NODE_PORT (i.e. 25672 by default). This can be explicitly configured using the RABBITMQ_DIST_PORT variable - see the configuration guide.

Erlang Versions Across the Cluster

All nodes in a cluster must run the same version of Erlang.

If you have any comments please let us know.