Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Deploy a RabbitMQ cluster using Docker

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Author: Wang Lei's blog source: Wechat official account (Wang Lei's blog)

Original link: https://mp.weixin.qq.com/s/yINNN2HImYlWsUo5DowbjA

Overview

This article focuses on the use of Docker, and how to deploy RabbitMQ clusters, the most basic Docker installation, this article does not do too much description, readers can take care of themselves.

Installation of Docker on Windows10

Because I am using the Windows system, all recommend a good installation article, see: https://blog.csdn.net/xiaoping0915/article/details/75094857 for details

Note: set Ali Cloud Docker Hub acceleration and configure Registry mirrors address "https://j0andt2p.mirror.aliyuncs.com/"".

Aliyun's Mirror Market: https://dev.aliyun.com/search.html

Download RabbitMQ image

1. Mirror address

RabbitMQ Docker official Certification Image address: https://dev.aliyun.com/detail.html?spm=5176.1971733.2.16.6c045aaaDxFoMn&repoId=1256

two。 Installation command

Before installing, remember to set Docker Hub as Ali Cloud's acceleration to facilitate installation.

Docker pull rabbitmq:3.6.15-management

Note that you use the mirror version with the suffix "- management", which includes the web console.

3. View installation

Use the command: docker images to view the downloaded image, as shown below:

Docker common commands

Container stop: docker stop container name

Startup 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

Copy files from container to physical machine: docker cp container name: container directory physical machine directory

Copy files from physical machine to container: docker cp physical machine directory container name: container directory

Enter the Docker directory

There are three simple ways to enter the Docker container:

Use attach

Use SSH

Use exec

1.attach

One drawback of attach is that when the connection is terminated, or after using exit, the container will exit the background, so it is not suitable for production environment. Since it doesn't work, we won't introduce it too much 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 this is not elegant, nor is it the best practice. For more information, click to see: https://blog.csdn.net/bolg_hero/article/details/50267103

3.exec

Exec is undoubtedly our best practice at this stage, let's take a look at how it is used.

Enter the docker command:

Docker exec-it / bin/bash

Among them / bin/bash may also be / bin/sh.

Use docker exec-- help to see more commands and instructions.

Exit docker:

Exit

Start RabbitMQ

Docker run-d-- hostname localhost-- name myrabbit-p 15672 rabbitmq:3.6.15-management 15672 rabbitmq:3.6.15-management

Parameter description:

-d background process running

Hostname RabbitMQ host name

Name Container name

-p port:port local port: container port

-p 15672 http access port

-p 5672 5672 amqp access port

After the startup is complete, use: docker ps to view the running of the program.

Use: http:// host ip:15672 access, user name password using the default: guest/guest.

Start multiple RabbitMQ

Docker run-d-- hostname localhost-- name myrabbit-p 15672 rabbitmq:3.6.15-management 15672 rabbitmq:3.6.15-management

Docker run-d-- hostname localhost2-- name myrabbit2-p 15673 rabbitmq:3.6.15-management 15672 rabbitmq:3.6.15-management

So we can use the http:// host ip:15672 and the http:// host ip:15673 to access, and 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

Step 1: install RabbitMQ

Docker run-d-- hostname rabbit1-- name myrabbit1-p 15672 RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.6.15-management 15672 RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.6.15-management

Docker run-d-hostname rabbit2-name myrabbit2-p 5673 name myrabbit2 5672-- link myrabbit1:rabbit1-e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.6.15-management

Docker run-d-- hostname rabbit3-- name myrabbit3-p 5674 link myrabbit1:rabbit1-- link myrabbit2:rabbit2-e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.6.15-management

For the meaning of the parameters, see the section "starting RabbitMQ" above.

Note:

Use "--link" connection between multiple containers. This property cannot be reduced.

The Erlang Cookie value must be the same, that is, the value of the RABBITMQ_ERLANG_COOKIE parameter must be the same, as shown in the section "configuring the same Erlang Cookie" below.

Step 2: join the RabbitMQ node to the cluster

Set up Node 1:

Docker exec-it myrabbit1 bash

Rabbitmqctl stop_app

Rabbitmqctl reset

Rabbitmqctl start_app

Exit

Set node 2 and join the cluster:

Docker exec-it myrabbit2 bash

Rabbitmqctl stop_app

Rabbitmqctl reset

Rabbitmqctl join_cluster-ram rabbit@rabbit1

Rabbitmqctl start_app

Exit

The parameter "--ram" indicates that it is set to a memory node, while ignoring the secondary parameter defaults to the disk node.

Set node 3 to join the cluster:

Docker exec-it myrabbit3 bash

Rabbitmqctl stop_app

Rabbitmqctl reset

Rabbitmqctl join_cluster-ram rabbit@rabbit1

Rabbitmqctl start_app

Exit

Once set up, the http:// physical machine ip:15672 is used to access it. The default account password is guest/guest, as shown below:

Three nodes, one disk node and two memory nodes are started.

Configure the same Erlang Cookie

In some special cases, such as several individual physical machines that have been running for some time, we have not set the same Erlang cookie value before. now we want to deploy a single physical machine into a cluster to realize that we need to synchronize the cookie value of Erlang.

1. Why configure the same erlang cookie?

Because RabbitMQ is implemented in Erlang, Erlang Cookie is equivalent to the secret key of communication between different nodes, and Erlang nodes are authenticated by exchanging Erlang Cookie.

Location of 2.Erlang Cookie

To know the location of the Erlang Cookie, first get the home dir path in the RabbitMQ startup log as the root path. Use: "docker logs Container name" to view, as shown below:

So the entire path to Erlang Cookie is "/ var/lib/rabbitmq/.erlang.cookie".

Note: everyone's erlang cookie location may be different, be sure to check your own home dir path.

3. Copy Erlang Cookie to other RabbitMQ nodes

After you get the Erlang Cookie of the first RabbitMQ, you just need to copy the file to another RabbitMQ node.

The copy command between the physical machine and the container is as follows:

Copy files from container to physical machine: docker cp container name: container directory physical machine directory

Copy files from physical machine to container: docker cp physical machine directory container name: container directory

Set Erlang Cookie file permissions: "chmod 600 / var/lib/rabbitmq/.erlang.cookie".

references

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 attention to more developments of the author

Cdn.apigo.cn/gongzhonghao.jpg ">

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report