RabbitMQ other operations

We close rabbit@server-1 and rabbit@server-3. Check the cluster status in each step

[root@server-1 rabbitmq]# rabbitmqctl stop_app
Stopping node 'rabbit@server-1' ...
...done.
[root@server-2 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-2' ...
[{nodes,[{disc,['rabbit@server-1']},
         {ram,['rabbit@server-3','rabbit@server-2']}]},
 {running_nodes,['rabbit@server-3','rabbit@server-2']},
 {cluster_name,<<"rabbit@server-1">>},
 {partitions,[]}]
...done.
[root@server-3 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-3' ...
[{nodes,[{disc,['rabbit@server-1']},
         {ram,['rabbit@server-3','rabbit@server-2']}]},
 {running_nodes,['rabbit@server-2','rabbit@server-3']},
 {cluster_name,<<"rabbit@server-1">>},
 {partitions,[]}]
...done.
[root@server-3 ~]#  rabbitmqctl stop_app
Stopping node 'rabbit@server-3' ...
...done.
[root@server-3 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-3' ...
[{nodes,[{disc,['rabbit@server-1']},
         {ram,['rabbit@server-2','rabbit@server-3']}]}]
...done.
[root@server-1 rabbitmq]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-1' ...
[{nodes,[{disc,['rabbit@server-1']},
         {ram,['rabbit@server-2','rabbit@server-3']}]}]
...done.
[root@server-3 ~]# rabbitmqctl start_app
Starting node 'rabbit@server-3' ...
...done.
[root@server-3 ~]# rabbitmqctl start_app
Starting node 'rabbit@server-3' ...
...done.
[root@server-3 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-3' ...
[{nodes,[{disc,['rabbit@server-1']},
         {ram,['rabbit@server-3','rabbit@server-2']}]},
 {running_nodes,['rabbit@server-2','rabbit@server-1','rabbit@server-3']},
 {cluster_name,<<"rabbit@server-1">>},
 {partitions,[]}]
...done.
...done.
[root@server-2 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-2' ...
[{nodes,[{disc,['rabbit@server-1']},
         {ram,['rabbit@server-3','rabbit@server-2']}]},
 {running_nodes,['rabbit@server-3','rabbit@server-1','rabbit@server-2']},
 {cluster_name,<<"rabbit@server-1">>},
 {partitions,[]}]
...done.
[root@server-1 rabbitmq]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-1' ...
[{nodes,[{disc,['rabbit@server-1']},
         {ram,['rabbit@server-3','rabbit@server-2']}]},
 {running_nodes,['rabbit@server-3','rabbit@server-2','rabbit@server-1']},
 {cluster_name,<<"rabbit@server-1">>},
 {partitions,[]}]
...done.

Some important warnings:
When the whole cluster is shut down, the last closed node must be the first node to be online.
If the last node to go offline cannot be recovered, you can use forget_ cluster_ The node command removes it from the cluster
If all cluster nodes stop at the same time and are not controlled (such as power failure), it may leave all nodes thinking that other nodes stop later. In this case, you can use force on one node_ The boot command makes it bootable again

Cluster remove node

[root@server-3 ~]# rabbitmqctl stop_app
Stopping node 'rabbit@server-3' ...
...done.
[root@server-3 ~]# rabbitmqctl reset
Resetting node 'rabbit@server-3' ...
...done.
[root@server-3 ~]# rabbitmqctl start_app
Starting node 'rabbit@server-3' ...
...done.

Run cluster on node_ Status command confirmation rabbit@server-3 is no longer part of the cluster and runs independently

[root@server-3 ~]#  rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-3' ...
[{nodes,[{disc,['rabbit@server-3']}]},
 {running_nodes,['rabbit@server-3']},
 {cluster_name,<<"rabbit@server-3">>},
 {partitions,[]}]
...done.
[root@server-1 rabbitmq]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-1' ...
[{nodes,[{disc,['rabbit@server-1']},{ram,['rabbit@server-2']}]},
 {running_nodes,['rabbit@server-2','rabbit@server-1']},
 {cluster_name,<<"rabbit@server-1">>},
 {partitions,[]}]
...done.
[root@server-2 ~]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-2' ...
[{nodes,[{disc,['rabbit@server-1']},{ram,['rabbit@server-2']}]},
 {running_nodes,['rabbit@server-1','rabbit@server-2']},
 {cluster_name,<<"rabbit@server-1">>},
 {partitions,[]}]
...done.

We can also delete nodes remotely, which is useful, for example, when dealing with unresponsive nodes
For example: we are at the node rabbit@server-2 upper handle rabbit@server-1 remove from cluster

[root@server-1 rabbitmq]# rabbitmqctl stop_app
Stopping node 'rabbit@server-1' ...
...done.
[root@server-2 ~]# rabbitmqctl forget_cluster_node rabbit@server-1
Removing node 'rabbit@server-1' from cluster ...
...done.

Note that server-1 still thinks it is clustered with server-2 and trying to start it will cause an error. We need to reset to restart.

[root@server-1 ~]# rabbitmqctl reset     #Must be reset
Resetting node rabbit@rabbit1 ...
 
[root@server-1 ~]# rabbitmqctl start_app
Starting node rabbit@rabbit1 ...
 completed with 0 plugins.

Server-2 is a memory node and server-1 is a disk node. An error will be reported when rabbitmqctl reset s. You need to turn server-2 into a disk node.

Connecting to a cluster from a client

The client can normally connect to any node in the cluster. If the node fails and the rest of the cluster still exists, the client should notice the closed connection and should be able to reconnect to some surviving members of the cluster. In general, it is not advisable to burn the node hostname or IP address into the client application: this introduces inflexibility, and if the cluster configuration changes or the number of nodes in the cluster changes, the client application needs to be edited, recompiled and redeployed. Instead, we recommend a more abstract approach: this may be a dynamic DNS service with a very short TTL configuration, or a common TCP load balancer, or some kind of mobile IP implemented with pacemaker or similar technology. generally speaking

Cluster with RAM nodes

RAM nodes only store their metadata in memory. Since RAM nodes do not have to write to the disc like disc nodes, they can perform better. However, please note that since the permanent queue data is always stored on disk, the performance improvement will only affect resource management (such as adding / deleting queues, switching or virtual hosts), but will not affect the publishing speed or consumption speed
RAM node is an advanced use case; You should not use them when setting up your first cluster. You should have enough optical nodes to handle your redundancy requirements, and then add additional RAM nodes for scaling when needed
Clusters containing only RAM nodes are fragile; If the cluster stops, you will not be able to start again and all data will be lost. RabbitMQ will block the creation of a cluster of RAM nodes in many cases, but it cannot completely block it

The example here shows a cluster with an optical disc and a RAM node for simplicity only; Such a cluster is a bad design choice

Create RAM node
We can declare a node as a ram node when we join the cluster for the first time. As before, we use rabbitmqctl join_cluster to complete this operation, but pass the -- ram flag

Change node type
We can change the type of node from RAM to disc and vice versa. Suppose we want to reverse the types of rabbit @ rabbit2 and rabbit @ rabbit1, converting the former from RAM node to disc node and the latter from disc node to ram node. To do this, we can use change_cluster_node_type command. The node must be stopped first

[root@server-1 rabbitmq]# rabbitmqctl stop_app
Stopping node 'rabbit@server-1' ...
...done.
[root@server-1 rabbitmq]# rabbitmqctl change_cluster_node_type ram
Turning 'rabbit@server-1' into a ram node ...
...done.
[root@server-1 rabbitmq]# rabbitmqctl start_app
Starting node 'rabbit@server-1' ...
...done.
[root@server-1 rabbitmq]# rabbitmqctl cluster_status
Cluster status of node 'rabbit@server-1' ...
[{nodes,[{disc,['rabbit@server-2']},
         {ram,['rabbit@server-3','rabbit@server-1']}]},
 {running_nodes,['rabbit@server-3','rabbit@server-1']},
 {cluster_name,<<"rabbit@server-1">>},
 {partitions,[]}]
...done.
[root@server-2 ~]# rabbitmqctl stop_app
Stopping node 'rabbit@server-2' ...
...done.
[root@server-2 ~]# rabbitmqctl change_cluster_node_type disc
Turning 'rabbit@server-2' into a disc node ...
...done.
[root@server-2 ~]# rabbitmqctl start_app

 

Tags: RabbitMQ

Posted by massive on Tue, 03 May 2022 03:03:50 +0300