Docker: How to build a rabbitmq image cluster

Docker: How To Build A Rabbitmq Image Cluster

Ordinary cluster:
The queue Queue we created at the moment, its metadata (primarily some configuration info of Queue) can be synchronized in all RabbitMQ cases, however the messages within the queue will solely exist on one RabbitMQ occasion, not can be synchronized to different queues.

When we devour a message, whether it is linked to one other occasion, then that occasion will find the situation of the Queue via metadata, then entry the occasion the place the Queue is situated, and pull the information and ship it to the patron.

This sort of cluster can enhance the message throughput of RabbitMQ, but it surely can not assure excessive availability, as a result of as soon as a RabbitMQ occasion hangs, the message can’t be accessed. If the message queue is persistent, it will possibly proceed after the RabbitMQ occasion is restored. Accessed; if the message queue is just not continued, the message is misplaced.

Mirrored cluster : It is predicated on the conventional mode, and the required queue is made into a mirrored queue, which exists in a number of nodes to obtain excessive availability (HA). This mode solves the above issues. Broker will actively synchronize message entities between mirror nodes, and there’s no want to quickly pull information when the patron fetches information. The uncomfortable side effects of this mode are additionally apparent. In addition to decreasing system efficiency, if there are too many mirrored queues and a giant variety of messages coming into, the community bandwidth contained in the cluster can be significantly consumed. Generally, mirror mode is really helpful for situations with excessive reliability necessities.

Node kind :

  • RAM node: The reminiscence node shops all of the metadata definitions of queues, switches, bindings, customers, permissions and vhosts in reminiscence. The profit is that operations similar to swap and queue declarations may be made sooner.
  • Disk node: Store metadata on disk. A single-node system solely permits disk-type nodes to forestall system configuration info from being misplaced when RabbitMQ is restarted.

RabbitMQ requires a minimum of one disk node within the cluster, all different nodes may be reminiscence nodes, and when a node joins or leaves the cluster, it should notify a minimum of one disk node of the change. If the one disk node within the cluster crashes, the cluster can nonetheless maintain operating, however no different operations (add, delete, modify, examine) may be carried out till the node recovers. To make sure the reliability of cluster info, or when you find yourself unsure whether or not to use disk nodes or reminiscence nodes, it’s endorsed to use disk nodes straight.

READ :  How to add Google Analytics code to Drupal 7

1. Build the RabbitMq working surroundings

Operating surroundings: centos7, build two rabbitmq nodes via docker.

1. Query the rabbitmq image via search

docker search rabbitmq

2. Pull the newest official image of rabbitmq via pull.
It is healthier to convey the model with the tag of administration. Otherwise, the newest newest is pulled, and the online administration web page can’t be displayed in full, and an summary: administration solely mode can be prompted.

docker pull rabbitmq:3.8.25-management

3. Create the container

docker run -d --name rabbitmq1 -p 5672:5672 -p 15672:15672 --hostname myRabbit1 
-e RABBITMQ_DEFAULT_VHOST=my_vhost1  -e RABBITMQ_DEFAULT_USER=admin 
-e RABBITMQ_DEFAULT_PASS=admin a4eb038c2ecb

–title: container title

-p: endpoint mapping

–hostname: node title of rabbitmq

-e RABBITMQ_DEFAULT_VHOST: digital host title

-e RABBITMQ_DEFAULT_USER: login account

-e RABBITMQ_DEFAULT_PASS: Login password

a4eb038c2ecb is the mirror id, exchange it in accordance to your individual state of affairs.

4. Start the administration web page
Our image doesn’t open the online administration web page by default, so we enter the container startup via the exec command. The surroundings of this image is centos

[[email protected] ~]# docker exec -it 639a151c5440 /bin/bash
[email protected]:/# rabbitmq-plugins allow rabbitmq_management

Access http://localhost:15672/ within the browser to open it, and one other rabbitmq does the identical, the distinction is that the ports are modified to 5673 and 15673, and so forth., and when creating a container, use –hyperlink to join to the primary rabbitmq node (or Create a bridged community connection), as follows

docker run -d --name rabbitmq2 -p 5673:5672 -p 15673:15672 --hostname myRabbit2 
-e RABBITMQ_DEFAULT_VHOST=my_vhost2  -e RABBITMQ_DEFAULT_USER=admin 
-e RABBITMQ_DEFAULT_PASS=admin --link rabbitmq1:myRabbit1 a4eb038c2ecb

5. Set erlang cookie
The erlang cookie may be set by the parameter -e RABBITMQ_ERLANG_COOKIE when operating the container, however it’s now expired and deprecated.

We first examine the operating log of the container via the docker logs command, and search for the house dir parameter as follows

[[email protected] ~]
//.....
  Starting dealer...2021-11-17 02:19:55.859245+00:00 [info] <0.222.0>
2021-11-17 02:19:55.859245+00:00 [info] <0.222.0>  node           : [email protected]
2021-11-17 02:19:55.859245+00:00 [info] <0.222.0>  dwelling dir       : /var/lib/rabbitmq
2021-11-17 02:19:55.859245+00:00 [info] <0.222.0>  config file(s) : /and so forth/rabbitmq/conf.d/10-default-guest-user.conf
2021-11-17 02:19:55.859245+00:00 [info] <0.222.0>                 : /and so forth/rabbitmq/conf.d/management_agent.disable_metrics_collector.conf
2021-11-17 02:19:55.859245+00:00 [info] <0.222.0>  cookie hash    : Aed9pjd9vYWw3hng7Gjmkg==
2021-11-17 02:19:55.859245+00:00 [info] <0.222.0>  log(s)         : /var/log/rabbitmq/[email protected]_upgrade.log
2021-11-17 02:19:55.859245+00:00 [info] <0.222.0>                 : <stdout>
2021-11-17 02:19:55.859245+00:00 [info] <0.222.0>  database dir   : /var/lib/rabbitmq/mnesia/[email protected]

So the .erlang.cookie file is below this path, we are able to see this file once we enter the container

[email protected]:~# ls -a /var/lib/rabbitmq
.  ..  .bash_history  .erlang.cookie  mnesia

Let’s set the permissions of the erlang cookie and run the next code within the container. If the permissions are usually not sufficient, the following operations will report an error

chmod 600 /var/lib/rabbitmq/.erlang.cookie

After that, we copy the .erlang.cookie file in rabbitmq1 to the bodily machine via the docker cp command after which copy it to the container of rabbitmq2. The copy command between the bodily machine and the container is as follows:

READ :  asp.net core – Ocelot – Add Token to Downstream Url – Stack Overflow

The container copies recordsdata to the bodily machine: docker cp Container title: Container listing
Physical machine listing Physical machine copies recordsdata to the container: docker cp Physical machine listing Container title: Container listing
The particular code is as follows:

docker cp rabbitmq1:/var/lib/rabbitmq/  d:workspace
docker cp d:workspacerabbitmq.erlang.cookie rabbitmq2:/var/lib/rabbitmq/

After copying, the rabbitmq2 container wants to be restarted, in any other case the next error can be reported when the rabbitmqctl command is executed:

[error] Cookie file /var/lib/rabbitmq/.erlang.cookie have to be accessible by proprietor solely

Normal cluster mode

After restarting, enter the container and add the node of rabbitmq2 to rabbitmq1 to create a frequent cluster, and execute the next codes respectively:

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram [email protected]    //myRabbitmq1 is the hostname of rabbitmq in rabbitmq1 container
rabbitmqctl start_app

After that, we are able to see two nodes on the net administration web page.
Docker How To Build A Rabbitmq Image Cluster
Create a queue at any node, and one other node may even generate the identical queue. And it may be discovered that the vhost of rabbitmq2 has modified from my_vhost2 to my_vhost1, which is identical as rabbitmq.

3. Mirror Mode

The mirror mode is to enter the rabbitmq1 container on the idea of the conventional mode and enter the next command:

rabbitmqctl set_policy -p my_vhost1 ha-all "^" '{"ha-mode":"all"}' --apply-to all

The particular format is

rabbitmqctl set_policy [-p Vhost] Name Pattern Definition [Priority]
-p Vhost: Optional parameter, set for the queue below the desired vhost
Name: the title of the coverage
Pattern: Matching sample of the queue (common expression)
Definition: definition of the mirror, together with three elements ha-mode, ha-params, ha-sync-mode
        ha-mode: specifies the sample of the mirror queue, legitimate values are all/precisely/nodes
            all: means mirroring on all nodes within the cluster
            precisely: means mirroring on a specified variety of nodes, the variety of nodes is specified by ha-params
            nodes: means mirroring on the desired nodes, the node names are specified by ha-params
        ha-params: as a parameter, as a complement to ha-mode
        ha-sync-mode: the best way to synchronize messages within the queue, legitimate values are automated and guide
precedence: optionally available parameter, the precedence of the coverage

rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}' --apply-to all

Or log in to the rabbitmq administration web page –> Admin –> Policies –> Add / replace a coverage
1667383929 394 Docker How To Build A Rabbitmq Image Cluster
title: coverage title

READ :  An Object Reference Is Required For The Non-Static Field, Method, Or Property

Pattern: ^ matcher, just one means match all. message refers to the title of the queue beginning with the synchronization “message”

Definition: ha-mode=all is a matching kind, which is split into 3 modes: all (representing all queues)
Priority: Priority, first sorted in accordance to precedence, the upper the worth, the upper the precedence; the identical precedence is sorted in accordance to the creation time , the later it’s created, the upper the precedence.

Briefly clarify the distinction between Operator Policy and User Policy:

  • Operator Policy is for service suppliers or company infrastructure departments to set sure normal guidelines that want to be enforced
  • User Policy is a algorithm for enterprise functions

Operator Policy and User Policy can be mixed and utilized to the queue. In order to forestall the protection of some key attributes of the queue by the Operator Policy, such because the Dead Letter Exchange of the lifeless letter queue alternate, leading to surprising outcomes of enterprise functions, the Operator Policy solely helps expire, message -ttl, max-length, max-length-bytes4 parameters.

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *