【问题标题】:Mosquitto: Starting in local only mode but can't fixMosquitto:以仅本地模式启动但无法修复
【发布时间】:2021-02-27 11:20:31
【问题描述】:

我的 Rpi4 运行我的家庭自动化系统最近将自己从 mosquitto 版本 1.6.12 升级到 2.0.8,因此它以仅本地模式启动。

进行了一些挖掘,但仍然无法使其全部正常工作,主要使用了这个以前的有用问题Mosquitto: Starting in local only mode,但我的设备仍然无法连接。

从我的蚊子日志中我看到了

1614386087: mosquitto version 2.0.8 starting
1614386087: Config loaded from /etc/mosquitto/mosquitto.conf.
1614386087: Opening ipv4 listen socket on port 1883.
1614386087: Opening ipv6 listen socket on port 1883.
1614386087: mosquitto version 2.0.8 running

服务显示这个

:~$ sudo systemctl status mosquitto
* mosquitto.service - Mosquitto MQTT Broker
   Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2021-02-27 00:34:47 GMT; 10h ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
  Process: 375 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS)
  Process: 398 ExecStartPre=/bin/chown mosquitto: /var/log/mosquitto (code=exited, status=0/SUCCESS)
  Process: 404 ExecStartPre=/bin/mkdir -m 740 -p /var/run/mosquitto (code=exited, status=0/SUCCESS)
  Process: 411 ExecStartPre=/bin/chown mosquitto: /var/run/mosquitto (code=exited, status=0/SUCCESS)
 Main PID: 419 (mosquitto)
   Memory: 1.5M
   CGroup: /system.slice/mosquitto.service
           `-419 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Feb 27 00:34:47 Vero4K systemd[1]: Starting Mosquitto MQTT Broker...
Feb 27 00:34:47 Vero4K mosquitto[419]: 1614386087: Loading config file /etc/mosquitto/conf.d/calz.conf
Feb 27 00:34:47 Vero4K systemd[1]: Started Mosquitto MQTT Broker.

在我的 calz.conf 文件中

listener 1883
allow_anonymous true

但是我本地版本的 Domoticz(在同一个盒子上运行)在它的日志中显示了这一点

Error: Plugin: Connection Exception: 'resolve: Host not found (authoritative)' connecting to '127.0.0.1:1883'
Error: (ShellyMQTT) Failed to connect to: 127.0.0.1:1883, Description: resolve: Host not found (authoritative)

我所有的 Tasmota 设备现在都显示了

14:49:38 MQT: Attempting connection...
14:49:38 MQT: Connect failed to 192.168.1.19:1883, rc -2. Retry in 120 sec

我可以看到端口也打开了

sudo netstat -tulpn | grep LISTEN
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      361/vsftpd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      729/sshd
tcp        0      0 0.0.0.0:37015           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:36666           0.0.0.0:*               LISTEN      608/kodi.bin
tcp        0      0 0.0.0.0:36667           0.0.0.0:*               LISTEN      608/kodi.bin
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      375/mosquitto
tcp        0      0 0.0.0.0:49472           0.0.0.0:*               LISTEN      763/rpc.statd
tcp        0      0 0.0.0.0:9090            0.0.0.0:*               LISTEN      608/kodi.bin
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/init
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      608/kodi.bin
tcp6       0      0 :::22                   :::*                    LISTEN      729/sshd
tcp6       0      0 :::49079                :::*                    LISTEN      763/rpc.statd
tcp6       0      0 :::36666                :::*                    LISTEN      608/kodi.bin
tcp6       0      0 :::36667                :::*                    LISTEN      608/kodi.bin
tcp6       0      0 :::1883                 :::*                    LISTEN      375/mosquitto
tcp6       0      0 :::49919                :::*                    LISTEN      -
tcp6       0      0 :::9090                 :::*                    LISTEN      608/kodi.bin
tcp6       0      0 :::111                  :::*                    LISTEN      1/init
tcp6       0      0 :::8080                 :::*                    LISTEN      608/kodi.bin

/etc/mosquitto/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

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

有什么想法吗?

【问题讨论】:

  • resolve: Host not found 表示它无法将 '127.0.0.1:1883' 转换为主机名,这很可能意味着您不应该包含端口号
  • 在 docker 容器中使用早期版本 1.6。

标签: networking mqtt iot mosquitto


【解决方案1】:

您的问题不是 Mosquitto 没有在听,而是您的设备正在尝试解析 127.0.0.1:1883 的主机名

我怀疑您已将 host:port 组合输入到应该输入的字段中

  1. 仅包含主机名/IP 地址
  2. 您可能不应该输入 127.0.0.1,因为它始终指向输入它的设备,您应该输入代理实际运行的 IP 地址。

【讨论】:

  • 不,127.0.0.1 日志是运行 MQTT 的位置,因此 Mosquitto 和 Domoticz 位于同一设备上,因此 localhost 应该可以工作。我已经修复了外部设备的错误复制/粘贴,这些指向 Rpi4 所在的 192.168.19。所以无论是本地还是外部的作品。
  • 很好,但您可能不应该在主机字段中包含端口号
  • 刚刚尝试从另一个 Windows 机器使用端口查询``` 启动 portqry.exe -n 192.168.1.19 -e 1883 -p TCP ... 查询目标系统调用:192.168.1.19 正在尝试解决IP 地址到名称... 无法将 IP 地址解析为名称查询... TCP 端口 1883(未知服务):不侦听 portqry.exe -n 192.168.1.19 -e 1883 -p TCP 退出并返回代码 0x00000001。 ```
  • 对不起,“主机字段中的端口号”是什么意思,我指定端口的唯一位置是在侦听器下的 calz.conf 文件中。
  • 编辑问题以显示 1) /etc/mosquittto/mosquitto.con 2) sudo lsof -i -P | grep mosquitto的输出
【解决方案2】:

最后还以为我整理出来了,奇怪的组合……

更新 Mosquito 需要侦听器端口和匿名部分,但由于某种原因,我的 Raspberry Pi 在重新启动时切换到来宾网络并获得了一个新 IP,所以什么都无法访问它:(

我意识到当端口正在侦听并且无法访问它时,对于 kodi、ssh 等其他所有东西都是一样的。我碰巧在控制台上,因为当时它更方便,如果我有尝试 SSH 到它也会失败。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-12
    • 2013-06-13
    • 2018-01-01
    相关资源
    最近更新 更多