如何禁用 mosquitto MQTT local-only 模式并监听所有 IP 地址
使用默认配置文件启动 Mosquitto 时,你会看到类似这样的日志消息
mosquitto_local_only_log.txt
mosquitto_1 | 1637858580: Starting in local only mode. Connections will only be possible from clients running on this machine.表示 mosquitto MQTT 代理只在 127.0.0.1 上监听,无法通过网络访问。
为了修复此问题,你可以简单地绑定到所有 IP 地址,使用
mosquitto_bind_listener.conf
bind_address 0.0.0.0
listener 1883在 mosquitto.conf 中
完整的 mosquitto.conf 示例
mosquitto.conf
persistence true
persistence_location /mosquitto/data/
log_dest file /mosquitto/log/mosquitto.log
listener 1883
## 认证 ##
allow_anonymous false
password_file /mosquitto/conf/mosquitto.conf有关如何使用此配置设置 mosquitto MQTT 代理的更多详细信息,请参见我们之前的文章如何使用 docker-compose 设置独立 mosquitto MQTT 代理。
**如果 mosquitto 仍然打印 local only 消息,即使你的配置文件中有 listener 1883,请检查 mosquitto 是否使用了正确的配置文件。**在我的情况下,我拼错了配置文件路径(conf 而不是 config),因此 mosquitto 使用了默认配置文件而不是我的配置文件,从而忽略了我放在配置文件中的所有语句。
Check out similar posts by category:
MQTT, Networking
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow