Mosquitto创建MQTT服务器提示Starting in local only mode的解决办法
一、问题现象
使用新下载的Mosquitto创建MQTT服务器提示Starting in local only mode. Connections will only be possible from clients running on this machine.
测试发现服务器只能接入本机的客户端,而其他设备上的客户端在连接时直接被重置了。
二、原因分析
随后查阅了一下Mosquitto的更新记录,原来在其2.0.0
大版本更新后如果不加载配件文件则使用回环接口(仅可用于本地Socket通信)。
Breaking changes
- When the Mosquitto broker is run without configuring any listeners it will now bind to the loopback interfaces 127.0.0.1 and/or ::1. This means that only connections from the local host will be possible.
Running the broker as
mosquitto
ormosquitto -p 1883
will bind to the loopback interface.Running the broker with a configuration file with no listeners configured will bind to the loopback interface with port 1883.
Running the broker with a listener defined will bind by default to
0.0.0.0
/::
and so will be accessible from any interface. It is still possible to bind to a specific address/interface.
Mosquitto更新记录: https://mosquitto.org/blog/2020/12/version-2-0-0-released
三、解决方法
先修改软件安装目录中的配置文件mosquitto.conf
然后加载配置文件来启动服务器。
-
配置端口号,编辑
mosquitto.conf
,搜索listener
去掉行首的#
并加上端口号,示例端口为1883# On systems that support Unix Domain Sockets, it is also possible
# to create a # Unix socket rather than opening a TCP socket. In
# this case, the port number should be set to 0 and a unix socket
# path must be provided, e.g.
# listener 0 /tmp/mosquitto.sock
#
# listener port-number [ip address/host name/unix socket path]listener 1883
-
启用匿名访问,若不允许
匿名访问
则只有添加客户端鉴权信息才能接入。为简化测试我们启用匿名访问:将mosquitto.conf
里的allow_anonymous
选项改为true
并保存# Boolean value that determines whether clients that connect
# without providing a username are allowed to connect. If set to
# false then a password file should be created (see the
# password_file option) to control authenticated client access.
#
# Defaults to false, unless there are no listeners defined in the configuration
# file, in which case it is set to true, but connections are only allowed from
# the local machine.
allow_anonymous true
-
加载配置文件启动服务器测试,执行命令
mosquitto.exe -c mosquitto.conf -v
,此时LOG上已经没了Starting in local only mode
且非本地客户端可以正常接入了
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2017-12-09 Windows系统重装工具 WinToHDD Enterprise v2.8 企业破解版
2017-12-09 冰点文库下载器
2015-12-09 WebAPI通过multipart/form-data方式同时上传文件以及数据(含HttpClient上传Demo)