在windows 10上实现运行rabbitmq cluster,含三个节点,并能同时启用rabbitmq_management
插件,实现web管理。rabbitmq版本为:rabbitmq-server-windows-3.6.6
增加
127.0.0.1 node1
127.0.0.1 node2
127.0.0.1 node3
copy rabbitmq-server.bat rabbitmq-server-node1.bat
copy rabbitmq-server.bat rabbitmq-server-node2.bat
copy rabbitmq-server.bat rabbitmq-server-node3.bat
copy rabbitmqctl.bat rabbitmqctl-node1.bat
copy rabbitmqctl.bat rabbitmqctl-node2.bat
copy rabbitmqctl.bat rabbitmqctl-node3.bat
copy rabbitmq-env.bat rabbitmq-env-node1.bat
copy rabbitmq-env.bat rabbitmq-env-node2.bat
copy rabbitmq-env.bat rabbitmq-env-node3.bat
copy rabbitmq-plugins.bat rabbitmq-plugins-node1.bat
copy rabbitmq-plugins.bat rabbitmq-plugins-node2.bat
copy rabbitmq-plugins.bat rabbitmq-plugins-node3.bat
copy rabbitmq.config.example rabbitmq-node1.config
copy rabbitmq.config.example rabbitmq-node2.config
copy rabbitmq.config.example rabbitmq-node3.config
以下只展示node1的修改步骤,node2和node3的RABBITMQ_CONFIG_FILE
,RABBITMQ_NODENAME
, RABBITMQ_NODE_PORT
, RABBITMQ_DIST_PORT
还有listener port
改成不一样的即可。
在开头大概16行左右添加
REM node1
set RABBITMQ_CONFIG_FILE=!RABBITMQ_HOME!\etc\rabbitmq-node1
set RABBITMQ_BASE=!RABBITMQ_HOME!\sbin\rabbitmq-cluster
set RABBITMQ_NODENAME=rabbit1@node1
set RABBITMQ_NODE_PORT=9991
set RABBITMQ_DIST_PORT=16671
确保RABBITMQ_HOME已经定义好;RABBITMQ_BASE把rabbit数据等目录移到sbin目录下,好方便删除重建。
call "%TDP0%\rabbitmq-env.bat" %~n0
-> call "%TDP0%\rabbitmq-env-node1.bat" %~n0
call "%TDP0%\rabbitmq-env.bat" %~n0
-> call "%TDP0%\rabbitmq-env-node1.bat" %~n0
call "%TDP0%\rabbitmq-env.bat" %~n0
-> call "%TDP0%\rabbitmq-env-node1.bat" %~n0
在{rabbitmq_management
下找到
%% {listener, [{port, 12345},
%% {ip, "127.0.0.1"},
%% {ssl, true},
%% {ssl_opts, [{cacertfile, "/path/to/cacert.pem"},
%% {certfile, "/path/to/cert.pem"},
%% {keyfile, "/path/to/key.pem"}]}]},
改成
{listener, [{port, 15671},
{ip, "127.0.0.1"},
{ssl, false}
]}
注意括号的闭合问题
在命令行中sbin
目录下执行
rabbitmq-plugins-node1 enable rabbitmq_management
因为三个节点是共用一个插件开关配置文件(!RABBITMQ_HOME!\sbin\rabbitmq-cluster\enabled_plugins),所以只要执行node1的即可。
rabbitmq-server-node1.bat
rabbitmq-server-node2.bat
rabbitmq-server-node3.bat
rabbitmqctl-node2.bat stop_app
rabbitmqctl-node2.bat reset
rabbitmqctl-node2.bat join_cluster rabbit1@node1
rabbitmqctl-node2.bat start_app
rabbitmqctl-node2.bat cluster_status
rabbitmqctl-node3.bat stop_app
rabbitmqctl-node3.bat reset
rabbitmqctl-node3.bat join_cluster rabbit1@node1 --ram
rabbitmqctl-node3.bat start_app
rabbitmqctl-node3.bat cluster_status
在命令行中执行rabbitmqctl-node2.bat cluster_status
Cluster status of node rabbit3@node3 ...
[{nodes,[{disc,[rabbit2@node2,rabbit1@node1]},{ram,[rabbit3@node3]}]},
{running_nodes,[rabbit1@node1,rabbit2@node2,rabbit3@node3]},
{cluster_name,<<"rabbit1@njun">>},
{partitions,[]},
{alarms,[{rabbit1@node1,[]},{rabbit2@node2,[]},{rabbit3@node3,[]}]}]
访问:http://127.0.0.1:15671/, http://127.0.0.1:15672/, http://127.0.0.1:15673/ 随便一个都可以