Erlang/OTP 語言平台的分布式程式,由分布互聯的 Erlang 運作系統組成,每個 Erlang 運作系統被稱為節點(Node),節點(Node) 間通過 TCP 互聯,消息傳遞的方式通信:
Node1 | -------- | Node2 |
---|---|---|
\ / | ||
\ / | ||
/ \ | ||
/ \ |
EMQ 節點叢集使用的 TCP 端口:
4369 叢集節點發現端口 6369 叢集節點控制通道
防火牆根據使用的 MQTT 接入方式,開啟上述端口的通路權限。
叢集節點間如有防護牆,需開啟上述 TCP 端口互訪權限。
如果叢集節點間存在防火牆,防火牆需要開啟 4369 端口和一個 TCP 端口段。4369 由 epmd 端口映射服務使用,TCP 端口段用于節點間建立連接配接與通信。
防火牆設定後,EMQ 需要配置相同的端口段,emqttd/etc/emq.conf 檔案:
Distributed node port range
node.dist_listen_min = 6369
node.dist_listen_max = 7369
EMQ叢集:
rpm安裝:
安裝依賴
yum -y install yum install lksctp-tools
安裝包
yum -y install emqttd-centos7-v2.3.11-1.el7.centos.x86_64.rpm
啟動
systemctl start emqttd.service
配置叢集目錄:vim /data/emq/emqx/etc/emqx.conf
cluster.discovery = manual
#日志相關配置
Crash dump log file. 故障轉儲日志檔案
node.crash_dump = /data/emq/emq-cluster/logs/crash.dump
Sets the log dir. 主日志路徑
log.dir = /data/emq/emq-cluster/logs/
The file where error logs will be writed to. 錯誤日志
log.error.file = /data/emq/emq-cluster/logs/error.log
The file for crash log. 故障日志的檔案
log.crash.file = /data/emq/emq-cluster/logs/crash.log
啟動emq:./bin/emqx start
emqx 3.0.1 is started successfully!
配置叢集:vim /etc/emqttd/emq.conf
cluster.name = emqcl
cluster.discovery = manual
node.name = [email protected]
node.proto_dist = inet_tcp
node.dist_listen_min = 6369
node.dist_listen_max = 7369
listener.tcp.internal = 0.0.0.0:11883 内部mqtt/tcp協定偵聽器的IP位址和端口
開啟防火牆通路權限
firewall-cmd --zone=public --add-port={1883/tcp,8080/tcp,18083/tcp,4369/tcp,8883/tcp.8083/tcp,8084/tcp,6370/tcp} --permanent
firewall-cmd --reload
重新開機EMQ服務
systemctl start emqttd.service
[[email protected] ~]# netstat -tnlp

叢集操作指令:
節點加入叢集
emqttd_ctl cluster join [email protected]
檢視叢集的狀态
emqttd_ctl cluster help
[[email protected] ~]# emqttd_ctl cluster status
Cluster status: [{running_nodes,['[email protected]',br/>'[email protected]',
'[email protected]']}]
節點退出叢集
主動退出:emqttd_ctl cluster leave
Leave the cluster successfully.
Cluster status: [{running_nodes,['[email protected]']}]
從叢集中删除: emqttd_ctl cluster force-leave [email protected]
Remove the node from cluster successfully.
Cluster status: [{running_nodes,['[email protected]',
'[email protected]']}]
轉載于:https://blog.51cto.com/13576471/2359149