建议单机版集群仅作为学习使用,生产环境最好使用多服务器集群来避免单点故障带来的服务不可用,必竟单机版的集是伪集群。
1:准备基础文件、环境变量
设置环境变量:
变量名:RABBITMQ_BASE
变量值:C:\Program Files\RabbitMQ Server(例:这个是安装目录的前半部分,我的安装目录是:C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.5)
准备多节点需要文件
windows环境下对应的bat文件在安装目录下的sbin文件夹下
次用2个节点来建单机集群所以对就的文件命名我们在对应的文件名加node1,node2来区分,这样便于后面的管理更清晰。
分别复制2份下面对应的文件
rabbitmq-server.bat:分别重命名为rabbitmqctl-node1.bat,rabbitmqctl-node2.bat
rabbitmqctl.bat:分别重命名为rabbitmqctl-node1.bat,rabbitmqctl-node2.bat
rabbitmq-env.bat:分别重命名为rabbitmq-env-node1.bat,rabbitmq-env-node2.bat
rabbitmq-plugins.bat:分别重命名为rabbitmq-plugins-node1.bat,rabbitmq-plugins-node2.bat
准备配置文件(配置文件在安装目录的etc文件夹下):
复制rabbitmq.config.example2份,并分别重命名为:rabbitmq-node1.config,rabbitmq-node2.config
2:基础文件准备完毕进行对应文件的修改:
修改rabbitmq-node1.config
在{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, 15673},{ip, "127.0.0.1"},{ssl, false}]}
修改rabbitmq-node2.config
在{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, 15675},{ip, "127.0.0.1"},{ssl, false}]}
修改rabbitmq-env-node1.bat
在开头大概16行左右添加
set RABBITMQ_CONFIG_FILE=!RABBITMQ_HOME!\etc\rabbitmq-node1
set RABBITMQ_BASE=!RABBITMQ_BASE!\rabbitmq-cluster
set [email protected]
set RABBITMQ_NODE_PORT=5673
set RABBITMQ_DIST_PORT=16671
修改rabbitmq-server-node1.bat
call "%TDP0%/rabbitmq-env.bat" %~n0 修改为 call "%TDP0%/rabbitmq-env-node1.bat" %~n0
修改rabbitmqctl-node1.bat
call "%TDP0%/rabbitmq-env.bat" %~n0 修改为 call "%TDP0%/rabbitmq-env-node1.bat" %~n0
修改rabbitmq-plugins-node1.bat
call "%TDP0%/rabbitmq-env.bat" %~n0 修改为 call "%TDP0%/rabbitmq-env-node1.bat" %~n0
修改rabbitmq-env-node2.bat
在开头大概16行左右添加
set RABBITMQ_CONFIG_FILE=!RABBITMQ_HOME!\etc\rabbitmq-node2
set RABBITMQ_BASE=!RABBITMQ_BASE!\rabbitmq-cluster
set [email protected]
set RABBITMQ_NODE_PORT=5675
set RABBITMQ_DIST_PORT=16673
修改rabbitmq-server-node2.bat
call "%TDP0%/rabbitmq-env.bat" %~n0 修改为 call "%TDP0%/rabbitmq-env-node2.bat" %~n0
修改rabbitmqctl-node2.bat
call "%TDP0%/rabbitmq-env.bat" %~n0 修改为 call "%TDP0%/rabbitmq-env-node2.bat" %~n0
修改rabbitmq-plugins-node2.bat
call "%TDP0%/rabbitmq-env.bat" %~n0 修改为 call "%TDP0%/rabbitmq-env-node2.bat" %~n0
3:启动server:
rabbitmq-server-node1.bat
rabbitmq-server-node1.bat
添加节点2到节点1组集群
rabbitmqctl-node2.bat stop_app
rabbitmqctl-node2.bat reset
rabbitmqctl-node2.bat join_cluster [email protected]
rabbitmqctl-node2.bat start_app
cluster_status 查看集群状态
在命令行中执行rabbitmqctl-node2.bat cluster_status
访问http://127.0.0.1:15674/#/,http://127.0.0.1:15675/#/查看
原文地址:https://www.cnblogs.com/songpingyi/p/9938786.html