本文使用docker进行安装,因此安装之前需要已经安装了docker
拉取镜像
docker pull emqx/nanomq:latest
相关配置及密码认证
创建目录/usr/local/nanomq/conf以及配置文件nanomq.conf、pwd.conf
# #====================================================================
# # MQTT Broker
# #====================================================================
mqtt {
property_size = 32
max_packet_size = 10KB
max_mqueue_len = 2048
retry_interval = 10s
keepalive_multiplier = 1.25
# Three of below, unsupported now
max_inflight_window = 2048
max_awaiting_rel = 10s
await_rel_timeout = 10s
}
listeners.tcp {
bind = "0.0.0.0:1883"
}
auth {
allow_anonymous = false # 允许匿名登录
no_match = allow # 没有 ACL 规则匹配情况下的默认操作
deny_action = ignore # ACL 检查拒绝情况下的默认操作
cache = {
max_size = 32 # 客户端可以缓存的最大 ACL 条目数量
ttl = 1m # ACL 规则缓存有效时间
}
password = {include "/etc/nanomq_pwd.conf"} # 密码存储文件路径
# acl = {include "/etc/nanomq_acl.conf"} # ACL 配置文件路径
}
admin: public
client: public
通过 Docker 运行NanoMQ
docker run -d -p 1883:1883 \
-v /usr/local/nanomq/conf/nanomq.conf:/etc/nanomq.conf\
-v /usr/local/nanomq/conf/pwd.conf:/etc/nanomq_pwd.conf\
--name nanomq emqx/nanomq:latest
验证
下载MQTTX工具,验证连接以及消息的发布、订阅