请帮助我了解如何发布到位于服务器中的 Mosquitto,该服务器需要 key 文件才能通过 ssh 连接到它。
我正在尝试从不同网络中的计算机向 Ubuntu 16.04 服务器上的 Mosquitto 发布消息。
我已将问题缩小到服务器的连接配置设置。
要通过 ssh 访问它,我需要传递 key 文件,例如:
ssh -i mykeyfile.pem user@ipaddress
问题是我无法从不同网络中的计算机访问 Mosquitto,因为我不知道如何指定 key 文件。我检查了端口,它们是打开的。
这就是我尝试发布的方式:
mosquitto_pub -h ip_address -p 1883 -t test -m "hello world"
使用相同的配置,我在另一台不需要 key 文件的服务器上进行了尝试。我设法发布了一条消息。这就是我得出的结论,问题出在 key 文件上。
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.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
我尝试发布时遇到的错误是:
错误:连接超时
编辑
防火墙被禁用,所以 sudo ufw status
的结果是 disactivated
。我启用它并设置了一些规则。目前的状态是:
Status: active
To Action From
-- ------ ----
8083 ALLOW Anywhere
22 ALLOW Anywhere
80 ALLOW Anywhere
443 ALLOW Anywhere
1883 ALLOW Anywhere
8083 (v6) ALLOW Anywhere (v6)
22 (v6) ALLOW Anywhere (v6)
80 (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)
1883 (v6) ALLOW Anywhere (v6)
下一个输出来自 iptables sudo iptables -L -v -n
:
Chain ufw-user-input (1 references)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:8083
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:8083
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:22
699 40412 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:80
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:443
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:443
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1883
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:1883
0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 tcp dpt:1883
0 0 ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 udp dpt:1883
但是还是不能发布消息。
Mosquitto 所在的计算机运行 Apache2 服务器
我希望这是有道理的。 谢谢。
最佳答案
这是我解决问题的方法。
上下文:
- Mosquitto 在服务器中,
- 服务器位于VM
- VM 在 OpenStack 上。
在对 iptables、ufw、firewall 和 mosquitto 的配置文件进行大量(可能是不必要的)更改后,我检查了 OpenStack(我知道......我之前怎么没有提到这个!好吧,我是如此很困惑,这不是我的第一个想法)。然后我意识到我的 VM 的安全组没有有端口 1883 的规则(不允许或拒绝)。我添加了它。
Eureka ,我可以从外部计算机发布消息。
这是我的安全组的样子(添加的最后两行):
我的结论是,不仅只有一扇门,而且像洋葱一样有很多层要穿过!
希望这对其他人有帮助。
关于ssl - 在 OpenStack 服务器中发布到 Mosquitto,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54056736/