Docker builds rabbitMQ clusters

Install Docker

1, the simplest way to install docker directly using the official script installation (automatic installation)

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
Copy the code

Start the docker

sudo systemctl start docker
Copy the code

2, manual installation

If you have docker installed before, uninstall the old version, or don’t uninstall it, as long as it works

sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
Copy the code

Then install the dependencies required by the Docker software

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2
Copy the code

Then install the latest Docker

sudo yum install docker-ce docker-ce-cli containerd.io
Copy the code

Start the

sudo systemctl start docker
Copy the code

Second, the rabbitmq

Pull the RabbitMQ image to download MQ with the console

Docker pull the rabbitmq: 3.8.9 - managementCopy the code

Start the image, -d indicates background operation –hostname sets hostname –name alias of the container -p port mapping -e sets Erlang cookie // Erlang cookie in the cluster Must be consistent

docker run -d --hostname devRabbit1 --name qhDevRabbit1 -p 15672:15672 -p 5672:5672 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' RabbitMQ :3.8.9-management docker run -d --hostname devRabbit2 --name qhDevRabbit2 -p 5673:5672 --link qhDevRabbit1:devRabbit1 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' Rabbitmq :3.8.9- Management docker run -d --hostname devRabbit3 --name qhDevRabbit3 -p 5674:5672 --link qhDevRabbit1:devRabbit1 --link QhDevRabbit2: devRabbit2 - e RABBITMQ_ERLANG_COOKIE = 'rabbitcookie rabbitmq: 3.8.9 - managementCopy the code

Then go into each container to configure the cluster

The first one

docker exec -it qhDevRabbit1 bash
Copy the code

Execute inside the container

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
Copy the code

The second

docker exec -it qhDevRabbit2 bash
Copy the code

Execute inside the container

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@devRabbit1
rabbitmqctl start_app
Copy the code

The third

docker exec -it qhDevRabbit3 bash
Copy the code

Execute inside the container

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@devRabbit1
rabbitmqctl start_app
Copy the code

The orders for the last two are the same

Set the mirroring queue policy to run on any node

rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'
Copy the code

Finally enter the management console to see the line

Visit http://ip:15672