cluster 命令
cluster 命令集群多个 EMQ X 消息服务器节点(进程):
cluster join <Node> | 加入集群 |
---|---|
cluster leave | 离开集群 |
cluster force-leave <Node> | 从集群删除节点 |
cluster status | 查询集群状态 |
cluster 命令集群本机两个 EMQ X 节点示例:
目录 | 节点名 | MQTT 端口 |
---|---|---|
emqx1 | emqx1@127.0.0.1 | 1883 |
emqx2 | emqx2@127.0.0.1 | 2883 |
启动 emqx1 :
$ cd emqx1 && ./bin/emqx start
启动 emqx2 :
$ cd emqx2 && ./bin/emqx start
emqx2 节点与 emqx1 集群,emqx2 目录下:
$ ./bin/emqx_ctl cluster join emqx1@127.0.0.1
Join the cluster successfully.
Cluster status: [{running_nodes,['emqx1@127.0.0.1','emqx2@127.0.0.1']}]
任意节点目录下查询集群状态:
$ ./bin/emqx_ctl cluster status
Cluster status: [{running_nodes,['emqx2@127.0.0.1','emqx1@127.0.0.1']}]
集群消息路由测试:
# emqx1节点上订阅x
$ mosquitto_sub -t x -q 1 -p 1883
# emqx2节点上向x发布消息
$ mosquitto_pub -t x -q 1 -p 2883 -m hello
emqx2 节点离开集群:
$ cd emqx2 && ./bin/emqx_ctl cluster leave
emqx1 节点下删除 emqx2:
$ cd emqx1 && ./bin/emqx_ctl cluster force-leave emqx2@127.0.0.1