Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install RabbitMQ on CentOS 7

Install RabbitMQ on CentOS 7

sudo yum -y install epel-release
sudo yum -y update

Install Erlang

Download repository

wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm

Add repository

sudo rpm -Uvh erlang-solutions-1.0-1.noarch.rpm

Install erlang and dependencies

sudo yum -y install erlang socat logrotate

Install RabbitMQ

Download RabbitMQ package

wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.9/rabbitmq-server-3.7.9-1.el7.noarch.rpm

Add signing key

sudo rpm --import https://www.rabbitmq.com/rabbitmq-signing-key-public.asc

Install rabbitmq-server

sudo rpm -Uvh rabbitmq-server-3.7.9-1.el7.noarch.rpm

Start RabbitMQ

sudo systemctl start rabbitmq-server

Automatically start RabbitMQ at boot time

sudo systemctl enable rabbitmq-server

Firewall

If you have a firewall installed and running

sudo firewall-cmd --zone=public --permanent --add-port=4369/tcp
sudo firewall-cmd --zone=public --permanent --add-port=25672/tcp
sudo firewall-cmd --zone=public --permanent --add-port=5671-5672/tcp
sudo firewall-cmd --zone=public --permanent --add-port=15672/tcp
sudo firewall-cmd --zone=public --permanent --add-port=61613-61614/tcp
sudo firewall-cmd --zone=public --permanent --add-port=1883/tcp
sudo firewall-cmd --zone=public --permanent --add-port=8883/tcp

Reload the firewall

sudo firewall-cmd --reload

SELinux

If you have SELinux enabled

sudo setsebool -P nis_enabled 1

RabbitMQ Web Management Console

Enable RabbitMQ web management console

sudo rabbitmq-plugins enable rabbitmq_management

Modify file permissions

sudo chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/

Create an admin user (Change password to a strong password)

sudo rabbitmqctl add_user admin password

Make admin user and administrator

sudo rabbitmqctl set_user_tags admin administrator

Set admin user permissions

sudo rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

To access the RabbitMQ admin

http://Your_Server_IP:15672

RabbitMQ SSL

Create rabbitmq conf file at /etc/rabbitmq/rabbitmq.conf

management.listener.port = 15672
management.listener.ssl  = true

management.listener.ssl_opts.cacertfile = /path/to/your/ca_certificate.pem
management.listener.ssl_opts.certfile   = /path/to/your/certificate.pem
management.listener.ssl_opts.keyfile    = /path/to/your/key.pem

RabbitMQ Cluster

Setup multiple RabbitMQ servers, copy script below to /usr/local/sbin/rabbitmq-cluster.sh and run the script

#!/bin/bash
set -e
function getHostname()
{
local HOST=''
while test -z "$HOST"
do
read -p "$1 : " HOST
done
echo $HOST;
}
SETUP_MASTER_SCRIPT='
rabbitmqctl stop_app;
rabbitmqctl reset;
rabbitmqctl start_app;
';
# Step 1 : Setup the Master. Get the erlang cookie
echo "Setup RabbitMQ Master";
echo "=====================";
OUT=/tmp/master.out
MASTER_HOSTNAME=$(getHostname "Enter the master server's hostname");
echo "[$MASTER_HOSTNAME] Setting up master";
ssh -t $MASTER_HOSTNAME "bash -c '$SETUP_MASTER_SCRIPT cat /var/lib/rabbitmq/.erlang.cookie;'" | tee $OUT;
COOKIE=$(cat $OUT | tail -n1)
rm $OUT;
echo "Master's Erlang Cookie : '$COOKIE'"
MASTER_IP=$(getHostname "Enter the master server's IP as seen from the slaves (Use a local IP if available)");
# Step 2 : Setup the slaves
SETUP_SLAVE_SCRIPT="
sed -i \"s/^$/$MASTER_IP $MASTER_HOSTNAME\n/\" /etc/hosts
bash -c \"echo -n '$COOKIE' > /var/lib/rabbitmq/.erlang.cookie\";
rabbitmqctl stop_app;
rabbitmqctl reset;
rabbitmqctl join_cluster --ram rabbit@$MASTER_HOSTNAME;
rabbitmqctl start_app;
rabbitmqctl cluster_status;
";
echo "Setup RabbitMQ Slaves";
echo "=====================";
SERVER=$(getHostname "Enter slave's hostname or 'q' to quit");
while test "$SERVER" != "q"
do
echo "Setting up slave";
echo "ssh '$SERVER'";
ssh -t $SERVER "bash -c '$SETUP_SLAVE_SCRIPT'";
SERVER=$(getHostname "Enter another slave's hostname or 'q' to quit");
done
# Step 3 : Create admin user
echo "[$MASTER_HOSTNAME] Setting up admin user";
ssh -t $MASTER_HOSTNAME "bash -c 'rabbitmqctl add_user admin password'";
ssh -t $MASTER_HOSTNAME "bash -c 'rabbitmqctl set_user_tags admin administrator'";
ssh -t $MASTER_HOSTNAME "bash -c 'rabbitmqctl set_permissions -p / admin \".*\" \".*\" \".*\"'";
# Step 3 : Delete guest user
echo "[$MASTER_HOSTNAME] Removing user";
ssh -t $MASTER_HOSTNAME "bash -c 'rabbitmqctl delete_user guest'";
# Step 5 : Create sync policy
echo "[$MASTER_HOSTNAME] Synchronizing cluster";
ssh -t $MASTER_HOSTNAME $"bash -c 'rabbitmqctl set_policy -p / ha-all \"\" '\''{\"ha-mode\":\"all\",\"ha-sync-mode\":\"automatic\"}'\'''";
echo "Done";
@hollicksfeir

This comment has been minimized.

Copy link

hollicksfeir commented May 28, 2019

Thanks this page is really helpful

@Valantir007

This comment has been minimized.

Copy link

Valantir007 commented Jun 4, 2019

Omg... Yesterday I installed Erlang and RabbitMq and it was't working. Today I ran all of this commands from your post and it's working. Very thank you for helpful post.

@fernandoaleman

This comment has been minimized.

Copy link
Owner Author

fernandoaleman commented Jun 4, 2019

@hollicksfeir and @Valantir007 you're welcome. I'm glad this helped. 👍

@kapeshifk

This comment has been minimized.

Copy link

kapeshifk commented Jun 9, 2019

Thank you for sharing. This will make my life easier.

@fernandoaleman

This comment has been minimized.

Copy link
Owner Author

fernandoaleman commented Jun 9, 2019

Thank you for sharing. This will make my life easier.

@kapeshifk You're welcome. 👍

@gochemjackets

This comment has been minimized.

Copy link

gochemjackets commented Jul 3, 2019

Thank you so much. I've installed Rabbitmq more than 100 times, and it is finally working now with ur post. Very helpful!!!

@TranHuyTiep

This comment has been minimized.

Copy link

TranHuyTiep commented Jul 13, 2019

how to i can fix "Job for rabbitmq-server.service failed because the control process exited with error code. See "systemctl status rabbitmq-server.service" and "journalctl -xe" for details."

@jmptrader

This comment has been minimized.

Copy link

jmptrader commented Aug 14, 2019

Muchas Gracias!! Fernando, excelente.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.