创建运行IoTEdge的虚拟机


文档摘要

创建运行IoT Edge的虚拟机 在Azure中,您可以创建一个虚拟机——一种您可以在云中配置并运行自己软件的计算机。 您可以在Wikipedia上的虚拟机页面上阅读更多关于虚拟机的信息。 任务 - 设置IoT Edge虚拟机 运行以下命令以创建一个已预装Azure IoT Edge的虚拟机: 将 with a name for this virtual machine. This needs to be globally unique, so use something like with your name or another value on the end.

创建运行IoT Edge的虚拟机

在Azure中,您可以创建一个虚拟机——一种您可以在云中配置并运行自己软件的计算机。

您可以在Wikipedia上的虚拟机页面上阅读更多关于虚拟机的信息。

任务 - 设置IoT Edge虚拟机

  1. 运行以下命令以创建一个已预装Azure IoT Edge的虚拟机:

    az deployment group create \ --resource-group fruit-quality-detector \ --template-uri https://raw.githubusercontent.com/Azure/iotedge-vm-deploy/1.2.0/edgeDeploy.json \ --parameters dnsLabelPrefix=<vm_name> \ --parameters adminUsername=<username> \ --parameters deviceConnectionString="<connection_string>" \ --parameters authenticationType=password \ --parameters adminPasswordOrKey="<password>"

    <vm_name> with a name for this virtual machine. This needs to be globally unique, so use something like fruit-quality-detector-vm- with your name or another value on the end.

    Replace <username> and <password> with a username and password to use to log in to the VM. These need to be relatively secure, so you can't use admin/password.

    Replace <connection_string> with the connection string of your fruit-quality-detector-edge IoT Edge device.

    This will create a VM configured as a DS1 v2 virtual machine. These categories indicate how powerful the machine is, and therefor how much it costs. This VM has 1 CPU and 3.5GB of RAM.

    You can see the current pricing of these VMs on the Azure Virtual Machine pricing guide

    Once the VM has been created, the IoT Edge runtime will be installed automatically, and configured you connect to your IoT Hub as your fruit-quality-detector-edge 设备中的占位符替换为相应的值。

  2. 您需要虚拟机的IP地址或DNS名称来从该设备调用图像分类器。运行以下命令以获取此信息:

    az vm list --resource-group fruit-quality-detector \ --output table \ --show-details

    复制 PublicIps field, or the Fqdns 字段的值。

  3. 虚拟机是收费的。截至撰写本文时,一个DS1虚拟机每小时的成本约为0.06美元。为了降低成本,当您不使用它时,应该关闭虚拟机,并在完成项目后将其删除。

    您可以配置虚拟机在每天的特定时间自动关机。这样,如果您忘记关闭它,您不会被收取超过自动关机时间的费用。使用以下命令设置此功能:

    az vm auto-shutdown --resource-group fruit-quality-detector \ --name <vm_name> \ --time <shutdown_time_utc>

    <vm_name> with the name of your virtual machine.

    Replace <shutdown_time_utc> with the UTC time that you want the VM to shut down using 4 digits as HHMM. For example, if you want to shutdown at midnight UTC, you would set this to 0000 中的占位符替换为相应的值。对于美国西海岸的晚上7:30,您将使用0230(美国西海岸晚上7:30相当于UTC凌晨2:30)。

  4. 您的图像分类器将在该边缘设备上运行,并监听端口80(标准HTTP端口)。默认情况下,虚拟机阻止入站端口,因此您需要启用端口80。端口是在网络安全组中启用的,所以首先您需要知道虚拟机的网络安全组名称,这可以通过以下命令找到:

    az network nsg list --resource-group fruit-quality-detector \ --output table

    复制 Name 字段的值。

  5. 运行以下命令以向网络安全组添加规则,以打开端口80:

    az network nsg rule create \ --resource-group fruit-quality-detector \ --name Port_80 \ --protocol tcp \ --priority 1010 \ --destination-port-range 80 \ --nsg-name <nsg name>

    <nsg name> 替换为上一步中获取的网络安全组名称。

任务 - 管理您的虚拟机以降低成本

  1. 当您不使用虚拟机时,应将其关闭。要关闭虚拟机,请使用以下命令:

    az vm deallocate --resource-group fruit-quality-detector \ --name <vm_name>

    <vm_name> with the name of your virtual machine.

    There is an az vm stop 命令中的占位符替换为您的虚拟机名称。az vm stop 命令会停止虚拟机,但会保留分配给您的计算机,因此您仍需支付其运行费用。

  2. 要重启虚拟机,请使用以下命令:

    az vm start --resource-group fruit-quality-detector \ --name <vm_name>

    <vm_name> 替换为您的虚拟机名称。

声明:
本文件灏天文库团队进行了翻译。尽管我们力求准确,但请注意,翻译可能包含错误或不准确之处。原文档以其原始语言为准。我们不对因使用此翻译而产生的任何误解或误译负责。


发布者: 作者: 转发
评论区 (0)
U