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

How to set proxy for connecting of MQTT bridge?

我在公司代理后面的 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

任何人都可以帮助我吗?非常感谢。

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

只有 MQTT over Websockets 可以通过 HTTP 代理工作,但您不能将 mosquitto 配置为 运行 与 MQTT over Websockets 的桥接。

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

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

可以做到这一点。

HTTP CONNECT 与协议无关,它适用于底层 TCP 协议。