手动配置管理集群

假设部署两台服务器 s1.emqx.io, s2.emqx.io 上部署集群:

节点名主机名(FQDN)IP 地址
emqx@s1.emqx.io 或 emqx@192.168.0.10s1.emqx.io192.168.0.10
emqx@s2.emqx.io 或 emqx@192.168.0.20s2.emqx.io192.168.0.20

Warning

节点名格式: Name@Host , Host 必须是 IP 地址或 FQDN(主机名.域名)

emqx@s1.emqx.io 节点设置

emqx/etc/emqx.conf:

  1. node.name = emqx@s1.emqx.io
  2. node.name = emqx@192.168.0.10

也可通过环境变量:

  1. export EMQX_NODE_NAME=emqx@s1.emqx.io && ./bin/emqx start

Warning

节点启动加入集群后,节点名称不能变更。

emqx@s2.emqx.io 节点设置

emqx/etc/emqx.conf:

  1. node.name = emqx@s2.emqx.io
  2. node.name = emqx@192.168.0.20

节点加入集群

启动两台节点后,emqx@s2.emqx.io 上执行:

  1. $ ./bin/emqx_ctl cluster join emqx@s1.emqx.io
  2. Join the cluster successfully.
  3. Cluster status: [{running_nodes,['emqx@s1.emqx.io','emqx@s2.emqx.io']}]

或,emqx@s1.emqx.io 上执行:

  1. $ ./bin/emqx_ctl cluster join emqx@s2.emqx.io
  2. Join the cluster successfully.
  3. Cluster status: [{running_nodes,['emqx@s1.emqx.io','emqx@s2.emqx.io']}]

任意节点上查询集群状态:

  1. $ ./bin/emqx_ctl cluster status
  2. Cluster status: [{running_nodes,['emqx@s1.emqx.io','emqx@s2.emqx.io']}]

节点退出集群

节点退出集群,两种方式:

  1. leave: 本节点退出集群
  2. force-leave: 从集群删除其他节点

emqx@s2.emqx.io 主动退出集群:

  1. $ ./bin/emqx_ctl cluster leave

或 emqx@s1.emqx.io 节点上,从集群删除 emqx@s2.emqx.io 节点:

  1. $ ./bin/emqx_ctl cluster force-leave emqx@s2.emqx.io