How to install RabbitMQ on Linux 9

Share on Social Media

In this Linux tutorial, you will learn how to install RabbitMQ on Linux 9 that includes Red Hat based distributions.

What is RabbitMQ:

RabbitMQ is an open-source message broker software that enables applications to communicate and transfer data between each other. It implements the Advanced Message Queuing Protocol (AMQP), which is a widely adopted standard for reliable messaging between different software systems.

At its core, RabbitMQ acts as a mediator or intermediary between two or more applications. It receives messages from a sender, known as a producer, and delivers those messages to a receiver, known as a consumer. The messages are typically organized into queues within RabbitMQ, which provides a way to store and route them.

RabbitMQ supports various messaging patterns, including point-to-point, publish/subscribe, and request/reply. It provides features like message durability, acknowledgments, and routing flexibility, making it a robust and reliable messaging system.

Developers can use RabbitMQ to build distributed and scalable applications that need to handle high volumes of messages and ensure reliable delivery. It is widely used in various industries and scenarios, such as enterprise systems, microservices architectures, event-driven systems, and cloud computing environments.

RabbitMQ is written in Erlang and is known for its stability, performance, and fault-tolerant design. It offers client libraries for multiple programming languages, making it accessible for developers using different technology stacks.

Video to install RabbitMQ on Linux:

YouTube player

Environment Specification:

We are using a minimal Rocky Linux 9 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 4 GB
  • Storage – 40 GB
  • Operating System – Rocky Linux release 9.2 (Blue Onyx)
  • Hostname – rabbitmq-01.centlinux.com
  • IP Address – 192.168.18.87/24

Prepare your Linux Server:

Login to your Linux server as root user by using a ssh client.

Set a Fully Qualified Domain Name (FQDN) of your Linux machine and set up Local DNS Resolution by executing following commands.

# hostnamectl set-hostname rabbitmq-01.centlinux-com.preview-domain.com
# echo "192.168.18.87 rabbitmq-01 rabbitmq-01.centlinux-com.preview-domain.com" >> /etc/hosts

Update software packages in your Linux OS by executing dnf command.

# dnf update -y

If above command installs a new version of Linux Kernel, then you should reboot your Linux OS with new Kernel before installing RabbitMQ software.

# reboot

After reboot, note down the Linux OS and Linux Kernel versions.

# cat /etc/rocky-release
Rocky Linux release 9.2 (Blue Onyx)

# uname -r
5.14.0-284.11.1.el9_2.x86_64

Install Additional Yum Repositories:

To install RabbitMQ on Linux, you may need some software packages from Extra Packages for Enterprise Linux (EPEL) yum repository. Therefore, install EPEL yum repository as follows.

# dnf install -y epel-release

You can download RabbitMQ software from their offical website. Or you can install RabbitMQ official yum repository then install Message Broker software by using Linux Package Manager.

We suggest that you should install RabbitMQ on Linux from their official yum repository.

To install RabbitMQ official yum repository, execute following command at Linux terminal.

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

Similarly, you should also install RabbitMQ ErLang repository.

# curl -1sLf 'https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/setup.rpm.sh' | sudo -E bash

Build yum cache for newly installed yum repositories.

# dnf makecache
Extra Packages for Enterprise Linux 9 - x86_64  1.7 kB/s | 6.7 kB     00:03
rabbitmq-rabbitmq-erlang                        376  B/s | 659  B     00:01
rabbitmq-rabbitmq-erlang-noarch                 248  B/s | 659  B     00:02
rabbitmq-rabbitmq-erlang-source                 308  B/s | 659  B     00:02
rabbitmq_rabbitmq-server                        794  B/s | 1.8 kB     00:02
rabbitmq_rabbitmq-server-source                 392  B/s | 951  B     00:02
Rocky Linux 9 - BaseOS                          1.8 kB/s | 4.1 kB     00:02
Rocky Linux 9 - AppStream                       2.6 kB/s | 4.5 kB     00:01
Rocky Linux 9 - Extras                          1.9 kB/s | 2.9 kB     00:01
Metadata cache created.

Install RabbitMQ on Linux:

All required yum repositories have been added. Now you can install RabbitMQ on Linux by using dnf command.

# dnf install -y rabbitmq-server

Enable and start RabbitMQ service.

# systemctl enable --now rabbitmq-server.service
Created symlink /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service → /usr/lib/systemd/system/rabbitmq-server.service.

Install RabbitMQ Management Plugins:

To enable web based Management Console for your Message Broker Software, you need to install some plugins on your RabbitMQ Server.

# rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@rabbitmq-01:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@rabbitmq-01...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

started 3 plugins.

Configure Linux Firewall:

Identify the service ports, that are being used by RabbitMQ software, execute following commands on Linux terminal.

# ss -tulpn | grep beam
tcp   LISTEN 0      1024                             0.0.0.0:15672      0.0.0.0:*    users:(("beam.smp",pid=2172,fd=37))
tcp   LISTEN 0      128                              0.0.0.0:25672      0.0.0.0:*    users:(("beam.smp",pid=2172,fd=18))
tcp   LISTEN 0      128                                    *:5672             *:*    users:(("beam.smp",pid=2172,fd=35))

# ss -tulpn | grep epmd
tcp   LISTEN 0      4096                             0.0.0.0:4369       0.0.0.0:*    users:(("epmd",pid=2208,fd=3))
tcp   LISTEN 0      4096                                [::]:4369          [::]:*    users:(("epmd",pid=2208,fd=4))

Allow above service ports in Linux firewall.

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

# firewall-cmd --reload
success

Install rabbitmqadmin on Linux:

The management plugin ships with a command line tool rabbitmqadmin which can perform some of the same actions as the Web-based UI, and which may be more convenient for automation tasks.

rabbitmqadmin can be downloaded from any RabbitMQ node that has the management plugin enabled. Navigate to http://{hostname}:15672/cli/rabbitmqadmin to download it. The tool requires a supported version of Python to be installed.

You can use following curl command to download rabbitmqadmin.

# curl http://localhost:15672/cli/rabbitmqadmin -o /usr/local/bin/rabbitmqadmin
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 42533  100 42533    0     0  2307k      0 --:--:-- --:--:-- --:--:-- 2307k

Grant execute permissions to rabbitmqadmin command.

# chmod +x /usr/local/bin/rabbitmqadmin

Create a RabbitMQ Admin User:

RabbitMQ software shipped with a default user guest with password guest. This guest user has administrative privileges but it can only be login to message-broker server from localhost.

Therefore, you need to create another admin user to access RabbitMQ Management web interface remotely.

First, check the already available users on Message Broker server.

# rabbitmqctl list_users
Listing users ...
user    tags
guest   [administrator]

Execute following command at Linux terminal to create a new RabbitMQ user.

# rabbitmqctl add_user admin P@ssw0rd
Adding user "admin" ...
Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more.

Set [administrator] tag for admin user to make it a RabbitMQ Administrator.

# rabbitmqctl set_user_tags admin administrator
Setting tags for user "admin" to [administrator] ...

Check the list of available users again.

# rabbitmqctl list_users
Listing users ...
user    tags
admin   [administrator]
guest   [administrator]

Create a RabbitMQ Virtual Host:

RabbitMQ is multi-tenant system: connections, exchanges, queues, bindings, user permissions, policies and some other things belong to virtual hosts, logical groups of entities. If you are familiar with virtual hosts in Apache or server blocks in Nginx, the idea is similar. There is, however, one important difference: virtual hosts in Apache are defined in the configuration file; that’s not the case with RabbitMQ: virtual hosts are created and deleted using rabbitmqctl or HTTP API instead.

To create a RabbitMQ virtual host, you can use following Linux command.

# rabbitmqctl add_vhost /my_vhost
Adding vhost "/my_vhost" ...

Check the available virtual host on your Message Broker server.

# rabbitmqctl list_vhosts
Listing vhosts ...
name
/my_vhost
/

Grant permissions on my_vhost to admin user.

# rabbitmqctl set_permissions -p /my_vhost admin ".*" ".*" ".*"
Setting permissions for user "admin" in vhost "/my_vhost" ...

Check the permissions of admin user.

# rabbitmqctl list_user_permissions admin
Listing permissions for user "admin" ...
vhost   configure       write   read
/my_vhost       .*      .*      .*

Check the permission on my_vhost.

# rabbitmqctl list_permissions -p /my_vhost
Listing permissions for vhost "/my_vhost" ...
user    configure       write   read
admin   .*      .*      .*

Create a Message Queue:

You can create a message queue by using rabbitmqadmin command.

# rabbitmqadmin -V /my_vhost -u admin -p P@ssw0rd declare queue name=my_queue01
queue declared

Send a message to your message queue by using following command.

# rabbitmqadmin -V /my_vhost -u admin -p P@ssw0rd publish routing_key=my_queue01 payload='Hello World!' exchange=amq.default
Message published

Receive the message in your message queue.

# rabbitmqadmin -V /my_vhost -u admin -p P@ssw0rd get queue=my_queue01
+-------------+----------+---------------+--------------+---------------+------------------+------------+-------------+
| routing_key | exchange | message_count |   payload    | payload_bytes | payload_encoding | properties | redelivered |
+-------------+----------+---------------+--------------+---------------+------------------+------------+-------------+
| my_queue01  |          | 0             | Hello World! | 12            | string           |            | False       |
+-------------+----------+---------------+--------------+---------------+------------------+------------+-------------+

Access RabbitMQ Management Web Interface:

Open URL http://rabbitmq-01.centlinux.com:15672 in a web browser.

rabbitmq-management-login

Login as admin user.

rabbitmq-management-overview

After successful login, you may reach at the dashboard of RabbitMQ Management web interface. You can perform complete administration of your message-broker server from here.

Click on “Queues”.

rabbitmq-management-queues

Conclusion – Install RabbitMQ on Linux:

In this Linux tutorial, you have learned how to install RabbitMQ on Linux 9 or other Red Hat based Linux distributions. For more information about using RabbitMQ software, we suggest that you should attend online training RabbitMQ: The Complete Guide with Software Architecture Applicationsudemy-link