创建集群

先把所有的插件都禁用先,避免因插件的端口问题导致集群启动不了.

默认插件监听端口: rabbit_stomp_listenersup:::61613 rabbit_mqtt_listenersup:::1883 rabbitmq_management:::15672

rabbitmq-plugins -n node1@localhost list
rabbitmq-plugins -n node1@localhost disable rabbitmq_management
rabbitmq-plugins -n node1@localhost disable rabbitmq_mqtt
rabbitmq-plugins -n node1@localhost disable rabbitmq_stomp

集群节点

启动集群节点

````bash RABBITMQ_NODE_PORT=5672 RABBITMQ_NODENAME=master /ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmq-server -detached


#### 加入一个磁盘集群节点

```bash
-- 这样子,默认的节点名就是 node1@你的机器名 
RABBITMQ_NODE_PORT=5673 RABBITMQ_NODENAME=node1 /ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmq-server -detached

/ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n node1 stop_app
/ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n node1 reset

-- 第二个参数 master@sky-linux 是要填写完整的节点名
/ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n node1 join_cluster master@sky-linux

-- 启动node1节点
/ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n node1 start_app

这时查看集群状态

/ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n master  cluster_status
Cluster status of node 'master@sky-linux' ...
[{nodes,[{disc,['master@sky-linux','node1@sky-linux']}]},
 {running_nodes,['node1@sky-linux','master@sky-linux']},
 {cluster_name,<<"master@sky-linux">>},
 {partitions,[]},
 {alarms,[{'node1@sky-linux',[]},{'master@sky-linux',[]}]}

加入一个内存集群节点

RABBITMQ_NODE_PORT=5674 RABBITMQ_NODENAME=node2 /ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmq-server -detached

/ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n node2 stop_app
/ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n node2 reset

-- 加入集群
/ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n node2 join_cluster master@sky-linux --ram

-- 启动节点node2
/ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n node2 start_app

这时再查看集群状态

╭─sky@sky-linux /ihome/rabbitmq/rabbitmq_server-3.6.1  
╰─➤  /ihome/rabbitmq/rabbitmq_server-3.6.1/sbin/rabbitmqctl -n master cluster_status
Cluster status of node 'master@sky-linux' ...
[{nodes,[{disc,['master@sky-linux','node1@sky-linux']},
         {ram,['node2@sky-linux']}]},
 {running_nodes,['node2@sky-linux','node1@sky-linux','master@sky-linux']},
 {cluster_name,<<"master@sky-linux">>},
 {partitions,[]},
 {alarms,[{'node2@sky-linux',[]},
          {'node1@sky-linux',[]},
          {'master@sky-linux',[]}]}]

可以看到ram, ['node2@sky-linux']表示它就是内存内存节点并且已经是running了.

到这里,就已经完成了2个磁盘节点+1个内存节点的单机集群已经OK了.