Debian 12 bookworm
Sponsored Link

RabbitMQ : Configure Cluster2023/07/20

 
Configure RabbitMQ Cluster.
It shows to configure 2 RabbitMQ Servers on this example.
[1]
[2] On all Nodes, Configure unique node-name.
root@node01:~#
vi /etc/rabbitmq/rabbitmq-env.conf
# line 5 : uncomment and set unique node-name

NODENAME=
rabbit01
root@node01:~#
systemctl restart rabbitmq-server
root@node01:~#
rabbitmqctl eval "node()."

rabbit01@node01
[3] Configure clustering on a Node.
# put the same cookie on all nodes

root@node02:~#
ssh node01.srv.world 'cat /var/lib/rabbitmq/.erlang.cookie' > /var/lib/rabbitmq/.erlang.cookie

root@node02:~#
systemctl restart rabbitmq-server
# stop application and reset

root@node02:~#
rabbitmqctl stop_app

Stopping rabbit application on node rabbit02@node02 ...
root@node02:~#
rabbitmqctl reset

Resetting node rabbit02@node02 ...
# join in cluster
# specify only hostname, not with FQDN

root@node02:~#
rabbitmqctl join_cluster rabbit01@node01

# start application

root@node02:~#
rabbitmqctl start_app

# show status

root@node02:~#
rabbitmqctl cluster_status

Cluster status of node rabbit02@node02 ...
Basics

Cluster name: rabbit02@node02.srv.world

Disk Nodes

rabbit01@node01
rabbit02@node02

Running Nodes

rabbit01@node01
rabbit02@node02

Versions

rabbit01@node01: RabbitMQ 3.10.8 on Erlang 25.2.3
rabbit02@node02: RabbitMQ 3.10.8 on Erlang 25.2.3

Maintenance status

Node: rabbit01@node01, status: not under maintenance
Node: rabbit02@node02, status: not under maintenance

Alarms

(none)

Network Partitions

(none)

Listeners

Node: rabbit01@node01, interface: [::], port: 15672, protocol: http, purpose: HTTP API
Node: rabbit01@node01, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Node: rabbit01@node01, interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0
Node: rabbit02@node02, interface: [::], port: 15672, protocol: http, purpose: HTTP API
Node: rabbit02@node02, interface: [::], port: 25672, protocol: clustering, purpose: inter-node and CLI tool communication
Node: rabbit02@node02, interface: [::], port: 5672, protocol: amqp, purpose: AMQP 0-9-1 and AMQP 1.0

Feature flags

Flag: classic_mirrored_queue_version, state: enabled
Flag: drop_unroutable_metric, state: enabled
Flag: empty_basic_get_metric, state: enabled
Flag: implicit_default_bindings, state: enabled
Flag: maintenance_mode_status, state: enabled
Flag: quorum_queue, state: enabled
Flag: stream_queue, state: enabled
Flag: user_limits, state: enabled
Flag: virtual_host_metadata, state: enabled
[4] Configure Queue sync setting.
If [rabbitmqadmin] command is not found, install it, refer to here.
This example shows to configure that Queue is synced on all Nodes.
There are some modes to sync among Nodes, refer details to official site below.
  ⇒ https://www.rabbitmq.com/ha.html
# add Queue for sync

root@node01:~#
rabbitmqadmin declare queue name=shared_queue

queue declared
# set sync policy
# rabbitmqctl set_policy [policy name(any name you like)] [Queue] [Mode]

root@node01:~#
rabbitmqctl set_policy ha-policy "shared_queue" '{"ha-mode":"all"}'

Setting policy "ha-policy" for pattern "shared_queue" to "{"ha-mode":"all"}" with priority "0" for vhost "/" ...
# show status

root@node01:~#
rabbitmqadmin list queues name node policy slave_nodes state synchronised_slave_nodes

+--------------+-----------------+-----------+-----------------+---------+--------------------------+
|     name     |      node       |  policy   |   slave_nodes   |  state  | synchronised_slave_nodes |
+--------------+-----------------+-----------+-----------------+---------+--------------------------+
| shared_queue | rabbit01@node01 | ha-policy | rabbit02@node02 | running | rabbit02@node02          |
+--------------+-----------------+-----------+-----------------+---------+--------------------------+
[5] To Enable management Plugin on all Nodes, it's possible to see each Node's status like follows.
Matched Content