docker distributed cluster deployment rabbitmq

rabbitmq message queue is currently more popular use of technology, where it and other types of comparisons in this technology do not go into details. This paper describes how to deploy rabbitmq distributed cluster at Docker. This article does not tell docker download and install rabbitmq image.

First, preparation

      Taking as an example the two servers. A server for IP 192.168.1.10, IP server B is 192.168.1.11. In order to facilitate the subsequent management of more docker disposed, respectively A, B docker two servers which new directory, the following example structure:

            cd /home/user/

             mkdir docker

             cd docker 

             mkdir rabbitmq

             cd  rabbitmq

             touch hosts

             vim hosts  

Just enter the created hosts file configuration server mapping, later edited wq to save and exit

     192.168.1.10  rabbit1

     192.168.1.11  rabbit2

Second, the launch has been downloaded rabbitmq A mirror server

 docker run -d --privileged=true --net host --hostname rabbit1 --name rabbitmq1 -v /home/user/docker/rabbitmq:/var/lib/rabbitmq -v /home/user/docker/rabbitmq/hosts:/etc/hosts -e RABBITMQ_ERLANG_COOKIE='your erlang cookie' rabbitmq_bac

  important point:

       1, adding --privileged = true is the docker container really have root access to the server, do not add this may lead to the container can not be mounted to a local directory.

       2, RABBITMQ_ERLANG_COOKIE two servers must be the same, or can not be added to the cluster nodes. RABBITMQ_ERLANG_COOKIE value may .erlang.cookie container file / var / lib / rabbitmq in view, because it is a hidden file ls -a command needs to be used when viewing the document. Then use the more command or tail command to view the files stored value. RABBITMQ_ERLANG_COOKIE value is the value corresponding to the text inside. Meanwhile, in order to make the same cookie multiple servers, which .erlang.cookie sure to copy the files on a server to replace several other servers.

   Third, the start has been downloaded rabbitmq mirror server B

docker run -d --privileged=true --net host --hostname rabbit2 --name rabbitmq2 -v /home/user/docker/rabbitmq:/var/lib/rabbitmq -v /home/user/docker/rabbitmq/hosts:/etc/hosts -e RABBITMQ_ERLANG_COOKIE='your erlang cookie' rabbitmq_bac

 After creating a good run container, the container into the interior of the rabbit node added to the cluster.

docker exec -it rabbit2 /bin/bash

rabbitmqctl stop_app

rabbitmqctl join_cluster rabbit@rabbit1

rabbitmqctl start_app

This is basically a distributed cluster rabbitmq build better.

Finally, why I would prefer the deployment docker it. For one or two servers, his advantage is not obvious, but when we need to build a large cluster to his advantage will be reflected, personal feelings following main points:

  1, installation is quick and easy to deploy. Docker written script can quickly build a service.

  2, each server to maintain a consistent version of the same services and content. docker backup migration is for us a very good offer this capability. We can put our already configured docker container to save the image and then export to a local form our own version, and then loaded into a docker other servers, we can guarantee our service version is exactly the same. This also provides great convenience for us on the line, but also make us avoid version problems or other causes as a result of inconsistencies.

Released four original articles · won praise 0 · Views 4820

Guess you like

Origin blog.csdn.net/abc1230456/article/details/104737981