【发布时间】:2018-04-17 10:41:33
【问题描述】:
一般信息:
- IP:
1.2.3.4 - 服务器:Raspian Stretch (Debian 9)
- 在服务器上运行 apache2 和 2 个网站。
- 蚊子用户:
user - moquittto 密码:
psw
我已经在我的服务器上安装了mosquitto 并设置了用户和密码。
当我在 localhost 中使用它时,我没有问题:
mosquitto_pub -h localhost -p 1883 -t topic -u "user" -P "psw" -m "new message"
mosquitto_sub -h localhost -p 1883 -t topic -u "user" -P "psw"
我收到new message 没有任何问题
不幸的是,如果我使用我的公共 ip,它就不再起作用了:
mosquitto_pub -h 1.2.3.4 -p 1883 -t topic -u "user" -P "psw" -m "new message"
mosquitto_sub -h 1.2.3.4 -p 1883 -t topic -u "user" -P "psw"
几秒钟后,订阅者和发布者都会打印此错误:Error: Connection timed out
我可以想象这是一个封闭的端口,但我不知道如何解锁它。
我试过了,但没有改变任何东西:sudo iptables -A INPUT -p tcp -m tcp --dport 1883 -j ACCEPT
这些是我的配置文件:
/etc/mosquitto/conf.d/default.conf
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883
/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.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
【问题讨论】:
-
顶级 conf 文件 (
/etc/mosquitto/mosquitto.conf) 中有什么。托管环境(例如 AWS)中的服务器也是如此,如果是的话,您是否检查过没有环境级别的防火墙,您也需要在其中打开端口。 -
@hardillb 我已经编辑了您需要的信息。服务器自托管在我家的树莓派 wifi 连接中。