【发布时间】:2021-12-30 21:37:37
【问题描述】:
我在作为代理和客户端的同一 Raspberry Pi Bullseye (3 A+) 上运行 MQTT 服务器 mosquitto 版本 2.0.11。我有代码工作,但明白需要修改 .conf 文件才能让事情正常工作。我一定还是不明白,因为这是我的文件:
# I had pid_file /run/mosquitto/mosquitto.pid below, but changed this when docs suggested below should be included if running automatically when device boots, which it will be.
pid_file /var/run/mosquitto/mosquitto.pid
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
现在当我尝试像这样运行 mosquitto 时:
mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf
我收到此错误:
1637370455: Loading config file /etc/mosquitto/conf.d/mosquitto.conf
1637370455: Error: Duplicate pid_file value in configuration.
1637370455: Error found at /etc/mosquitto/conf.d/mosquitto.conf:7.
1637370455: Error found at /etc/mosquitto/conf.d/mosquitto.conf:14.
第 7 行是pid_file /var/run/mosquitto/mosquitto.pid
第 14 行是include_dir /etc/mosquitto/conf.d
我可以使用 localhost 进行基本的 pub 和 sub 测试,但主机名仍然没有运气。是的,我知道您应该使用安全性,但我有一个通过本地 WiFi 控制机器人的应用程序,并且希望在不更改该组件的情况下保留应用程序的使用。
任何帮助我回到正轨,让 Mosquitto 经纪人和客户在同一个 pi 上工作,允许匿名访问和运行,非常感谢。我已经浏览了文档、示例文件,并参考了史蒂夫的其他教程,但正确的配置仍然不清楚。谢谢!
【问题讨论】:
-
检查
include_dir中的文件是否有另一个pid_file行! -
谢谢。我那里只有 mosquitto.conf 和 README。我已经注释掉了包含行,但随后在 PID 行上出现错误。然后在运行时: mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf 我得到 1637421962: Error: Unable to write pid file。还注释掉了 PID 行,但得到:1637422031:错误:无法打开日志文件 /var/log/mosquitto/mosquitto.log 进行写入。但是,似乎服务器当时正在运行,因为我没有返回到提示符。关于摆脱错误的任何想法?
-
还想知道如何让 mosquitto 在启动时自动使用这个 .conf 文件。我一直在自动运行 mosquitto: sudo systemctl enable mosquitto.service 但这不包括 conf 文件的自动运行,例如: mosquitto -c /etc/mosquitto/conf.d/mosquitto.conf 知道如何修复?
标签: raspberry-pi mqtt mosquitto