如何连接到Azure上托管的虚拟机上安装的mosquitto代理?

问题描述 投票:0回答:1

我在1883端口的虚拟机上安装了mosquitto broker。这个虚拟机托管在azure cloud上。为了获得对这个代理的访问,我通过添加入站规则打开了端口。但是我无法从外部发布到这个mosquitto代理网络。

我通过允许端口1883允许来自外部网络的访问来添加入站规则

string ClientId = new Guid().ToString();
client = new MqttClient("104.211.219.200", 1883, false, null);
client.Connect(ClientId);
client.Publish("local", Encoding.UTF8.GetBytes("Message from local PC"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
azure-virtual-machine mosquitto
1个回答
0
投票

根据您的描述,根据我的经验,我认为您的mosquitto现在不起作用是由于您的VM网络接口没有添加NSG规则以允许来自端口1883的入站请求。

以下是我在Azure Windows VM上安装mosquitto服务器的步骤。希望能帮助到你。

  1. 在Azure门户上,使用Windows 2012 R2 Datacenter创建Windows VM。
  2. 在选项卡Just-in-time access中启用Configuration功能,然后下载RDP文件以访问此VM。 enter image description here
  3. 我将mosquitto服务器安装文件(x64发行版,它来自https://mosquitto.org/download/)上传到Windows VM,并尝试安装它。 enter image description here
  4. 我有一个关于缺少VCRUNTIME140.dll的问题,然后安装VC ++ 2015发行版安装(它来自https://www.microsoft.com/en-us/download/details.aspx?id=48145)来修复它。
  5. 然后,我在mosquitto路径打开一个命令窗口并运行它。 enter image description here enter image description here
  6. 将入站规则添加到Windows Firewall with Advanced Security。它允许来自Windows 18上的端口1883的请求。 enter image description here
  7. 将入站规则添加到NSG网络接口以允许来自Azure VNET上的端口1883的请求。 enter image description here enter image description here
  8. 我使用MQTT桌面客户端MQTT.fx(它来自https://www.hivemq.com/blog/seven-best-mqtt-client-tools/)来测试连接,发布和订阅测试消息。 enter image description here enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.