Skip to content

Instantly share code, notes, and snippets.

@fernandoaleman
Last active April 22, 2024 19:00
Show Gist options
  • Star 80 You must be signed in to star a gist
  • Fork 49 You must be signed in to fork a gist
  • Save fernandoaleman/fe34e83781f222dfd8533b36a52dddcc to your computer and use it in GitHub Desktop.
Save fernandoaleman/fe34e83781f222dfd8533b36a52dddcc to your computer and use it in GitHub Desktop.
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.8.35/rabbitmq-server-3.8.35-1.el8.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.8.35-1.el8.noarch.rpm

Start RabbitMQ

sudo systemctl start rabbitmq-server

Automatically start RabbitMQ at boot time

sudo systemctl enable rabbitmq-server

RabbitMQ Config (Optional)

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

listeners.ssl.default = 5671

ssl_options.cacertfile = /path/to/cacertfile.pem
ssl_options.certfile   = /path/to/certfile.pem
ssl_options.keyfile    = /path/to/keyfile.pem
ssl_options.verify     = verify_peer
ssl_options.versions.1 = tlsv1.2
ssl_options.versions.2 = tlsv1.1
ssl_options.fail_if_no_peer_cert = false

tcp_listen_options.backlog       = 128
tcp_listen_options.nodelay       = true
tcp_listen_options.exit_on_close = false
tcp_listen_options.keepalive     = false

heartbeat = 580

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 Web Management SSL (Recommended)

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

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

management.listener.ssl_opts.cacertfile = /path/to/cacertfile.pem
management.listener.ssl_opts.certfile   = /path/to/certfile.pem
management.listener.ssl_opts.keyfile    = /path/to/keyfile.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";
@Valantir007
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
Copy link
Author

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

@kapeshifk
Copy link

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

@fernandoaleman
Copy link
Author

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

@kapeshifk You're welcome. 👍

@knockknockyoo
Copy link

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

@TranHuyTiep
Copy link

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
Copy link

Muchas Gracias!! Fernando, excelente.

@chill-cod3r
Copy link

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."

☝️

@ymrcse
Copy link

ymrcse commented May 8, 2020

How can i change the default data directory to other location in centos 7 rabbitmq3.6.10

@oleksandr-roskovynskyi
Copy link

Installing the latest rabbitmq-server with help from a script from https://packagecloud.io/rabbitmq/rabbitmq-server/install

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

@abhinavraj23
Copy link

There's an error coming at installing RabbitMq, it says
error: Failed dependencies: erlang >= 21.3 is needed by rabbitmq-server-3.8.8-1.el6.noarch

Although the latest version of erlang is installed.

@DLongKMA
Copy link

DLongKMA commented Jun 19, 2021

Thank you so much
But when I run 'sudo systemctl start rabbitmq-server'
It take me a long time to run
How can I solve that ?

@pf0418
Copy link

pf0418 commented Jul 1, 2021

Thanks you so much
But when i run 'sudo systemctl start rabbitmq-server'
It take me a long time to run
How can i slove that ?
Thanks from VietNam

I have the same issue as well, it's a timed-out issue

@pf0418
Copy link

pf0418 commented Jul 1, 2021

Installing the latest rabbitmq-server with help from a script from https://packagecloud.io/rabbitmq/rabbitmq-server/install

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

I tried this and everything works! I just followed the commands here. Thanks a lot!

@gazeldx
Copy link

gazeldx commented Oct 12, 2021

I have to use $ wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.19/rabbitmq-server-3.8.19-1.el7.noarch.rpm to make it work. Otherwise, I will get a failed error.

The point seems to be that CentOS 7 should only use *.el7.noarch.rpm not .el6.

According to: https://www.vultr.com/docs/how-to-install-rabbitmq-on-centos-7

@DLongKMA
Copy link

Installing the latest rabbitmq-server with help from a script from https://packagecloud.io/rabbitmq/rabbitmq-server/install

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

I tried this and everything works! I just followed the commands here. Thanks a lot!

Thanks so much bro <3

@Navven
Copy link

Navven commented Dec 28, 2021

3.8.8 The corresponding erlang support version is 21.3-23.x If the erlang version is not in the range, it may cause some problems
https://www.rabbitmq.com/which-erlang.html

@kumaranDuden
Copy link

i facing on rabbitmq service not started because 5672 is allocated for another service rabbitmq config how to change the default port any suggestion

@krishnatummeti
Copy link

Install RabbitMQ on CentOS 7 not working help me

sudo yum -y update
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest

@dengkj
Copy link

dengkj commented Nov 7, 2022

Thanks

@mhall0011
Copy link

screen
Where can find the username and password of this mailerq management, i have tried using the loging used in accessing rabbitmq but it did not work, please, can someone advise me better? Thanks.

@mhall0011
Copy link

i understand the question i asked above may be reasonably answered from https://www.mailerq.com/documentation/management-console

please someone should guide me on what to do please

@turan1302
Copy link

Failed to start LSB: RabbitMQ is a multi-protocol messaging broker

I get an error. What is the reason

@madcatgith
Copy link

madcatgith commented Mar 22, 2023

As @Navven mentioned you need to check your erlang version and compatibility with rabbitMQ
Erlang check:
erl -eval '{ok, Version} = file:read_file(filename:join([code:root_dir(), "releases", erlang:system_info(otp_release), "OTP_VERSION"])), io:fwrite(Version), halt().' -noshell

rabbitMQ compatibility
https://www.rabbitmq.com/which-erlang.html

In my case i had erlang 24.3.4.1 installed following this guide and rabbitMQ v3.8.8 that are not compatible. So i installed 3.8.35 and all worked

wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.35/rabbitmq-server-3.8.35-1.el8.noarch.rpm sudo rpm -Uvh rabbitmq-server-3.8.35-1.el8.noarch.rpm

@fernandoaleman
Copy link
Author

Thanks @madcatgith, I have updated this gist with the newer version of RabbitMQ 👍

@PrithviMedavaram
Copy link

Thanks @fernandoaleman for the step by step explanation.

@prfthiraljain
Copy link

prfthiraljain commented Aug 7, 2023

How to Install RabbitMq on CentOS9.

@jamshid
Copy link

jamshid commented Aug 21, 2023

The link http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm broke recently, always returns a 304. Even if you use Cache-control: no-cache the rabbitmq rpm install fails with erlang >= 23.2 is needed by rabbitmq-server-3.8.35-1.el8.noarch.

These instructions based on https://github.com/rabbitmq/erlang-rpm#centos-7-and-derivatives seem to work on centos:7:

    yum -y install epel-release && \
    yum install -y https://github.com/rabbitmq/erlang-rpm/releases/download/v25.3.2.3/erlang-25.3.2.3-1.el7.x86_64.rpm && \
    yum -y install erlang socat logrotate && \
    rpm --import https://www.rabbitmq.com/rabbitmq-signing-key-public.asc && \
    yum -y install https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.35/rabbitmq-server-3.8.35-1.el8.noarch.rpm && \
    type rabbitmq-diagnostics && echo "Running rabbitmq in background to verify install..." && ( /usr/sbin/rabbitmq-server & ) && \
    retry=0 && while sleep 10 && ! rabbitmq-diagnostics -q ping ; do true ; if test $((retry++)) -gt 12 ; then echo "rabbitmq is not hopping after 2m" ; exit 1 ; fi ; done && \
    yum clean all

@stardustman
Copy link

Download RabbitMQ package

wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.35/rabbitmq-server-3.8.35-1.el8.noarch.rpm
why use el8.noarch.rpm when install rabbit on centos7?

@stardustman
Copy link

I met this error on centos7 using rabbitmq3.8.5 when start the server.

-- Unit rabbitmq-server.service has begun starting up.
12月 19 20:05:48 node01 rabbitmq-server[32380]: {"Kernel pid terminated",application_controller,"{application_start_failure,lager,{bad_return,{{lager_app,start,[normal,[]]},{'EXIT',{undef,[{erl_syntax,atom,[module],[]},{g
12月 19 20:05:48 node01 rabbitmq-server[32380]: Kernel pid terminated (application_controller) ({application_start_failure,lager,{bad_return,{{lager_app,start,[normal,[]]},{'EXIT',{undef,[{erl_syntax,atom,[module],[]},{gl
12月 19 20:05:48 node01 rabbitmq-server[32380]: Crash dump is being written to: erl_crash.dump...done
12月 19 20:05:48 node01 systemd[1]: rabbitmq-server.service: main process exited, code=exited, status=1/FAILURE
12月 19 20:05:48 node01 systemd[1]: Failed to start RabbitMQ broker.
-- Subject: Unit rabbitmq-server.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

how to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment