Rabbitmq series (V) deploying rabbitmq clusters using docker
summary
This article focuses on the use of docker, how to deploy rabbitmq cluster and the most basic docker installation. This article does not describe too much. Readers can do it by themselves.
Installation of docker on Windows 10
Because I use windows, I recommend a good installation article. See the following for details: https://blog.csdn.net/xiaoping0915/article/details/75094857
Note: set alicloud docker hub acceleration and configure the registry mirrors address“ https://j0andt2p.mirror.aliyuncs.com/ ”。
Alibaba cloud image Market: https://dev.aliyun.com/search.html
Download rabbitmq image
1. Image address
Rabbitmq docker official authentication image address: https://dev.aliyun.com/detail.html?spm=5176.1971733.2.16.6c045aaaDxFoMn&repoId=1256
2. Installation command
Before installation, remember to set the docker hub as Alibaba cloud's acceleration to facilitate installation.
Note that the mirror version with the suffix "- management" contains the web console.
3. View installation
Use the command: docker images to view the downloaded image, as shown in the following figure:
Docker common commands
Container stop: docker stop container name start container: docker start container name delete container: docker RM container name delete image: docker RMI image name view all containers running: docker PS view all containers: docker PS - a container copy files to physical machine: docker CP container name: container directory physical machine directory physical machine copy files to container : docker CP physical machine directory container name: container directory
Enter docker directory
There are three simple ways to enter the docker container:
1.attach
Attach has a disadvantage. When the connection is terminated or exit is used, the container will exit the background, so it is not suitable for production environment. Since it's not easy to use, we can't introduce it here.
2.SSH
According to our previous habit of using liunx, Using SSH to connect to the server seems to be a very attractive answer, but it is neither elegant nor the best practice. Click to view the details: https://blog.csdn.net/bolg_hero/article/details/50267103
3.exec
Exec is undoubtedly our best practice at this stage. Let's see how it is used.
Enter the docker command:
Where / bin / bash may also be / bin / sh
Use docker exec -- help to view more commands and command descriptions.
Exit docker:
Start rabbitmq
Parameter Description:
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
Start multiple rabbitmq
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
Set up rabbitmq cluster
Step 1: install rabbitmq;
Step 2: join the rabbitmq node to the cluster;
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:
Three nodes, one disk node and two memory nodes were started.
Configure the same Erlang cookie
In some special cases, such as several single physical machines that have been running for a period of time, we have not set the same Erlang cookie value before. Now we need to deploy a single physical machine into a cluster to synchronize the Erlang cookie value.
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.
To know the location of Erlang cookies, first obtain the home dir path in the rabbitmq startup log as the root path. Use "docker logs container name", as shown in the following figure:
Therefore, the full path of Erlang cookie is "/ var / lib / rabbitmq /. Erlang. Cookie".
Note: everyone's Erlang cookie location may be different. Be sure to check their home dir path.
After obtaining the Erlang cookie of the first rabbitmq, you only need to copy this file to other rabbitmq nodes.
The replication commands between the physical machine and the container are as follows:
Set Erlang cookie file permissions: "Chmod 600 / var / lib / rabbitmq /. Erlang. Cookie".
reference material
https://blog.csdn.net/xiaoping0915/article/details/75094857
https://blog.csdn.net/luosai19910103/article/details/78604692
https://blog.csdn.net/bolg_hero/article/details/50267103
http://ivivisoft.com/2017/03/06/rabbitmq-cluster/
Long press the QR code to pay more attention to the author's developments