运行家庭自动化的 Rpi4 最近将其自身从 mosquitto 版本 1.6.12 升级到 2.0.8,因此它以仅本地模式启动。
做了一些挖掘,但仍然无法使其再次正常工作,主要使用了之前的有用问题Mosquitto:以仅本地模式启动,但我的设备仍然无法连接。
从我的蚊子日志中我看到
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
有什么想法吗?
您的问题不是 Mosquitto 没有监听,而是您的设备正在尝试解析主机名
127.0.0.1:1883
我怀疑您已将主机:端口组合输入到应该的字段中
127.0.0.1
,因为它始终指向输入它的设备,并且您应该输入代理实际运行的 IP 地址。我终于解决了这个问题。在 /etc/mosquitto/conf.d/ 中的 custom.conf(或您命名的任何名称)文件中,在“listener 1883”后面添加运行 MQTT 代理的系统的 IP 地址。像这样: 听众 1883 如果您运行 netstat 命令,则在运行“mosquitto -c”命令后,您应该能够看到 mosquitto 在主机 IP 地址上运行。
我想我最终还是把它整理好了,奇怪的组合......
更新 Mosquito 需要侦听器端口和匿名部分,但由于某种原因,我的 Raspberry Pi 重新启动后已切换到访客网络并获得了新的 IP,因此任何内容都无法访问它:(
我意识到当端口正在侦听并且无法访问它时,对于其他所有东西(例如kodi,ssh等)也是如此。我碰巧在控制台上,因为当时它更方便,如果我尝试过通过 SSH 访问它也会失败。