AbbitMQ Cluster Setup Job Based on Docker

Keywords: RabbitMQ Docker network sudo

AbbitMQ Cluster Setup Job Based on Docker

1. Goals

Set up a RabbitMQ cluster with three nodes

2. Preparations

2.1 Operating System

Set the software source of ubuntu as a mirror of Ali to improve download speed.See https://opsx.alibaba.com/mirror

Beginners recommend GUI configuration: System Settings - > Software and Updates Selection Download Server - > "Mirs.aliyun.com"

2.2 Docker installation and configuration:

Official Web Detailed Tutorial: https://docs.docker.com/install/linux/docker-ce/ubuntu/

  • This job is installed using scripts (reference Rookie Bird Tutorial ), the same principle Official Install using the convenience script .Download the sh script and execute it.
    $ wget -qO- https://get.docker.com/ | sh
    
  • During the process of validating this job, due to network reasons, docker.com is sometimes not available in China, which makes it impossible to download sh scripts.So instead choose to install using the software source, note the package name docker.io
    $ apt install docker.io
    
    View version information after installation
    $ docker -v
    Docker version 17.12.1-ce, build 7390fc6
    
  • Add permissions: Create a new (if not exist) and add the current user to the docker user group, you can run the docker without sudo (you need to log in again).
    $ sudo groupadd docker
    groupadd: group 'docker' already exists
    $ sudo usermod -aG docker $USER
    
    The docker user group is automatically created after the docker is installed in this job
  • Configure the domestic mirror with the following results:
    $ cat /etc/docker/daemon.json
    {
      "registry-mirrors": ["http://hub-mirror.c.163.com"]
    }
    
    Restart docker service for configuration to take effect
    $ sudo service docker restart
    
  • Finally, the hello-world test ([docker basic command reference] @Newbie Tutorial](http://www.runoob.com/docker/docker-run-command.html))
    $ docker run --rm hello-world
    

3. Deploy RabbitMQ Cluster

It is very convenient to deploy RabbitMQ using docker. This job uses a mirror rabbitmq:management with a web management interface.

For the purpose of building a cluster, there are two things to note about deploying a single AbbitMQ node:

RabbitMQ nodes address each other using domain names, either short or fully-qualified (FQDNs). Therefore hostnames of all cluster members must be resolvable from all cluster nodes, as well as machines on which command line tools such as rabbitmqctl might be used.

  • All nodes need to have the same ErLang Cookie set.

RabbitMQ nodes and CLI tools (e.g. rabbitmqctl) use a cookie to determine whether they are allowed to communicate with each other. For two nodes to be able to communicate they must have the same shared secret called the Erlang cookie. The cookie is just a string of alphanumeric characters up to 255 characters in size.

3.1 Deploying RabbitMQ applications
  • This job uses the docker networking scheme for domain name resolution, so create a network named rabbit_net first
$ docker network create rabbit_net
  • Deploy three RabbitMQ nodes, rabbitmq-node0, rabbitmq-node1, and rabbitmq-node2, set the same ErLang Cooike, and add it to rabbit_net.Because the default configuration of RABBITMQ_NODENAME under Unix* is rabbit@$HOSTNAME, this job keeps the container name identical to the hostname, making the hostname identical in the HOSTAME and rabbit_net of RabbitMQ.
$ docker run -d --name rabbitmq-node0 \
    -h rabbitmq-node0 \
    --publish 5671:5671 \
    --publish 5672:5672 \
    --publish 25672:25672 \
    --publish 15672:15672 \
    -e RABBITMQ_ERLANG_COOKIE='JOLLYCHICFOURIER' \
    --net=rabbit_net \
    rabbitmq:management
    
$ docker run -d --name rabbitmq-node1 \
    -h rabbitmq-node1 \
    --publish 5681:5671 \
    --publish 5682:5672 \
    --publish 25682:25672 \
    --publish 15682:15672 \
    -e RABBITMQ_ERLANG_COOKIE='JOLLYCHICFOURIER' \
    --net=rabbit_net \
    rabbitmq:management
    
$ docker run -d --name rabbitmq-node2 \
    -h rabbitmq-node2 \
    --publish 5691:5671 \
    --publish 5692:5672 \
    --publish 25692:25672 \
    --publish 15692:15672 \
    -e RABBITMQ_ERLANG_COOKIE='JOLLYCHICFOURIER' \
    --net=rabbit_net \
    rabbitmq:management

Functions of RabbitMQ ports:

4369 (epmd)
5672, 5671 (AMQP 0-9-1 without and with TLS)
15672 (if management plugin is enabled)
25672 (Erlang distribution)
61613, 61614 (if STOMP is enabled)
1883, 8883 (if MQTT is enabled)

So by default port configuration, you can log in after deployment http://host IP:15672 To get to the administration page.rabbitmq default user name and password: guest/guest.

3.2 Cluster Configuration

Based on the nodes deployed above, RabbitMQ's cluster configuration is relatively simple.Because the nodes are all on the same network and have the same ErlangCookie set up.So by logging in to any one node, rabbitmqctl can operate on all the other nodes in the cluster.

  • Log in to rabbitmq-node0 using docker
$ docker exec -it rabbitmq-node0 /bin/sh
  • Cluster configuration is done in rabbitmq-node0.
$ rabbitmqctl -n rabbit@rabbitmq-node1 stop_app
$ rabbitmqctl -n rabbit@rabbitmq-node1 join_cluster rabbit@rabbitmq-node0
$ rabbitmqctl -n rabbit@rabbitmq-node1 start_app

$ rabbitmqctl -n rabbit@rabbitmq-node2 stop_app
$ rabbitmqctl -n rabbit@rabbitmq-node2 join_cluster rabbit@rabbitmq-node0
$ rabbitmqctl -n rabbit@rabbitmq-node2 start_app

At this point, the job is finished.

Posted by waygood on Thu, 09 May 2019 20:06:39 -0700