Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux MQTT不';不能与全球ip合作_Linux_Debian_Port_Mqtt - Fatal编程技术网

Linux MQTT不';不能与全球ip合作

Linux MQTT不';不能与全球ip合作,linux,debian,port,mqtt,Linux,Debian,Port,Mqtt,一般资料: IP:1.2.3.4 服务器:Raspian Stretch(Debian 9) 服务器上运行的是apache2和2个网站 MOSQUITO用户:user 输入密码:psw 我已在服务器上安装了mosquitto,并设置了用户和密码。 当我在localhost中使用它时,我没有问题: mosquitto_pub -h localhost -p 1883 -t topic -u "user" -P "psw" -m "new message" mosquitto_sub -h lo

一般资料:

  • IP:
    1.2.3.4
  • 服务器:Raspian Stretch(Debian 9)
  • 服务器上运行的是apache2和2个网站
  • MOSQUITO用户:
    user
  • 输入密码:
    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"
我收到
新消息
,没有任何问题

不幸的是,如果我使用我的公共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"
几秒钟后,订阅者和发布者都会打印此错误:
错误:连接超时

我可以想象它有点像一个封闭的港口,但我不知道如何打开它

我试过了,但没有做任何改变:
sudoiptables-A INPUT-ptcp-mtcp-dport1883-jaccept

以下是我的配置文件:

/etc/mosquitto/conf.d/default.conf

allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883
# 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
/etc/mosquitcho/mosquitcho.conf

allow_anonymous false
password_file /etc/mosquitto/passwd
listener 1883
# 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

我假设您使用的IP实际上不是
1.2.3.4
——如果您没有自己的IP,并且它没有列为a,请不要在内部使用它

同样,如果你不拥有它,不要尝试在外部/互联网上使用它


如果您在消费者NAT’ing路由器后面,并使用路由器的外部IP地址,则可能存在两个问题:

  • 大多数消费者路由器不支持-即:您无法从路由器后面使用外部IP访问服务(即使您已正确设置端口转发)。
    • 要测试这一点,请尝试从朋友家连接或通过其他互联网连接(例如:您的手机)
    • 解决方案是直接连接到内部服务器。如果幸运的话,您的路由器可以配置为处理发夹,或者您可以升级路由器
  • 您可能需要在路由器上进行设置,以便在内部将端口
    1883
    上的传入连接转发到服务器

  • 顶层conf文件(
    /etc/mosquitto/mosquitto.conf
    )中有什么内容。服务器也在宿主环境(如AWS)中,如果是,您是否检查过没有环境级防火墙,也不需要在其中打开端口。@hardillb我已经用您需要的信息进行了编辑。服务器是在我家的无线网络连接上通过树莓皮自行托管的。谢谢,我用第2点解决了这个问题。我忘了设置端口转发