我正试图使用esp32发布到Ubuntu笔记本电脑上的mosquitto MQTT服务器。我不断遇到错误(不是真正的错误,更多的是一个安全功能(:
1645391623: mosquitto version 2.0.14 starting
1645391623: Using default config.
1645391623: Starting in local only mode. Connections will only be possible from clients running on this machine.
1645391623: Create a configuration file which defines a listener to allow remote access.
1645391623: For more details see https://mosquitto.org/documentation/authentication-methods/
1645391623: Opening ipv4 listen socket on port 1883.
1645391623: Opening ipv6 listen socket on port 1883.
1645391623: mosquitto version 2.0.14 running
1645391674: mosquitto version 2.0.14 terminating
我在栈交换和普通互联网上对此做了很多研究。我似乎需要在mosquitto.conf文件中添加这样的内容:
listener 1883
allow_anonymous true
或
listener 1883 0.0.0.0
allow_anonymous true
我希望可以从本地网络上的外部设备访问代理。以下是原始mosquitto.conf文件的样子:
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
以下是我修改后的文件:
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
listener 1883
allow_anonymous true
无论使用哪个文件,我都会收到相同的消息。
我使用的是Ubuntu 20.04.3 LTS。
我很乐意提供您可能需要的任何其他信息。
如果您能提供任何帮助或建议,我们将不胜感激!
编辑:使用以下命令后:mosquitto -c /etc/mosquitto/mosquitto.conf
我收到以下输出:
mosquitto -c /etc/mosquitto/mosquitto.conf
1645395680: Loading config file /etc/mosquitto/conf.d/mosquito.conf
1645395680: Error: Unable to open log file /var/log/mosquitto/mosquitto.log for writing.
1645395680: Error: Address already in use
或者如果我使用sudo命令:
1645395654: Loading config file /etc/mosquitto/conf.d/mosquito.conf
这是在我使用命令sudo systemctl kill mosquitto.service
试图删除端口错误之后。
解决:我在文件末尾只使用了allow_anonymous true
。我似乎是通过在.conf文件的末尾放入listener 1883
而得到错误的。我也已经开始重新启动服务,而不是试图在控制台中运行它。谢谢你的帮助!
安装mosquito后,将设置以mosquito用户身份运行的systemd服务。我建议你试着作为一个普通用户运行它,你会遇到几个问题
- 如果服务即将耗尽,将失败,因为地址/端口已被服务使用
- 如果您先停止该服务,那么它将无法写入日志文件,因为该文件为mosquitto用户所有
因此,最好的测试方法是更新配置文件,然后重新启动服务(sudo service mosquitto restart
(并使用journalctl -f -u mosquitto.service
跟踪日志