使用 Bicep 在 Ubuntu 虚拟机上运行 Azure IoT Edge
适用于: IoT Edge 1.5 IoT Edge 1.4
重要
IoT Edge 1.5 LTS 和 IoT Edge 1.4 LTS 是受支持的版本。 IoT Edge 1.4 LTS 的生命周期结束日期为 2024 年 11 月 12 日。 如果你使用的是较低的版本,请参阅更新 IoT Edge。
使用 Azure IoT Edge 运行时可将设备转变为 IoT Edge 设备。 该运行时可以部署在像 Raspberry Pi 一样小的设备上,也可以部署在像工业服务器一样大的设备上。 使用 IoT Edge 运行时配置设备后,即可开始从云中部署业务逻辑。
若要了解有关 IoT Edge 运行时如何工作以及包含哪些组件的详细信息,请参阅了解 Azure IoT Edge 运行时及其体系结构。
从 Azure CLI 部署
无法部署远程 Bicep 文件。 在本地将 Bicep 文件的副本保存为 main.bicep。
使用以下命令来确保已安装 Azure CLI IoT 扩展:
az extension add --name azure-iot
接下来,如果在桌面上使用 Azure CLI,请先登录:
az cloud set -n AzureChinaCloud az login # az cloud set -n AzureCloud //means return to Public Azure.
如果你有多个订阅,请选择要使用的订阅:
列出订阅:
az account list --output table
复制要使用的订阅的 SubscriptionID 字段。
使用复制的 ID 设置工作订阅:
az account set -s <SubscriptionId>
创建新资源组(或者在后续步骤中指定现有的资源组):
az group create --name IoTEdgeResources --location chinanorth2
创建新虚拟机:
若要为
password
使用 authenticationType,请参阅以下示例:az deployment group create \ --resource-group IoTEdgeResources \ --template-file "main.bicep" \ --parameters dnsLabelPrefix='my-edge-vm1' \ --parameters deviceConnectionString=$(az iot hub device-identity connection-string show --device-id <REPLACE_WITH_DEVICE-NAME> --hub-name <REPLACE-WITH-HUB-NAME> -o tsv) \ --parameters authenticationType='password' \ --parameters adminUsername='<REPLACE_WITH_USERNAME>' \ --parameters adminPasswordOrKey="<REPLACE_WITH_SECRET_PASSWORD>"
若要使用 SSH 密钥进行身份验证,可为 authenticationType 指定
sshPublicKey
,然后在 adminPasswordOrKey 参数中提供 SSH 密钥的值。 例如:#Generate the SSH Key ssh-keygen -m PEM -t rsa -b 4096 -q -f ~/.ssh/iotedge-vm-key -N "" #Create a VM using the iotedge-vm-deploy script az deployment group create \ --resource-group IoTEdgeResources \ --template-file "main.bicep" \ --parameters dnsLabelPrefix='my-edge-vm1' \ --parameters deviceConnectionString=$(az iot hub device-identity connection-string show --device-id <REPLACE_WITH_DEVICE-NAME> --hub-name <REPLACE-WITH-HUB-NAME> -o tsv) \ --parameters authenticationType='sshPublicKey' \ --parameters adminUsername='<REPLACE_WITH_USERNAME>' \ --parameters adminPasswordOrKey="$(< ~/.ssh/iotedge-vm-key.pub)"
验证部署是否已成功完成。 虚拟机资源应会部署到所选的资源组中。 请记下计算机名称,此名称应采用
vm-0000000000000
格式。 另外,请记下关联的“DNS 名称”,其格式应为<dnsLabelPrefix>
.<location>
.cloudapp.chinacloudapi.cn。可以从上一步骤的 JSON 格式输出中获取“DNS 名称”,它作为“公共 SSH”条目的一部分显示在 outputs 节中。 使用此条目的值可以通过 SSH 连接到新部署的计算机。
"outputs": { "public SSH": { "type": "String", "value": "ssh <adminUsername>@<DNS_Name>" } }
也可以从 Azure 门户中新部署的虚拟机的“概述”部分获取“DNS 名称”。
设置后若要通过 SSH 连接到此 VM,请在命令中使用关联的“DNS 名称”:
ssh <adminUsername>@<DNS_Name>
后续步骤
预配了安装运行时的 IoT Edge 设备后,现在可以部署 IoT Edge 模块。
如果无法正确安装 IoT Edge 运行时,请参阅故障排除页。
若要将现有安装更新到最新版本的 IoT Edge,请参阅更新 IoT Edge 安全守护程序和运行时。
若要通过 SSH 或其他入站连接打开端口以访问 VM,请参阅有关打开 Linux VM 的端口和终结点的 Azure 虚拟机文档。