Rabbitmq series (VI) complete solution of rabbitmq cluster architecture you don’t know
preface
This paper will systematically introduce the characteristics, exception handling, construction and use of rabbitmq cluster architecture.
Knowledge points
1、 Why cluster?
2、 Characteristics of cluster
3、 Cluster exception handling
4、 Cluster node type
5、 Cluster construction method
6、 Mirror queue
1、 Why cluster?
As one of the best functions of rabbitmq, built-in cluster has two functions:
2、 Characteristics of cluster
The rabbitmq cluster is composed of multiple nodes, but we found that not every node has a full copy of all queues.
Rabbitmq node incomplete copy feature
Why doesn't rabbitmq copy all queue contents and status to all nodes by default?
There are two reasons:
Therefore, other non owner nodes only know the metadata of the queue and the pointer to the queue node.
3、 Cluster exception handling
According to the characteristics of nodes without secure copies, when the cluster node crashes, the node queue and associated bindings are lost, and the consumers attached to the queue lose their subscription information. How to deal with this problem?
This problem can be divided into two situations:
There are two storage types of nodes:
The disk node stores the configuration information and meta information on the disk, and the internal secondary node stores these information in memory. Of course, the performance of the internal secondary node greatly exceeds that of the disk node.
The single node system must be a disk node, otherwise all system configuration information will be lost every time you restart rabbitmq.
Rabbitmq requires at least one disk node in the cluster. When a node joins or leaves the cluster, it must notify the disk node.
Special exception: the only disk node in the cluster crashes
What happens if the only disk node in the cluster crashes?
If the disk node of the unique disk crashes, the following operations cannot be performed:
Summary: if the disk node of the only disk crashes, the cluster can keep running, but you can't change anything.
Solution: set up two disk nodes in the cluster. As long as one can, you can operate normally.
5、 Cluster construction method
In this chapter, we use docker to create a rabbitmq cluster. Firstly, it is easy to operate, secondly, it can make more full use of server hardware resources, and thirdly, docker is also the mainstream deployment scheme. For more details of docker, please see my another article: "deploying rabbitmq clusters with docker". Next, enter our main body. Cluster construction is divided into two steps:
Step 1: install multiple rabbitmq
docker run -d --hostname rabbit1 --name myrabbit1 -p 15672:15672 -p 5672:5672 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.6.15-management
docker run -d --hostname rabbit2 --name myrabbit2 -p 5673:5672 --link myrabbit1:rabbit1 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.6.15-management
docker run -d --hostname rabbit3 --name myrabbit3 -p 5674:5672 --link myrabbit1:rabbit1 --link myrabbit2:rabbit2 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.6.15-management
For specific parameter meanings, see "starting rabbitmq" above.
Note:
Step 2: join the rabbitmq node to the cluster
Set node 1:
Set node 2 to join the cluster:
The parameter "-- RAM" indicates that it is set as a memory node. Ignoring the secondary parameter, it defaults to a disk node.
Set node 3 to join the cluster:
After setting, you can access it using http: / / physical machine IP: 15672. The default account password is guest / guest. The effect is as follows:
So far, we have completed the establishment of rabbitmq cluster and started 3 nodes, 1 disk node and 2 memory nodes.
Set node type
If you want to change the node type, you can modify it through the command, as follows:
Remove node
If you want to remove a node from the cluster, you can use the following command:
Cluster restart sequence
The order of cluster restart is fixed and reverse. As follows:
Finally, the shutdown must be a disk node, otherwise it may cause cluster startup failure, data loss and other abnormalities.
6、 Mirror queue
The mirror queue is rabbit 2 A new function brought by version 6.0 allows the built-in dual active redundancy option. Unlike ordinary queues, the mirror node has a copy of the slave queue from other nodes in the cluster. Once the master node is unavailable, the oldest slave queue will be elected as the new master queue.
How the mirror queue works: to some extent, you can think of the mirror queue as having a hidden fanout switch that instructs the sender channel to distribute messages to the slave queue.
Set mirror queue
Set the image queue command: "rabbitmqctl set_policy name matching pattern (regular) image definition". For example, set the image queue with the name mypolicy to match all queues with the name starting with amp stored on two nodes. The command is as follows:
It can be seen that there are three parameters for setting the image queue, and each parameter is separated by a space.
The effect of setting up the image queue to store two nodes is shown in the following figure:
View mirror queue
Delete mirror queue
reference material
Book: "rabbitmq actual combat - efficient deployment of distributed message queue" -- it is not recommended to buy programs, but rather to operate and maintain them https://www.cnblogs.com/luo-mao/p/5909889.html https://www.jianshu.com/p/85543491ab00