You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派Bullseye上Mosquitto 2.0配置报错及主机名访问问题求助

错误根源

你的配置触发了递归加载逻辑:你将主配置文件放在/etc/mosquitto/conf.d/目录下,同时配置里写了include_dir /etc/mosquitto/conf.d,Mosquitto加载配置时读到这行就会再次扫描该目录下的所有conf文件,重复加载当前配置,导致pid_file参数重复定义报错。
另外主机名无法连接的原因是默认listener 1883仅绑定本地回环地址(127.0.0.1),没有绑定WiFi网卡的IP地址。

解决方案步骤

  1. 调整配置文件结构
  • 将当前存放在/etc/mosquitto/conf.d/mosquitto.conf的文件移动到默认主配置路径:
sudo mv /etc/mosquitto/conf.d/mosquitto.conf /etc/mosquitto/mosquitto.conf
  • 编辑主配置,删除include_dir /etc/mosquitto/conf.d行,同时修改listener参数绑定所有网卡,修改后完整配置如下:
# 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

listener 1883 0.0.0.0
allow_anonymous true
  1. 启动服务
  • 手动启动命令修改为:
mosquitto -c /etc/mosquitto/mosquitto.conf
  • 如果需要开机自启,使用systemd管理即可:
sudo systemctl enable --now mosquitto
sudo systemctl restart mosquitto
  1. 验证功能
  • 执行ss -tulnp | grep 1883,确认输出中有0.0.0.0:1883的监听记录,说明端口绑定正常。
  • 本地使用主机名进行pub/sub测试,同WiFi下的控制设备也可直接用树莓派主机名连接MQTT服务。

可选配置(保留conf.d目录)

如果你需要保留/etc/mosquitto/conf.d目录存放额外配置片段,只需在主配置中保留include_dir /etc/mosquitto/conf.d行,将listener、匿名访问这类自定义配置单独拆分为/etc/mosquitto/conf.d/custom.conf即可,不要将主配置放在conf.d目录下避免递归加载。

内容的提问来源于stack exchange,提问作者Gallaugher

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 20:54:04