This guide will cover the steps required to Install RabbitMQ on CentOS 7 / CentOS 6 server. My 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).
For Ubuntu, check: How to install Latest RabbitMQ Server on Ubuntu
Installation Requirements:
- EPEL repository
- Erlang repository
- 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.
Step 1: Set System Hostname
You can start by configuring the hostname for your server.
Set server hostname on CentOS 6:
$ sudo vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=mq-01.example.com
Restart network service once you make the changes.
sudo /etc/init.d/network restart
Then confirm current hostname setting:
$ hostname
mq-01.example.com
To temporarily set the hostname for the current shell session, use:
sudo hostname mq-01.example.com
Set server hostname on CentOS 7:
For CentOS 7 server, you can easily set server hostname using a hostnamectl command.
sudo hostnamectl set-hostname mq-01.example.com --static
Step 2: Add EPEL repository
Add epel repository to your system using yum command as below:
sudo yum -y install epel-release wget
You can check the repository has been added and working using the following command:
sudo yum repolist
Step 3: Install Erlang
Add Erlang official YUM repository:
wget https://packages.erlang-solutions.com/erlang-solutions-2.0-1.noarch.rpm
sudo rpm -Uvh erlang-solutions-2.0-1.noarch.rpm
Then install Erlang RPM package:
sudo yum install erlang
Accept installation prompt and import GPG key:
...
Transaction Summary
======================================================================================================================================================================================================
Install 1 Package (+91 Dependent packages)
Total download size: 62 M
Installed size: 163 M
Is this ok [y/d/N]: y
....
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 16 MB/s | 62 MB 00:00:03
Retrieving key from file:///etc/pki/rpm-gpg//erlang_solutions.asc
Importing GPG key 0xA14F4FCA:
Userid : "Erlang Solutions Ltd. <[email protected]>"
Fingerprint: 4349 75bd 900c cbe4 f7ee 1b1e d208 507c a14f 4fca
Package : erlang-solutions-2.0-1.noarch (installed)
From : /etc/pki/rpm-gpg//erlang_solutions.asc
Is this ok [y/N]: y
Confirm Erlang installation by checking the version and CLI tool access
$ erl
Erlang/OTP 24 [erts-12.0.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1]
Eshell V12.0.3 (abort with ^G)
1>
BREAK: (a)bort (A)bort with dump (c)ontinue (p)roc info (i)nfo
(l)oaded (v)ersion (k)ill (D)b-tables (d)istribution
q
Step 4: Install RabbitMQ Server
Add RabbitMQ Repository:
Run the commands below to add RabbitMQ YUM repository to yourCentOS 7 / CentOS 6:
cat << EOF | sudo tee /etc/yum.repos.d/rabbitmq.repo
[rabbitmq_rabbitmq-server]
name=rabbitmq_rabbitmq-server
baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/\$releasever/\$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOF
Update repositories cache
sudo yum clean all
sudo yum makecache
List available repositories as configured in the system:
$ sudo yum repolist
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.mirror.constant.com
* epel: d2lzkl7pfhq30w.cloudfront.net
* extras: mirror.math.princeton.edu
* updates: mirrors.advancedhosters.com
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10072
droplet-agent/x86_64 DigitalOcean Droplet Agent 5
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13665
erlang-solutions/7/x86_64 Centos 7 - x86_64 - Erlang Solutions 5704
extras/7/x86_64 CentOS-7 - Extras 500
rabbitmq_rabbitmq-server/7/x86_64 rabbitmq_rabbitmq-server 78
updates/7/x86_64 CentOS-7 - Updates 2747
repolist: 32771
Install rabbitmq-server package.
sudo yum -y install rabbitmq-server
Start and enable rabbitmq-server to start on boot.
CentOS 7:
sudo systemctl enable --now rabbitmq-server
Check service status:
$ systemctl status rabbitmq-server
● rabbitmq-server.service - RabbitMQ broker
Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2021-09-13 09:19:14 UTC; 48s ago
Main PID: 9636 (beam.smp)
CGroup: /system.slice/rabbitmq-server.service
├─9636 /usr/lib64/erlang/erts-12.0.3/bin/beam.smp -W w -MBas ageffcbf -MHas ageffcbf -MBlmbcs 512 -MHlmbcs 512 -MMmcs 30 -P 1048576 -t 5000000 -stbt db -zdbbl 128000 -sbwt none -sbwtdc...
├─9651 erl_child_setup 32768
├─9676 /usr/lib64/erlang/erts-12.0.3/bin/epmd -daemon
├─9699 inet_gethost 4
└─9700 inet_gethost 4
Sep 13 09:19:06 centos rabbitmq-server[9636]: Doc guides: https://rabbitmq.com/documentation.html
Sep 13 09:19:06 centos rabbitmq-server[9636]: Support: https://rabbitmq.com/contact.html
Sep 13 09:19:06 centos rabbitmq-server[9636]: Tutorials: https://rabbitmq.com/getstarted.html
Sep 13 09:19:06 centos rabbitmq-server[9636]: Monitoring: https://rabbitmq.com/monitoring.html
Sep 13 09:19:06 centos rabbitmq-server[9636]: Logs: /var/log/rabbitmq/[email protected]
Sep 13 09:19:06 centos rabbitmq-server[9636]: /var/log/rabbitmq/rabbit@centos_upgrade.log
Sep 13 09:19:06 centos rabbitmq-server[9636]: <stdout>
Sep 13 09:19:06 centos rabbitmq-server[9636]: Config file(s): (none)
Sep 13 09:19:14 centos rabbitmq-server[9636]: Starting broker... completed with 0 plugins.
Sep 13 09:19:14 centos systemd[1]: Started RabbitMQ broker.
CentOS 6:
Use the commands below to start the service on CentOS 6:
sudo chkconfig rabbitmq-server on
sudo chkconfig --list | grep rabbitmq
sudo 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
Step 5: Enable RabbitMQ UI
You can enable the Management Plugin to use a web-based interface to administer RabbitMQ.
### For CentOS 7 ###
sudo rabbitmq-plugins enable rabbitmq_management
sudo systemctl restart rabbitmq-server
### For CentOS 6 ###
sudo service rabbitmq-server restart
Configure Firewall
Open ports on the firewall:
sudo firewall-cmd --add-port={4369/tcp,25672}/tcp --permanent
With Iptables:
sudo iptables -A INPUT -p tcp -m tcp --dport 4369 -j ACCEPT
sudo iptables -A INPUT -p tcp -m tcp --dport 25672 -j ACCEPT
Access RabbitMQ Admin web console
Access to the “http://server:15672/” from a client: You should get a login window:
Login with username and the password created earlier:
The next article to read is: