RabbitMQ Clusters not Forming
RabbitMQ Clusters not Forming in RabbitMQ Issues.
RabbitMQ Clusters not Forming#
Case 1: Node Failure#
After manually restarting RabbitMQ, the RabbitMQ cluster has failed to form correctly, due to the following:
- If the node-1, which is receiving data, goes down, then the data is not getting synced to node-2.
- If node-2 also goes down, then older data that was received by node-1 will get processed.
This caused data loss in HEAL software.
Note: This issue is observed in HA mode.
To manage the cluster manually, please follow the below steps:
-
Check the consul key status of RabbitMQ:
consul kv get service/rabbitmq/replication/statusExpected Output:
[root@server2 ~]# consul kv get service/rabbitmq/replication/status 0 -
Update the above consul key value to 1.
consul kv put service/rabbitmq/replication/status 1Expected Output:
Success! Data written to: service/rabbitmq/replication/status -
Navigate to HEAL RABBITMQ server in the below directory:
a1home -
Initiate the RabbitMQ service using the provided script to form a new cluster.
sh startServices.sh rabbitmqNote: Collect the latest script from the concerned team.
Expected Output:
[29-08-23 16:08:39]:[Info]:- [Starting Percona] [29-08-23 16:08:39]:[Info]:- [Percona is already running] [29-08-23 16:08:39]:[Info]:- [Percona is running in ha mode] [29-08-23 16:08:39]:[Info]:- [Enabling percona master slave replication between 192.0.2.19 and 192.0.2.21] [29-08-23 16:08:39]:[Info]:- [Updating server id in my.cnf] -
Collect the RabbitMQ container ID, by executing the below command:
RHEL 7.x: Docker
docker ps | grep rabbitmqRHEL 8.x: Podman
podman ps | grep rabbitmqExpected Output:
83d98c1b9dd3 server-01:8091/rabbitmq:3.11 "/docker-entrypoint.…" 12 days ago Up 12 days rabbitmq-node1-6584d02b-a054-eb0e-0539-555698870156Note: Make a note of the existing cluster (node) from above output.
For Example: Its node1 in the output.
-
Connect to the RabbitMQ container, by executing the below command:
RHEL 7.x: Docker
docker exec -it <container ID> bashRHEL 8.x: Podman
podman exec -it <container ID> bashFor Example:
docker exec -it 83d98c1b9dd3 bashIf the connection is successful for the container, the below output is obtained:
bash-5.1#If the container ID is incorrect, the below output is obtained:
Error: No such container: 83d98c1d8dd13 -
To stop the RabbitMQ application on the current node:
rabbitmqctl stop_app -
To reset the RabbitMQ node, by removing all persistent data, configurations, and message queues, execute below command:
rabbitmqctl reset -
Join the two RabbitMQ cluster:
rabbitmqctl join_cluster --ram rabbit@rabbitmq-<node details>For Example:
rabbitmqctl join_cluster --ram rabbit@rabbitmq-node2 -
This command starts the RabbitMQ application on the current node:
rabbitmqctl start_app
Case 2: Queues pilling up on Single Node#
Clusters are not created as the queues are pilling up on single node on RabbitMQ Dashboard. Observed the rabbitmqctl cluster_status is running node only as one node, queues are pilling up on single node on RabbitMQ dashboard. When the status was checked, it shows both are running correctly.
The error was observed as below:
Starting broker...{"Kernel pid terminated",application_controller,"
{application_start_failure,rabbit,{{failed_to_cluster_with,
['rabbit@rabbitmq-node2'],\"
Mnesia could not connect to any nodes.\"},{rabbit,start,[normal,
[]]}}}"}
Solution :
- Remove the data directory of the content of mnesia and restart the service.
-
Need to cat the .erlang.cookie should be same on both nodes and also add the extra hosts on rabbitmq nomad file as below:
“rabbitmq-node1:ip”, ”rabbitmq-node2:ip” -
Later login to container ID of rabbitmq and execute the cluster forming command as below:
rabbitmqctl stop_app; rabbitmqctl reset; rabbitmqctl join_cluster --ram rabbit@rabbitmq-node2; rabbitmqctl start_app; -
Check the rabbitmqctl cluster_status that cluster formed or not, later we added below hapolicy:
curl -X PUT -k --user guest:guest -H 'content-type: application/json' --data '{"pattern": ".", "apply-to": "queues", "definition": {"max-length": 50000, "ha-mode":"all"} }' "https://192.0.2.104:15672/api/policies/%2f/ha-policy" -
Restart the Event Detector, Action Detector, signal Notification, and A1event handler. The issue will be resolved.
Steps for setting the queue Limit#
Follow the below steps to set the queue limit:
-
Delete the policies either in RabbitMQ UI or RabbitMQ server.
-
Follow the below steps in RabbitMQ UI:
-
Login to RabbitMQ UI.
Username: guest Password: ***** -
Click on the Admin Tab. And on the right side, click on Policies .
-
Select each policy and delete it one by one.
Note: The policies are deleted in order to accommodate changes, test configurations, clean up the configuration, enforce security measures, and facilitate reconfiguration. The specific reasons for policy deletion can vary depending on the evolving needs and maintenance of the RabbitMQ system.
-
-
Follow the below steps in the RabbitMQ server:
-
List all the policies in RabbitMQ.
rabbitmqctl list_policies -p vhost001Expected Output:
Listing policies for vhost "vhost001" ... vhost name pattern apply-to definition priority vhost001 policy001 queue001 queues {"max-length":100} 0 -
Execute the below curl command to delete the specific policy.
rabbitmqctl clear_policy -p vhost001 <policy name>For Example:
rabbitmqctl clear_policy -p vhost001 <policy001>Expected Output:
Successful: If the above executed command is successful, then there wont be any output but the policy will be deleted. To check the same, list the policies in the virtual host.
Unsuccessful: If the command is not executed successful, then there will be an error displayed in the output.
Error: Policy '<policy001>' not found in virtual host 'vhost001'. -
Login to RabbitMQ container:
podman ps | grep -i rabbitmqExpected Output:
068f8919vfc0 support.heal:8091/rabbitmq:3.11 2 weeks ago Up 2 weeks rabbitmq-node1-56ce3ec5-8366-9b2a-b0fa-469f078b700f -
Collect the container ID and execute the below command:
podman exec -it <container ID> bashFor Example:
podman exec -it 068f8919bfc4 bashExpected Output:
[root@support-n1 Heal]# podman exec -it 068f8819bfc4 bash bash-5.1# -
Confirm if all the policies are deleted inside the container.
rabbitmqctl list_policiesExpected Output:
Listing policies for vhost "/" ... vhost name pattern apply-to definition priority / ha-policy . queues {"max-length-bytes":10000} 0
-
-
-
Navigate to RabbitMQ server
-
Check the status of RabbitMQ
nomad status rabbitmqExpected Output:
ID = rabbitmq Name = rabbitmq Submit Date = 2023-09-08T20:06:12+05:30 Type = service Priority = 50 Datacenters = dc1 Namespace = default Status = running Periodic = false Parameterized = false Summary Task Group Queued Starting Running Failed Complete Lost Unknown rabbitmq-node1 0 0 1 0 0 0 0 Latest Deployment ID = ad409e40 Status = successful Description = Deployment completed successfully Deployed Task Group Desired Placed Healthy Unhealthy Progress Deadline rabbitmq-node1 1 1 1 0 2023-09-08T20:17:38+05:30 Allocations ID Node ID Task Group Version Desired Status Created Modified 6584b02d fd797122 rabbitmq-node1 0 run running 16d19h ago 16d19h ago -
Collect the allocation ID and execute the below command:
nomad status <allocation ID>For Example:
nomad status 6584b02dExpected Output:
ID = 6586d02b-a054-eb0e-0539-556698970156 Eval ID = 040a1d5a Name = rabbitmq.rabbitmq-node1[0] Node ID = fd797122 Node Name = server-01.example Job ID = rabbitmq Job Version = 0 Client Status = running Client Description = Tasks are running Desired Status = run Desired Description = <none> Created = 16d20h ago Modified = 16d20h ago Deployment ID = ad409e40 Deployment Health = healthy Allocation Addresses: Label Dynamic Address *amqp yes 192.0.2.105:5672 -> 5671 *https yes 192.0.2.105:15671 -> 15671 *sync yes 192.0.2.105:4369 -> 4369 *cluster yes 192.0.2.105:25672 -> 25672 Task "rabbitmq-node1" is "running" Task Resources: CPU Memory Disk Addresses 10/3000 MHz 85 MiB/1.0 GiB 300 MiB Task Events: Started At = 2023-09-08T14:36:20Z Finished At = N/A Total Restarts = 0 Last Restart = N/A Recent Events: Time Type Description 2023-09-08T20:06:20+05:30 Started Task started by client 2023-09-08T20:06:12+05:30 Driver Downloading image 2023-09-08T20:06:12+05:30 Task Setup Building Task Directory 2023-09-08T20:06:12+05:30 Received Task received by client -
Collect the IP address from the output and login to the same server.
ssh <RabbitMQ IP address>For Example:
ssh 203.0.113.9
-
-
Purge all the queues either in RabbitMQ UI or RabbitMQ server.
-
Navigate to purge all the queues in RabbitMQ UI, as below:
-
Click on Queues and then click on the Que Name.
-
Click on the Purge Messages and OK.
-
-
Purge all the queues in RabbitMQ server.
-
List all the RabbitMQ queues
rabbitmqctl list_policiesExpected Output:
Timeout: 60.0 seconds ... Listing queues for vhost / ... name messages a1-event-messages 5 raw-forensic-messages 2 collation-messages 0 nor-thresholds 0 agent-maintenance-response-messages 0 anomaly-event-signal-messages 0 collated-transaction-messages 0 violated-events 0 anomaly-event-action-messages 12 static-aggregated-kpi 24 signal-messages 4 command-messages 0In the above output, there are few queues with values.
-
Purge the each que as below:
rabbitmqctl purge_queue a1-event-messagesExpected Output:
Purging queue 'a1-event-messages' in vhost '/' ... -
Once all the queues are purged, check the status of the que’s to confirm the same:
rabbitmqctl list_queuesExpected Output:
Timeout: 60.0 seconds ... Listing queues for vhost / ... name messages a1-event-messages 0 raw-forensic-messages 0 collation-messages 0 nor-thresholds 0 agent-maintenance-response-messages 0 anomaly-event-signal-messages 0 collated-transaction-messages 0 violated-events 0 anomaly-event-action-messages 0 static-aggregated-kpi 0 signal-messages 0 command-messages 0Once all the queues are purged the status should be 0 in all the que’s.
-
-
-
Run the below curl command from the RabbitMQ heal server.
curl -X PUT -k --user guest:guest -H 'content-type: application/json' --data '{"pattern": ".", "apply-to": "queues", "definition": {"max-length": <required value>, "ha-mode":"all"} }' "https://<primaryiprabbitmq>:<rabbitmqwebport>/api/policies/%2f/ha-policy"Note: While executing the command, ensure the Max-length is set as per requirement.
For Example:
curl -X PUT -k --user guest:guest -H 'content-type: application/json' --data '{"pattern": ".", "apply-to": "queues", "definition": {"max-length": 50000, "ha-mode":"all"} }' "https://192.0.2.17:1589/api/policies/%2f/ha-policy"Expected Output:
Successful: There wont be any output if the command is successful.
Unsuccessful: The below error will be obtained when the curl command is unsuccessful.
curl: (7) Failed to connect to 192.0.2.148 port 15671: Connection refusedAfter the above command is executed, the RabbitMQ self-restarts.
-
Check if the Max-length value is updated as below:
-
Login to RabbitMQ container
RHEL 7.x: Docker
docker ps | grep -i rabbitmqRHEL 8.x: Podman
podman ps | grep -i rabbitmqExpected Output:
068f8919vfc0 support.heal:8091/rabbitmq:3.11 2 weeks ago Up 2 weeks rabbitmq-node1-56ce3ec5-8366-9b2a-b0fa-469f078b700f -
Collect the container ID and execute the below command:
RHEL 7.x: Docker
docker exec -it <container ID> bashRHEL 8.x: Podman
podman exec -it <container ID> bashFor Example:
podman exec -it 068f8919bfc4 bashExpected Output:
[root@support-n1 Heal]# podman exec -it 068f8819bfc4 bash bash-5.1# -
Check if the value is updated.
rabbitmqctl list_policiesExpected Output:
Listing policies for vhost "/" ... vhost name pattern apply-to definition priority / ha-policy . queues {"ha-mode":"all","max-length":50000} 0Hence, in the above output, the value is updated as per the requirement.
-