Clustered RabbitMQ Centos 7

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Introduction

RabbitMQ is an open-source enterprise messaging scheme initially based on the Advanced Messaging Queuing Protocol (AMQP) standard but now supports numerous other protocols. Lightweight and easy to deploy on-premises or on the cloud, RabbitMQ is the most popular open-source messaging. To ensure optimal performance of RabbitMQ, it is critical to RabbitMQ monitoring.However, it is challenging for organizations to find Clustered RabbitMQ monitoring tools that provide complete visibility into their infrastructure. Also, check RabbitMQ on Centos8 and documentation rabbitmq site

What can RabbitMQ can do?

Reliability

So RabbitMQ offers a variety of features to let you trade off performance with reliability, including persistence, delivery support, publisher confirms, and high availability.

Flexible Routing

Messages are routed through exchanges before arriving at queues.

Also RabbitMQ features several built-in exchange types for the typical routing logic.

Also For more complex routing you can bind exchanges together or even write your own exchange type as a plugin.

Clustering RabbitMQ

Several RabbitMQ servers on a local network can be clustered together, forming a single logical broker.

Federation

For servers that need to be more loosely and unreliably connected than clustering allows, RabbitMQ offers a federation model.

Highly Available Queues

So Queues can be mirrored across several machines in a cluster, ensuring that even in the event of hardware failure your messages are safe.

Multi-protocol

RabbitMQ supports messaging over a variety of messaging protocols.

Many Clients Grouped

Also There are RabbitMQ clients for almost any language you can think of.

Management UI

RabbitMQ ships with an easy-to-use management UI that allows you to monitor and control every aspect of your message broker.

Prerequisites

  • The essential requirement for RabbitMQ Cluster setup is to have a minimum of 2 nodes with CentOS 7 that we will use this article.Then, set up their FQDN and basic network settings
  • At least two freshly used and updated CentOS 7 instances in the same subnet with private networking enabled
  • RabbitMQ installed with the management console enabled on each server. 
  • A non-admin user with sudo rights

Installing RabbitMQ

So Install Epel repository and Clustered RabbitMQ package

[root@master ~]# yum install epel-release -y
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.icidc.com
 * extras: mirrors.icidc.com
 * updates: mirrors.icidc.com
base                                                                                                                                                                                       | 3.6 kB  00:00:00
extras                                                                                                                                                                                     | 2.9 kB  00:00:00
updates                                                                                                                                                                                    | 2.9 kB  00:00:00
(1/4): extras/7/x86_64/primary_db                                                                                                                                                          | 242 kB  00:00:00
(2/4): base/7/x86_64/group_gz                                                                                                                                                              | 153 kB  00:00:00
(3/4): base/7/x86_64/primary_db                                                                                                                                                            | 6.1 MB  00:00:02
(4/4): updates/7/x86_64/primary_db                                                                                                                                                         | 9.6 MB  00:00:05
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================
 Package                                                Arch                                             Version                                           Repository                                        Size
==================================================================================================================================================================================================================
Installing:
 epel-release                                           noarch                                           7-11                                              extras                                            15 k

Transaction Summary
==================================================================================================================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
warning: /var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for epel-release-7-11.noarch.rpm is not installed
epel-release-7-11.noarch.rpm                                                                                                                                                               |  15 kB  00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <[email protected]>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-8.2003.0.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                                                                                                                       1/1
  Verifying  : epel-release-7-11.noarch                                                                                                                                                                       1/1

Installed:
  epel-release.noarch 0:7-11

Complete!
[root@master ~]# 

Also Install Clustered RabbitMQ and required packages

[root@master ~]# yum -y install rabbitmq-server erlang
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                                                                                       | 8.4 kB  00:00:00
 * base: mirrors.icidc.com
 * epel: download.nus.edu.sg
 * extras: mirrors.icidc.com
 * updates: mirrors.icidc.com
epel                                                                                                                                                                                       | 4.7 kB  00:00:00
(1/3): epel/x86_64/group_gz                                                                                                                                                                |  96 kB  00:00:00
(2/3): epel/x86_64/updateinfo                                                                                                                                                              | 1.0 MB  00:00:00
(3/3): epel/x86_64/primary_db                                                                                                                                                              | 6.9 MB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package rabbitmq-server.noarch 0:3.3.5-34.el7 will be installed
--> Processing Dependency: erlang-erts >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-kernel >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-mnesia >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch
--> Processing Dependency: erlang-os_mon >= R12B-3 for package: rabbitmq-server-3.3.5-34.el7.noarch


......................

Dependencies Resolved

==================================================================================================================================================================================================================
 Package                                                    Arch                                         Version                                                 Repository                                  Size
==================================================================================================================================================================================================================
Installing:
 rabbitmq-server                                            noarch                                       3.3.5-34.el7                                            epel                                       4.0 M
Installing for dependencies:
 erlang-asn1                                                x86_64                                       R16B-03.18.el7                                          epel                                       758 k
 erlang-compiler                                            x86_64                                       R16B-03.18.el7                                          epel                                       1.0 M
 erlang-crypto                                              x86_64                                       R16B-03.18.el7                                          epel                                        86 k
 erlang-erts                                                x86_64                                       R16B-03.18.el7                                          epel                                       2.5 M
 erlang-hipe                                                x86_64                                       R16B-03.18.el7                                          epel                                       2.4 M
                             293 k
 erlang-sd_notify                                           x86_64                                       0.1-1.el7                                               epel                                       9.1 k
 erlang-snmp                                                x86_64                                       R16B-03.18.el7                                          epel                                       1.5 M
 erlang-ssl                                                 x86_64                                       R16B-03.18.el7                                          epel                                       588 k
 erlang-stdlib                                              x86_64                                       R16B-03.18.el7                                          epel                                       2.2 M
 erlang-syntax_tools                                        x86_64                                       R16B-03.18.el7                                          epel                                       336 k
 erlang-tools                                               x86_64                                       R16B-03.18.el7                                          epel                                       566 k
 erlang-xmerl                                               x86_64                                       R16B-03.18.el7                                          epel                                       998 k
 lksctp-tools                                               x86_64                                       1.0.17-2.el7                                            base                                        88 k

Transaction Summary
==================================================================================================================================================================================================================
Install  1 Package (+21 Dependent packages)

Total download size: 21 M
Installed size: 36 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/epel/packages/erlang-asn1-R16B-03.18.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY                                    ]  0.0 B/s | 624 kB  --:--:-- ETA
Public key for erlang-asn1-R16B-03.18.el7.x86_64.rpm is not installed
(1/22): erlang-asn1-R16B-03.18.el7.x86_64.rpm                                                                                                                                              | 758 kB  00:00:00
..........                                                                                                                                                           4/22
  Verifying  : erlang-compiler-R16B-03.18.el7.x86_64                                                                                                                                                         5/22
  Verifying  : erlang-mnesia-R16B-03.18.el7.x86_64                                                                                                                                                           6/22
  Verifying  : erlang-crypto-R16B-03.18.el7.x86_64                                                                                                                                                           7/22
  Verifying  : erlang-hipe-R16B-03.18.el7.x86_64                                                                                                                                                             8/22
  Verifying  : erlang-inets-R16B-03.18.el7.x86_64                                                                                                                                                            
  Verifying  : erlang-os_mon-R16B-03.18.el7.x86_64                                                                                                                                                          17/22
  Verifying  : erlang-otp_mibs-R16B-03.18.el7.x86_64                                                                                                                                                        18/22
  Verifying  : erlang-tools-R16B-03.18.el7.x86_64                                                                                                                                                           19/22
  Verifying  : erlang-snmp-R16B-03.18.el7.x86_64                                                                                                                                                            20/22
  Verifying  : erlang-syntax_tools-R16B-03.18.el7.x86_64                                                                                                                                                    21/22
  Verifying  : erlang-asn1-R16B-03.18.el7.x86_64                                                                                                                                                            22/22

Installed:
  rabbitmq-server.noarch 0:3.3.5-34.el7

Dependency Installed:
  erlang-asn1.x86_64 0:R16B-03.18.el7             erlang-compiler.x86_64 0:R16B-03.18.el7               erlang-crypto.x86_64 0:R16B-03.18.el7               erlang-erts.x86_64 0:R16B-03.18.el7
  erlang-hipe.x86_64 0:R16B-03.18.el7             erlang-inets.x86_64 0:R16B-03.18.el7                  erlang-kernel.x86_64 0:R16B-03.18.el7               erlang-mnesia.x86_64 0:R16B-03.18.el7
  erlang-os_mon.x86_64 0:R16B-03.18.el7           erlang-otp_mibs.x86_64 0:R16B-03.18.el7               erlang-public_key.x86_64 0:R16B-03.18.el7           erlang-runtime_tools.x86_64 0:R16B-03.18.el7
  erlang-sasl.x86_64 0:R16B-03.18.el7             erlang-sd_notify.x86_64 0:0.1-1.el7                   erlang-snmp.x86_64 0:R16B-03.18.el7                 erlang-ssl.x86_64 0:R16B-03.18.el7
  erlang-stdlib.x86_64 0:R16B-03.18.el7           erlang-syntax_tools.x86_64 0:R16B-03.18.el7           erlang-tools.x86_64 0:R16B-03.18.el7                erlang-xmerl.x86_64 0:R16B-03.18.el7
  lksctp-tools.x86_64 0:1.0.17-2.el7

Complete!
[root@master ~]# 

Start and enable service

[root@master ~]# systemctl start rabbitmq-server

[root@master ~]# systemctl enable rabbitmq-server
Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service.

Adding user for RabbitMQ

Use RabbitMQ, add user first. By default, only guest user exists and he can connect the only localhost

[root@master ~]# rabbitmqctl add_user rabbit password
Creating user "rabbit" ...
...done.
[root@master ~]# rabbitmqctl list_users
Listing users ...
guest   [administrator]
rabbit  []
...done.
[root@master ~]#

Grant Admin rights to the rabbitmq user

Ggrant permissions to a user for virtualhosts

[root@master ~]# rabbitmqctl set_user_tags rabbit administrator
Setting tags for user "rabbit" to [administrator] ...
...done.
[root@master ~]# 

Add virtualhost to Clustered RabbitMQ

Use RabbitMQ, add virtualhosts

[root@master ~]# rabbitmqctl add_vhost /my_vhost
Creating vhost "/my_vhost" ...
...done.
[root@master ~]# rabbitmqctl list_vhosts
Listing vhosts ...
/
/my_vhost
...done.
[root@master ~]#

Install AMQP client library

Implements AMQP (Advanced Message Queuing Protocol) used for Clustered RabbitMQ

[root@master ~]# yum -y install python2-pika
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.rise.ph
 * epel: mirror.telkomuniversity.ac.id
 * extras: mirror.rise.ph
 * updates: mirror.rise.ph
Resolving Dependencies
--> Running transaction check
---> Package python2-pika.noarch 0:0.10.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================================================================================================
 Package                                               Arch                                            Version                                                Repository                                     Size
==================================================================================================================================================================================================================
Installing:
 python2-pika                                          noarch                                          0.10.0-10.el7                                          epel                                          170 k

Transaction Summary
==================================================================================================================================================================================================================
Install  1 Package

Total download size: 170 k
Installed size: 1.0 M
Downloading packages:
python2-pika-0.10.0-10.el7.noarch.rpm                                                                                                                                                      | 170 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python2-pika-0.10.0-10.el7.noarch                                                                                                                                                              1/1
  Verifying  : python2-pika-0.10.0-10.el7.noarch                                                                                                                                                              1/1

Installed:
  python2-pika.noarch 0:0.10.0-10.el7

Complete!
[root@master ~]#

Create python script to test connection

Sending a message on Python Clustered RabbitMQ

[root@master ~]# cat send_msg.py
#!/usr/bin/env python

import pika

credentials = pika.PlainCredentials('unixcop', 'password')
connection = pika.BlockingConnection(pika.ConnectionParameters(
                                     'localhost',
                                     5672,
                                     '/my_vhost',
                                     credentials))

channel = connection.channel()
channel.queue_declare(queue='Hello_World')

channel.basic_publish(exchange='',
                      routing_key='Hello_World',
                      body='Hello RabbitMQ World!')

print(" [x] Sent 'Hello_World'")

connection.close()
[root@master ~]#

[root@master ~]# python send_msg.py
 [x] Sent 'Hello_World'
[root@master ~]#

Create script for checking if message has been recieved

[root@master ~]# cat receive_msg.py
#!/usr/bin/env python

import signal
import pika

signal.signal(signal.SIGPIPE, signal.SIG_DFL)
signal.signal(signal.SIGINT, signal.SIG_DFL)

credentials = pika.PlainCredentials('unixcop', 'password')
connection = pika.BlockingConnection(pika.ConnectionParameters(
                                     'master.example.com',
                                     5672,
                                     '/my_vhost',
                                     credentials))

channel = connection.channel()
channel.queue_declare(queue='Hello_World')

def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)

channel.basic_consume(callback,
                      queue='Hello_World',
                      no_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
[root@master ~]#

[root@master ~]# python receive_msg.py
 [*] Waiting for messages. To exit press CTRL+C
 [x] Received 'Hello RabbitMQ World!'
 [x] Received 'Hello RabbitMQ World!'
^C

Set erlang cookie to all nodes for Clustered RabbitMQ

[root@master ~]# chmod 777 /var/lib/rabbitmq/.erlang.cookie
[root@master ~]# scp -r /var/lib/rabbitmq/.erlang.cookie root@worker1:/var/lib/rabbitmq/.erlang.cookie
[root@master ~]# scp -r /var/lib/rabbitmq/.erlang.cookie root@worker2:/var/lib/rabbitmq/.erlang.cookie
[root@master ~]# chmod 400 /var/lib/rabbitmq/.erlang.cookie
[root@master ~]# chown rabbitmq /var/lib/rabbitmq/.erlang.cookie
[root@master ~]# chgrp rabbitmq /var/lib/rabbitmq/.erlang.cookie

Join nodes to Clustered RabbitMQ

[root@worker1~]# rabbitmqctl stop_app
[root@worker1 ~]# rabbitmqctl join_cluster rabbit@master
[root@worker1 ~]# rabbitmqctl start_app
#---------------------------------------------------------------------------------#
[root@worker2 ~]# rabbitmqctl stop_app
[root@worker2 ~]# rabbitmqctl join_cluster rabbit@master
[root@worker2 ~]# rabbitmqctl start_app

Install RabbitMQ management plugin

[root@master ~]# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  mochiweb
  webmachine
  rabbitmq_web_dispatch
  amqp_client
  rabbitmq_management_agent
  rabbitmq_management
Plugin configuration has changed. Restart RabbitMQ for changes to take effect.

[root@master ~]# systemctl restart rabbitmq-server

Access to the “http://hostname or IP address):15672/” of a client, then, RabbitMQ login form is exposed, log in with an admin user.

Dashboard with cluster nodes

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook