cluster 命令

cluster 命令集群多个 EMQ X 消息服务器节点(进程):

cluster join <Node>加入集群
cluster leave离开集群
cluster force-leave <Node>从集群删除节点
cluster status查询集群状态

cluster 命令集群本机两个 EMQ X 节点示例:

目录节点名MQTT 端口
emqx1emqx1@127.0.0.11883
emqx2emqx2@127.0.0.12883

启动 emqx1 :

  1. $ cd emqx1 && ./bin/emqx start

启动 emqx2 :

  1. $ cd emqx2 && ./bin/emqx start

emqx2 节点与 emqx1 集群,emqx2 目录下:

  1. $ ./bin/emqx_ctl cluster join emqx1@127.0.0.1
  2. Join the cluster successfully.
  3. Cluster status: [{running_nodes,['emqx1@127.0.0.1','emqx2@127.0.0.1']}]

任意节点目录下查询集群状态:

  1. $ ./bin/emqx_ctl cluster status
  2. Cluster status: [{running_nodes,['emqx2@127.0.0.1','emqx1@127.0.0.1']}]

集群消息路由测试:

  1. # emqx1节点上订阅x
  2. $ mosquitto_sub -t x -q 1 -p 1883
  3. # emqx2节点上向x发布消息
  4. $ mosquitto_pub -t x -q 1 -p 2883 -m hello

emqx2 节点离开集群:

  1. $ cd emqx2 && ./bin/emqx_ctl cluster leave

emqx1 节点下删除 emqx2:

  1. $ cd emqx1 && ./bin/emqx_ctl cluster force-leave emqx2@127.0.0.1