两台服务器 s1.emqx.io, s2.emqx.io 上部署 EMQ X 集群:
节点名 主机名 (FQDN) IP 地址
emqx@s1.emqx.io 或 emqx@192.168.78.131 s1.emqx.io 192.168.78.131
emqx@s2.emqx.io 或 emqx@192.168.0.130 s2.emqx.io 192.168.78.130
emqx/etc/emqx.conf:
node.name = emqx@s1.emqx.io
# 或
node.name = emqx@192.168.78.131
注意: 节点启动加入集群后,节点名称不能变更。
emqx/etc/emqx.conf:
node.name = emqx@s2.emqx.io
# 或
node.name = emqx@192.168.78.130
注意: 节点启动加入集群后,节点名称不能变更。
启动两台节点后,在 s2.emqx.io 上执行:
$ ./bin/emqx_ctl cluster join emqx@192.168.78.131
执行命令后,加入集群failed
Failed to join the cluster: {
node_down,'[email protected]'}
加入失败原因是没有开放4370端口
开放4370端口:(所有节点开发4370端口)
firewall-cmd --zone=public --add-port=4370/tcp --permanent
重新启动防火墙:
firewall-cmd --reload
然后重新执行:
$ ./bin/emqx_ctl cluster join emqx@192.168.78.131
Join the cluster successfully.
Cluster status: #{
running_nodes =>
['[email protected]','[email protected]'],
或者在 s1.emqx.io 上执行:
$ ./bin/emqx_ctl cluster join emqx@192.168.78.130
Join the cluster successfully.
Cluster status: #{
running_nodes =>
['[email protected]','[email protected]'],
在任意节点上查询集群状态:
./bin/emqx_ctl cluster status
{
running_nodes =>
['[email protected]','[email protected]'],
stopped_nodes => []}
ws://192.168.78.130:8083/mqtt
ws://192.168.78.131:8083/mqtt
mqtt://192.168.78.130:1883
同时订阅一个主题例如all 然后选择一端发送消息,检查另一端是否能接收到消息
测试结果两个节点(s1.emqx.io和s2.emqx.io)之间无法互相通信
将 rpc.port_discovery = stateless改为
rpc.port_discovery = manual(手动命令创建集群)
firewall-cmd --zone=public --add-port=5369/tcp --permanent
firewall-cmd --reload
emqx restart
接下来可通过nginx配置负载均衡策略,进而合理分配连接
详细配置:nginx负载均衡配置分配连接