本实例采用“静态节点列表自动集群”
官方文档: http://www.emqtt.com/docs/v2/cluster.html
两台云端服务器:
A服务器:39.10.20.14
B服务器:10.14.64.45
修改A服务器配置文件
## Cluster discovery strategy: manual | static | mcast | dns | etcd | k8s
cluster.discovery = static
## Cluster Autoheal: on | off
cluster.autoheal = on
## Clean down node of the cluster
cluster.autoclean = 5m
##--------------------------------------------------------------------
## Cluster with static node list
## cluster.static.seeds = emq1@127.0.0.1,emq2@127.0.0.1
cluster.static.seeds = emq@39.10.20.14,emq@10.14.64.45
将node.name需要修改成本机的IP地址,默认的是127.0.0.1
## node.name = emq@127.0.0.1
node.name = emq@39.10.20.14
修改B服务器配置文件
## node.name = emq@127.0.0.1
node.name = emq@10.14.64.45
开启4369端口
4369由epmd端口映射服务使用,TCP端口段用于节点间建立连接与通信
在/etc/sysconfig/iptables配置文件中添加
-A INPUT -p tcp -m tcp --dport 4369 -j ACCEPT
防火墙设置后,EMQ需要配置相同的端口段,emqttd/etc/emq.conf 文件:
## Distributed node port range
node.dist_listen_min = 6369
node.dist_listen_max = 7369
重启两台服务器的EMQTT服务,在任意节点上查询集群状态:
[root@home ~]# ./sbin/emqttd_ctl cluster status
Cluster status: [{running_nodes,['emq@39.10.20.14','emq@10.14.64.45']}]
总结
注意4369端口号对外开启,node.name的名称需要修改与实际的IP地址,默认为127.0.0.1
手动加入方法
#添加集群主机
[root@home ~]# ./sbin/emqttd_ctl cluster join emq@39.10.20.14
#删除集群主机
[root@home ~]# ./sbin/emqttd_ctl cluster force-leave emq@39.10.20.14
Remove the node from cluster successfully.
Cluster status: [{running_nodes,['emq@10.14.64.45']}]
#说明
[root@home ~]# ./sbin/emqttd_ctl cluster remove emq@39.108.208.149
cluster join <Node> # Join the cluster
cluster leave # Leave the cluster
cluster force-leave <Node> # Force the node leave from cluster
cluster status # Cluster status