RabbitMQ Clustering on AWS using Ansible

In this short post, I’ll show you the steps to configure the RabbitMQ clustering on AWS using Ansible. We decided to use the RabbtiMQ instead of AWS SQS because we want better performance and also require some flexibility.

In this setup, we have created 3 EC2 servers(Ubuntu 14.04 LTS) and 1 classic ELB on AWS. Clients both providers and consumers connect to the RabbitMQ servers through ELB, so system will be functional even one or more server will be down in other words system will be operational as long as one of the server is running.

RabbitMQ Requirement(Copied from official RabbitMQ Site):

RabbitMQ nodes address each other using domain names, either short or fully-qualified (FQDNs). Therefore hostnames of all cluster members must be resolvable from all cluster nodes, as well as machines on which command line tools such as rabbitmqctl might be used.

Hostname resolution can use any of the standard OS-provided methods:
DNS records
Local host files (e.g. /etc/hosts)

Settings on AWS:

  • RabbitMQ EC2 Security Group Inbound Rules (5672 from ELB SG, 22 & 15672 from your IP or anywhere, All Traffic from Self)
  • RabbitMQ ELB Security Group Inbound Rules (5672 from your desired applications)
  • RabbitMQ ELB HealthCheck

Connect to each EC2 server and configure the hostname:

sudo vi /etc/hostname

Set the hostname:

After that modified the /etc/hosts file on each host(it will be the same):

sudo vi /etc/hosts

In my case I have given them the hostname rabbitmq-server-01,rabbitmq-server-02 and rabbitmq-server-03. So it will look like this:

After performaning all the steps, download this Repository from the GitHub:

git clone https://github.com/arbabnazar/rabbitmq-cluster.git
cd rabbitmq-cluster

Open rabbitmq-cluster/defaults/main.yml and set the values for these variables:

RABBITMQ_ERLANG_COOKIE: "VeryLongRadmonString"

RABBITMQ_USERS:
- name: "admin"
password: "VeryStrongPassword"
- name: "dev"
password: "AgainStrongPassword"

RABBITMQ_VHOSTS:
- '/'

RABBITMQ_CLUSTERED_HOSTS:
- "rabbit@rabbitmq-server-01"
- "rabbit@rabbitmq-server-02"
- "rabbit@rabbitmq-server-03"


Once you are all set with the variables, then run this command:

ansible-playbook -i rabbitmq-server-01.rbgreek.com,rabbit@rabbitmq-server-02.rbgreek.com,rabbit@rabbitmq-server-03.rbgreek.com, rabbitmq.yml -u arbabnazar

Note: Please don’t forget to change arbabnazar with your username and rabbitmq-server-01.rbgreek.com,rabbit@rabbitmq-server-02.rbgreek.com,rabbit@rabbitmq-server-03.rbgreek.com with your hostname

After successful completion of these tasks, open the management interface from anyone of the server:

http://rabbitmq-server-01.rbgeek.com:15672

Enter the Username and Password:

It will show all the details about the RabbitMQ Cluster:

 

Enjoy :-)

Hope this will help you!

Please Remember me in your prayers!

 

 

Leave a comment