1.消息队列emqtt
2.x版本之前都叫emqtt,3.x之后版本都叫emqx
下载地址:https://www.emqx.io/cn/downloads#broker
安装部署
1.下载软件包后上传到服务器,解压
unzip emqttd-centos7-v2.0.zip
2.以调试模式启动,检查服务是否正常
[root@localhost emqttd]# cd emqttd && ./bin/emqttd console Exec: /root/emqttd/erts-9.0/bin/erlexec -boot /root/emqttd/releases/2.3.7/emqttd -mode embedded -boot_var ERTS_LIB_DIR /root/emqttd/erts-9.0/../lib -mnesia dir "/root/emqttd/data/mnesia/emq@127.0.0.1" -config /root/emqttd/data/configs/app.2020.05.23.23.38.19.config -args_file /root/emqttd/data/configs/vm.2020.05.23.23.38.19.args -vm_args /root/emqttd/data/configs/vm.2020.05.23.23.38.19.args -- console Root: /root/emqttd /root/emqttd Erlang/OTP 20 [erts-9.0] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:32] [hipe] [kernel-poll:true] starting emqttd on node 'emq@127.0.0.1' emqttd ctl is starting...[ok] emqttd hook is starting...[ok] emqttd router is starting...[ok] emqttd pubsub is starting...[ok] emqttd stats is starting...[ok] emqttd metrics is starting...[ok] emqttd pooler is starting...[ok] emqttd trace is starting...[ok] emqttd client manager is starting...[ok] emqttd session manager is starting...[ok] emqttd session supervisor is starting...[ok] emqttd wsclient supervisor is starting...[ok] emqttd broker is starting...[ok] emqttd alarm is starting...[ok] emqttd mod supervisor is starting...[ok] emqttd bridge supervisor is starting...[ok] emqttd access control is starting...[ok] emqttd system monitor is starting...[ok] emqttd 2.3.7 is running now Eshell V9.0 (abort with ^G) (emq@127.0.0.1)1> Load emq_mod_presence module successfully. dashboard:http listen on 0.0.0.0:18083 with 4 acceptors. mqtt:tcp listen on 127.0.0.1:11883 with 4 acceptors. mqtt:tcp listen on 0.0.0.0:1883 with 16 acceptors. mqtt:ws listen on 0.0.0.0:8083 with 4 acceptors. mqtt:ssl listen on 0.0.0.0:8883 with 16 acceptors. mqtt:wss listen on 0.0.0.0:8084 with 4 acceptors. mqtt:api listen on 0.0.0.0:8080 with 4 acceptors.
3.查看服务启动状态
[root@localhost ~]# ./emqttd/bin/emqttd_ctl status Node 'emq@127.0.0.1' is started emqttd 2.3.7 is running
4.如果服务启动正常,更改为后台启动,启动错误日志将输出到log目录下
./bin/emqttd start
5.EMQ 消息服务器提供了状态监控 URL
http://localhost:8080/status
6.控制台 URL: http://localhost:18083/ ,默认登录用户名: admin, 密码: public。
7.停止服务器:
./bin/emqttd stop
调试配置
1.EMQ 2.0 消息服务器默认占用的 TCP 端口包括
1883 #MQTT 协议端口 8883 #MQTT/SSL 端口 8083 #MQTT/WebSocket 端口 8084 #MQTT/WebSocket/SSL监听端口 8080 #HTTP API 端口 18083 #Dashboard 管理控制台端口 11883 #MQTT/TCP内部协议监听端口 4369 #emq集群通信端口 6369 #erlang集群间通信端口
2.可通过 etc/emq.conf 配置文件的 ‘listener’ 段落设置(18083是由emq_dashboard插件控制,配置文件在etc/plugins/emq_dashboard.conf)
## TCP Listener: 1883, 127.0.0.1:1883, ::1:1883 listener.tcp.external = 0.0.0.0:1883 ## SSL Listener: 8883, 127.0.0.1:8883, ::1:8883 listener.ssl.external = 8883 ## External MQTT/WebSocket Listener listener.ws.external = 8083 ## HTTP Management API Listener listener.api.mgmt = 127.0.0.1:8080
3.EMQ 消息服务器主要配置文件
etc/emq.conf #EMQ 2.0 消息服务器配置文件 etc/acl.conf #EMQ 2.0 默认ACL规则配置文件 etc/plugins/*.conf #EMQ 2.0 各类插件配置文件
4.主配置文件
#集群名称 cluster.name = emqttd@192.168.1.1 #自动发现策略 #manual 手工命令创建集群 #static 静态节点列表自动集群 #mcast UDP 组播方式自动集群 #dns DNS A 记录自动集群 #etcd 通过 etcd 自动集群 #k8s Kubernetes 服务自动集群 cluster.discovery = manual #启用集群自愈 cluster.autoheal = on #自动清除宕机节点 cluster.autoclean = 5m #Erlang 虚拟机允许的最大进程数,一个 MQTT 连接会消耗2个 Erlang 进程,所以参数值 > 最大连接数 * 2 node.process_limit 256000 #Erlang 虚拟机允许的最大 Port 数量,一个 MQTT 连接消耗1个 Port,所以参数值 > 最大连接数 node.max_ports 65536 #Erlang 分布节点间通信使用 TCP 连接端口范围。注: 节点间如有防火墙,需要配置该端口段 node.dist_listen_min 6369 node.dist_listen_max 6379 #日志参数 log.console = console log.console.level = error log.error.file = log/error.log log.crash = on log.crash.file = log/crash.log log.syslog = on log.syslog.level = error #ClientId 最大允许长度 mqtt.max_clientid_len = 1024 #MQTT 最大报文尺寸 mqtt.max_packet_size = 64KB #MQTT 客户端最大允许闲置时间(Socket 连接建立,但未收到 CONNECT 报文): mqtt.client.idle_timeout = 30 #启用客户端连接统计 mqtt.client.enable_stats = off #强制 GC 设置 mqtt.conn.force_gc_count = 100 #允许任意客户端登录 mqtt.allow_anonymous = true #默认访问控制(ACL)文件 mqtt.acl_nomatch = allow mqtt.acl_file = etc/acl.conf mqtt.session.upgrade_qos = off mqtt.session.max_inflight = 32 mqtt.session.retry_interval = 20s mqtt.session.max_awaiting_rel = 100 mqtt.session.await_rel_timeout = 20s mqtt.session.enable_stats = off mqtt.session.expiry_interval = 2h #MQTT 消息队列参数设置 #队列类型。simple: 简单队列,priority: 优先级队列 mqtt.mqueue.type = simple #主题(Topic)队列优先级设置 mqtt.mqueue.priority = topic/1=10,topic/2=8 #队列长度, infinity 表示不限制 mqtt.mqueue.max_length = 0 #解除告警水位线 mqtt.mqueue.low_watermark = 20% #队列满告警水位线 mqtt.mqueue.high_watermark = 60% #是否缓存 QoS0 消息 mqtt.mqueue.store_qos0 = true #系统发布 $SYS 消息周期 mqtt.broker.sys_interval = 60s #发布订阅(PubSub)参数设置 mqtt.pubsub.pool_size = 8 mqtt.pubsub.by_clientid = true mqtt.pubsub.async = true #桥接(Bridge)参数设置 mqtt.bridge.max_queue_len = 10000 mqtt.bridge.ping_down_interval = 1s #插件(Plugin) 配置目录设置 mqtt.plugins.etc_dir = etc/plugins/ mqtt.plugins.loaded_file = data/loaded_plugins #MQTT/TCP 监听器 - 1883 listener.tcp.external = 0.0.0.0:1883 listener.tcp.external.acceptors = 16 listener.tcp.external.max_clients = 102400 listener.tcp.external.access.2 = allow all listener.tcp.external.backlog = 1024 listener.tcp.external.buffer = 4KB listener.tcp.external.nodelay = true listener.tcp.internal = 127.0.0.1:11883 listener.tcp.internal.acceptors = 16 listener.tcp.internal.max_clients = 102400 listener.tcp.internal.backlog = 512 listener.tcp.internal.tune_buffer = on listener.tcp.internal.buffer = 1MB listener.tcp.internal.recbuf = 4KB listener.tcp.internal.sndbuf = 1MB listener.tcp.internal.nodelay = true #MQTT/SSL 监听器 - 8883 listener.ssl.external = 8883 listener.ssl.external.acceptors = 16 listener.ssl.external.max_clients = 1024 listener.ssl.external.access.1 = allow all listener.ssl.external.handshake_timeout = 15 listener.ssl.external.keyfile = etc/certs/key.pem listener.ssl.external.certfile = etc/certs/cert.pem #MQTT/WebSocket 监听器 - 8083 listener.ws.external = 8083 listener.ws.external.acceptors = 4 listener.ws.external.max_clients = 64 listener.ws.external.access.1 = allow all #MQTT/WebSocket/SSL 监听器 - 8084 listener.wss.external = 8084 listener.wss.external.acceptors = 4 listener.wss.external.max_clients = 64 listener.wss.external.access.1 = allow all listener.wss.external.handshake_timeout = 15s listener.wss.external.keyfile = {{ platform_etc_dir }}/certs/key.pem listener.wss.external.certfile = {{ platform_etc_dir }}/certs/cert.pem #HTTP API 监听器 - 8080 listener.api.mgmt = 127.0.0.1:8080 listener.api.mgmt.acceptors = 4 listener.api.mgmt.max_clients = 64 listener.api.mgmt.access.1 = allow all #Erlang 虚拟机监控设置 sysmon.long_gc = false sysmon.long_schedule = 240 sysmon.large_heap = 8MB sysmon.busy_port = false sysmon.busy_dist_port = true
分布式集群
- 默认方式为手动加入集群,配置位于
cluster.discovery = manual
- 以三台机器为例,每台主机更改配置文件中的node.name
#节点1 node.name = emq@192.168.2.4 #节点2 node.name = emq@192.168.2.6 #节点3 node.name = emq@192.168.2.100
- 分别启动三个节点
#节点1,2,3都是这个命令 ./bin/emqttd start
- 加入集群
#只需要在其中额外两台节点添加就可以 ./bin/emqttd_ctl cluster join emq@192.168.2.100
- 查看集群节点状态
#任意一台都可以查看 ./bin/emqttd_ctl cluster status Cluster status: [{running_nodes,['emq@192.168.2.4','emq@192.168.2.100', 'emq@192.168.2.6']}]
- 节点退出集群
#主动离开方式 ./bin/emqttd_ctl cluster leave #被动离开方式,被踢出去 ./bin/emqttd_ctl cluster remove emq@192.168.1.1
上面是手动方式创建的集群,下面在配置文件中规定好集群,改好配置,直接启动就好了
cluster.discovery = static ##-------------------------------------------------------------------- ## Cluster with static node list cluster.static.seeds = emq1@127.0.0.1,ekka2@127.0.0.1
初学linux,每学到一点东西就写一点,如有不对的地方,恳请包涵!