如何设置连接MQTT桥的代理?

时间:2019-04-04 06:16:36

标签: proxy mqtt mosquitto

我的公司代理后面的Linux上有一个蚊子经纪人。 我已经配置了与AWS相同的桥梁,如下所示:(mosquitto.conf)

connection bridge
address ec2-xxx-xxx-xxx-xxx.ap-northeast-1.compute.amazonaws.com:8089
remote_username admin
remote_password password
topic abc/raspi01 both 0
bridge_cafile /etc/pki/tls/certs/nginx-selfsigned.crt
bridge_insecure false

但是当我使用以下命令启动mosquitto服务时:

service mosquitto restart

在日志文件中,存在一些错误:

1554356888: mosquitto version 1.5.5 starting
1554356888: Config loaded from /etc/mosquitto/mosquitto.conf.
1554356888: Opening ipv4 listen socket on port 1883.
1554356888: Opening ipv6 listen socket on port 1883.
1554356888: Warning: Address family not supported by protocol
1554356888: Connecting bridge bridge (ec2-xxx-xxx-xxx-xxx.ap-northeast-1.compute.amazonaws.com:8089)
1554356888: Error creating bridge: Name or service not known.
1554356888: Warning: Unable to connect to bridge bridge.
1554356901: New connection from 127.0.0.1 on port 1883.
1554356901: New connection from 127.0.0.1 on port 1883.
1554356901: New client connected from 127.0.0.1 as mqtt_fd05fada.b70918 (c1, k60).
1554356901: New client connected from 127.0.0.1 as mqtt_2a3a025d.6c941e (c1, k60).
1554356919: Connecting bridge bridge (ec2-xxx-xxx-xxx-xxx.ap-northeast-1.compute.amazonaws.com:8089)
1554356919: Error creating bridge: Name or service not known.
1554356950: Connecting bridge bridge (ec2-xxx-xxx-xxx-xxx.ap-northeast-1.compute.amazonaws.com:8089)
1554356950: Error creating bridge: Name or service not known.

我认为原因是我的公司代理人。 我已经尝试使用mosquitto.service中的设置,但无法解决。

[Unit]
Description=Mosquitto MQTT v3.1/v3.1.1 Broker
Documentation=man:mosquitto.conf(5) man:mosquitto(8)
After=network-online.target
Wants=network-online.target

[Service]
Type=notify
NotifyAccess=main
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Environment="HTTPS_PROXY=http://user:pass@proxyhost:8800"
Environment="HTTP_PROXY=http://user:pass@proxyhost:8800"
Environment="NO_PROXY=127.0.0.1,localhost"
Restart=on-failure

[Install]
WantedBy=multi-user.target

有人可以帮助我吗?非常感谢。

2 个答案:

答案 0 :(得分:0)

您不能将HTTP代理用于MQTT桥连接(或任何本机MQTT连接)。 MQTT是完全不同的协议。

仅通过Websockets的MQTT可以通过HTTP代理工作,但是您不能将mosquitto配置为通过Websockets的MQTT运行桥。

答案 1 :(得分:0)

如果在发送连接之前使用HTTP CONNECT 在net_mosq.c

rc = connect(*sock, rp->ai_addr, rp->ai_addrlen);

一个人就能做到。

HTTP CONNECT与协议无关,它适用于基础TCP协议。