RabbitMQ-Windows单机集群搭建

时间:2022-04-05 22:41:25

1、先安装Erlang http://www.erlang.org/downloads,安装完成后,设置环境变量:

  变量名:ERLANG_HOME

  变量值:D:\Program Files\erl9.0

RabbitMQ-Windows单机集群搭建

2、安装RabbitMQ  http://www.rabbitmq.com/install-windows.html;安装过程中会自动启动RabbitMQ服务

 安装之前,先设置环境变量:

  变量名:RABBITMQ_BASE

  变量值:D:\01-Config\RabbitMQServer

RabbitMQ-Windows单机集群搭建

RabbitMQ-Windows单机集群搭建

3、此时,RabbitMQ安装后,会出现一个节点rabbit@主机名,并可以通过http://localhost:15672/ 进行访问(需要先启用监控插件,参考第7小点)

RabbitMQ-Windows单机集群搭建

4、修改Hosts文件,增加  127.0.0.1 ClusterNode1

RabbitMQ-Windows单机集群搭建

5、复制文件

  5.1、RabbitMQ安装目录,sbin中的脚本文件复制并重新命名(与节点名一致,方便管理)

    rabbitmqctl-ClusterNode1.bat    

    rabbitmq-env-ClusterNode1.bat

    rabbitmq-plugins-ClusterNode1.bat

    rabbitmq-server-ClusterNode1.bat

    RabbitMQ-Windows单机集群搭建

  5.2、etc目录下复制配置文件,并修改配置文件名称(与节点名称一致,方便管理)

    复制rabbitmq.config.example文件,并重新命名为:rabbitmq-ClusterNode1.config

    RabbitMQ-Windows单机集群搭建

6、修改文件

  6.1、rabbitmq-env-ClusterNode1.bat  脚本文件修改,16行左右添加:

    set RABBITMQ_CONFIG_FILE=!RABBITMQ_HOME!\etc\rabbitmq-ClusterNode1
    set RABBITMQ_BASE=!RABBITMQ_BASE!\rabbitmq-cluster
    set RABBITMQ_NODENAME=rabbit1@ClusterNode1
    set RABBITMQ_NODE_PORT=5673
    set RABBITMQ_DIST_PORT=15673

    RabbitMQ-Windows单机集群搭建

  6.2、rabbitmqctl-ClusterNode1.bat  脚本文件修改:

    call "!TDP0!\rabbitmq-env.bat" %~n0  -》  call "!TDP0!\rabbitmq-env-ClusterNode1.bat" %~n0

  6.3、rabbitmq-plugins-ClusterNode1.bat  脚本文件修改:

    call "!TDP0!\rabbitmq-env.bat" %~n0  -》  call "!TDP0!\rabbitmq-env-ClusterNode1.bat" %~n0

  6.4、rabbitmq-server-ClusterNode1.bat  脚本文件修改:

    call "!TDP0!\rabbitmq-env.bat" %~n0  -》  call "!TDP0!\rabbitmq-env-ClusterNode1.bat" %~n0

  6.5、rabbitmq-ClusterNode1.config  配置文件修改,添加红色区域,port端口号为监控插件访问的端口(http://localhost:15673/#/)

    RabbitMQ-Windows单机集群搭建

7、启用插件,进入RabbitMQ安装目录,执行命令:

rabbitmq-plugins enable rabbitmq_management

检查节点rabbit1@ClusterNode1,指定的目录下面是否存在相关插件文件(下面第二张图),若不存在,则执行:rabbitmq-plugins-ClusterNode1 enable rabbitmq_management

RabbitMQ-Windows单机集群搭建

RabbitMQ-Windows单机集群搭建

8、启动节点,执行相关命令:

rabbitmq-server-ClusterNode1 -detached

RabbitMQ-Windows单机集群搭建

9、将节点rabbit@ClusterNode1,添加到rabbit@WK-Dream中,组成集群

rabbitmqctl-ClusterNode1 stop_app

rabbitmqctl-ClusterNode1 join_cluster rabbit@WK-Dream

rabbitmqctl-ClusterNode1 start_app

RabbitMQ-Windows单机集群搭建

10、查看集群状态

rabbitmqctl cluster_status

RabbitMQ-Windows单机集群搭建

11、通过监控页面,查看节点信息

RabbitMQ-Windows单机集群搭建