本文使用docker进行安装,因此安装之前需要已经安装了docker
拉取镜像
docker pull emqx/nanomq:latest
相关配置及密码认证
创建目录/usr/local/nanomq/conf以及配置文件nanomq.conf、pwd.conf
# #====================================================================
# # MQTT Broker
# #====================================================================
mqtt {property_size = 32max_packet_size = 10KBmax_mqueue_len = 2048retry_interval = 10skeepalive_multiplier = 1.25# Three of below, unsupported nowmax_inflight_window = 2048max_awaiting_rel = 10sawait_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工具,验证连接以及消息的发布、订阅