(Last Updated On: May 12, 2018)

This guide covers the Installation of RabbitMQ on CentOS 6 and CentOS 7, to be specific I’m running CentOS 6.9 and CentOS 7.5 on my local KVM machine using Vagrant. This Lab is based on my previous guide Using Vagrant with Libvirt on Linux. RabbitMQ is a message broker software that implements AMQP (Advanced Message Queuing Protocol).

Installation Requirements:

  1. EPEL repository
  2. Erlang repository
  3. Rabbitmq repository

I prefer using repositories to install the Rabbitmq server and Erlang as opposed to using rpm packages which tends to bring package dependency issues and having to manually update packages.

Set Hostname

You can start by configuring the hostname for your server.

Set server hostname on CentOS 6:

# cat /etc/hostname 
# cat /etc/sysconfig/network

Restart network service once you make the changes.

# /etc/init.d/network restart

Then confirm current hostname setting:

# hostname 

To temporarily set the hostname for the current shell session, use:

# hostname rabbitmq-server-01.example.com

Set server hostname on CentOS 7:

For CentOS 7 server, you can easily set server hostname using a hostnamectl command.

# hostnamectl set-hostname rabbitmq-server-01.example.com --static
# hostnamectl 
Static hostname: mysql-server-01.example.com
Icon name: computer-vm
Chassis: vm
Machine ID: 54525dfab6854668bc9b005c28ecce87
Boot ID: 989f5500267843e9bb5e5890f14f6ffb
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-862.el7.x86_64
Architecture: x86-64

Add EPEL repository:

Add epel repository to your system using yum command as below:

# yum -y install epel-release

Add Erlang repository for CentOS

# cat /etc/yum.repos.d/erlang.repo
name=CentOS $releasever - $basearch - Erlang Solutions

Add RabbitMQ Repository:

# curl -s https://packagecloud.io/install/repositories/rabbitmq/rabbitmq-server/script.rpm.sh | sudo bash

Install rabbitmq-server

# yum -y install rabbitmq-server

Start and enable rabbitmq-server to start on boot.

CentOS 7:

# systemct start rabbitmq-server  && systemctl enable rabbitmq-server

CentOS 6:

# chkconfig rabbitmq-server on
# chkconfig --list | grep rabbitmq
# service rabbitmq-server start

To use RabbitMQ, add user first. By default, only guest user exists and he can connect from localhost.

# rabbitmqctl add_user admin NUaiMe0k
Adding user "admin" ...
# rabbitmqctl set_user_tags admin administrator
# rabbitmqctl list_users 
Listing users ...
admin [administrator]
guest [administrator]

Other rabbitmqctl administration commands are:

Delete User:

rabbitmqctl delete_user user

Change User Password:

rabbitmqctl change_password user strongpassword

Add virtualhost:

rabbitmqctl add_vhost /my_vhost

List virtualhosts:

rabbitmqctl list_vhosts

Delete virtualhost:

rabbitmqctl delete_vhost /my_vhost

Grant user permissions for vhost:

rabbitmqctl set_permissions -p /my_vhost user ".*" ".*" ".*"

List vhost permissions:

rabbitmqctl list_permissions -p /my_vhost

To list user permissions:

rabbitmqctl list_user_permissions user

Delete user permissions:

rabbitmqctl clear_permissions -p /my_vhost user

Enable RabbitMQ UI

You can enable Management Plugin to use a web-based interface to administer RabbitMQ.

# rabbitmq-plugins enable rabbitmq_management
# systemctl restart rabbitmq-server
 or for CentOS 6:
# service rabbitmq-server restart

Open ports on the firewall:

# firewall-cmd --add-port={4369/tcp,25672}/tcp --permanent

With Iptables:

# iptables -A INPUT -p tcp -m tcp --dport 4369 -j ACCEPT
# iptables -A INPUT -p tcp -m tcp --dport 25672 -j ACCEPT

Access to the “http://server:15672/” from a client: You should get a login window:

Login with username and the password created earlier: