docker搭建rabbitmq集群

单机版搭建

        1 拉取rabbitMq镜像

                docker pull rabbitmq:3.9.5-management
        2 启动rabbitMq容器

                docker run  -d --name rabbitmq-104 -p 15672:15672  -p 5672:5672 -e                         RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin                         rabbitmq:3.9.5-management

        3 登录rabbitMq控制台查看

                浏览器访问:http:192.168.56.104:15672

        docker搭建rabbitmq集群_第1张图片

集群搭建

        1 机器准备         

                    192.168.56.102
                    192.168.56.103
                    192.168.56.104

        2 拉取镜像

                分别在3台机器上执行:docker pull rabbitmq:3.9.5-management

        3 启动容器

                102机器: docker run  -d --hostname node2 --add-host=node3:192.168.56.103 --add-host=node4:192.168.56.104 --name rabbitmq1 --net host -p 15672:15672  -p 5672:5672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -e RABBITMQ_ERLANG_COOKIE='rabbit_mq'  rabbitmq:3.9.5-management

                103机器:docker run  -d --hostname node3 --add-host=node2:192.168.56.102 --add-host=node4:192.168.56.104 --name rabbitmq2 --net host -p 15672:15672  -p 5672:5672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -e RABBITMQ_ERLANG_COOKIE='rabbit_mq'  rabbitmq:3.9.5-management

                104机器:docker run  -d --hostname node4 --add-host=node2:192.168.56.102 --add-host=node3:192.168.56.103 --name rabbitmq3 --net host -p 15672:15672  -p 5672:5672 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -e RABBITMQ_ERLANG_COOKIE='rabbit_mq'  rabbitmq:3.9.5-management

        4 相关配置

                分别进入三台虚拟机docker容器中:docker exec -it {containerName} bash

                102机器:

                        #首先停止当前MQ

                        rabbitmqctl stop_app

                        #resetMQ

                        rabbitmqctl reset

                        #重新启动MQ

                        rabbitmqctl start_app

                        #退出容器

                        exit

                103机器

                        #首先停止当前MQ
                        rabbitmqctl stop_app
                        #resetMQ
                        rabbitmqctl reset
                        #跟机器1的消息队列建立关系
                        rabbitmqctl join_cluster --ram rabbit@node2
                        #重新启动MQ
                        rabbitmqctl start_app
                        退出容器
                        exit

                104机器:

                        #首先停止当前MQ
                        rabbitmqctl stop_app
                        #resetMQ
                        rabbitmqctl reset
                        #跟机器1的消息队列建立关系
                        rabbitmqctl join_cluster --ram rabbit@node2
                        #重新启动MQ
                        rabbitmqctl start_app
                        #退出容器
                        exit

                注意事项:
                            节点间通信的cookie一定要相同
                            如果在执行 "rabbitmqctl join_cluster --ram rabbit@node2"报错,

                            不用管,直接执行 rabbitmqctl start_app

        5 登录控制台查看集群信息

                docker搭建rabbitmq集群_第2张图片

你可能感兴趣的:(docker搭建各项中间件操作,docker,rabbitmq,容器)