Article catalogue
preface
RabbitMQ, a message queuing middleware product, is written based on Erlang. Erlang language is naturally distributed (realized by synchronizing magic cookie s of each node of Erlang cluster).
Therefore, RabbitMQ naturally supports clustering. This makes it unnecessary for RabbitMQ to implement the HA scheme and save the metadata of the cluster through ZooKeeper like ActiveMQ and Kafka. Clustering is a way to ensure reliability. At the same time, it can increase message throughput through horizontal expansion. Let's take a look at the overall scheme of RabbitMQ cluster:
1, Construction of RabbitMQ cluster
1. Pull the image
docker pull rabbitmq:3-management
Note that the image version with the suffix "- management" is included in the web console.
2, RabbitMQ configuration
1. Start RabbitMQ
docker run -d --hostname myrabbit --name myrabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management docker run -d --hostname myrabbit1 --name myrabbit1 -p 15673:15672 -p 5673:5672 rabbitmq:3-management
Parameter Description:
- -d background process running
- hostname RabbitMQ host name
- Name container name
- -p port:port local port: container port
- -p 15672:15672 http access port
- -p 5672:5672 amqp access port
After startup, use: docker ps to check the running status of the program.
Use: http: / / host ip:15672 to access. The default user name and password are: guest/guest
In this way, we can use http: / / host ip:15672 and http: / / host ip:15673 for access. The default account password is still guest/guest
2. Set up RabbitMQ cluster
2.1 operating vessel
docker run -d --hostname rabbit1 --name myrabbit1 -p 15672:15672 -p 5672:5672 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3-management docker run -d --hostname rabbit2 --name myrabbit2 -p 5673:5672 --link myrabbit1:rabbit1 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3-management docker run -d --hostname rabbit3 --name myrabbit3 -p 5674:5672 --link myrabbit1:rabbit1 --link myrabbit2:rabbit2 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3-management
Note:
- Use "– link" connection between multiple containers. This attribute cannot be less.
- The Erlang Cookie value must be the same, that is, rabbitmq_ ERLANG_ The value of the cookie parameter must be the same.
2.2 configuring nodes to clusters
Physical node
docker exec -it myrabbit1 bash rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl start_app exit
Memory node 1
docker exec -it myrabbit2 bash rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl join_cluster --ram rabbit@rabbit1 rabbitmqctl start_app exit
Memory node 2
docker exec -it myrabbit3 bash rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl join_cluster --ram rabbit@rabbit1 rabbitmqctl start_app exit
2.3 successful configuration
Three nodes will appear after successful configuration, as shown in the figure
summary
1. Role of Erlang cookies
Because RabbitMQ is implemented in Erlang, Erlang cookies are equivalent to the secret keys for communication between different nodes. Erlang nodes obtain authentication by exchanging Erlang cookies. Just make sure that each node has the same Erlang Cookie
2. Location of Erlang cookies
The path of Erlang Cookie is "/ var/lib/rabbitmq/.erlang.cookie".