Azure IoT Edge入门(2)部署一台Edge Device
案例:部署一台Edge Device(Windows 系统)

通常情况下,部署一台Edge设备有如下四个步骤:
1. 创建Azure IoT Hub;
2.准备Edge Device(windows/linux),1.准备操作系统,2.在IoT Hub里创建IoT Edge Device;
3.安装并配置 Azure IoT Edge Runtime(离线或在线安装);
4. 从Azure Container Registry 下载业务容器,由业务容器开始发送遥测消息给Azure IoT Hub;
今天这一小节,介绍前三个步骤。
关于Azure Container Regisgtry,请参见《Azure Container Registry

Azure IoT Edge入门(2)部署一台Edge Device - 图1
本文主要介绍:
1. IoT Edge Runtime 对操作系统的要求
2. 准备Edge device(在azure 上购买一台Windows Server 2019)
3.准备Azure IoT Hub并新建IoT Edge Device
4.在Edge Device 上安装 IoT Edge Runtime
在线安装;
离线安装;

视频讲解:

您可以观看B站视频:https://www.bilibili.com/video/av91049338/
或在本站观看视频:

deploy-iot-dege-on-windows.mp4 (77.92MB)

图文步骤:

IoT Edge 对操作系统的要求,请参见:https://docs.azure.cn/zh-cn/iot-edge/support
主要分为两种(文档里称为两层),简单理解:
第一层系统是由微软进行过严格的Azure IoT Edge Runtime测试,完全兼容。
下表中列出的系统(不管是公开发布版还是公共预览版)受 Microsoft 的支持,并在每个新版本中进行了测试。

操作系统 AMD64 ARM32v7 ARM64
Raspbian Stretch Azure IoT Edge入门(2)部署一台Edge Device - 图3
Ubuntu Server 16.04 Azure IoT Edge入门(2)部署一台Edge Device - 图4 公共预览版
Ubuntu Server 18.04 Azure IoT Edge入门(2)部署一台Edge Device - 图5 公共预览版
Windows 10 IoT 核心版内部版本 17763 Azure IoT Edge入门(2)部署一台Edge Device - 图6
Windows 10 IoT 企业版内部版本 17763 Azure IoT Edge入门(2)部署一台Edge Device - 图7
Windows Server 2019 内部版本 17763 Azure IoT Edge入门(2)部署一台Edge Device - 图8
Windows Server IoT 2019 内部版本 17763 Azure IoT Edge入门(2)部署一台Edge Device - 图9


第二层理论上可兼容,或者微软合作伙伴已经成功运行了的。

操作系统 AMD64 ARM32v7 ARM64
CentOS 7.5 Azure IoT Edge入门(2)部署一台Edge Device - 图10 Azure IoT Edge入门(2)部署一台Edge Device - 图11 Azure IoT Edge入门(2)部署一台Edge Device - 图12
Debian 8 Azure IoT Edge入门(2)部署一台Edge Device - 图13 Azure IoT Edge入门(2)部署一台Edge Device - 图14 Azure IoT Edge入门(2)部署一台Edge Device - 图15
Debian 9 Azure IoT Edge入门(2)部署一台Edge Device - 图16 Azure IoT Edge入门(2)部署一台Edge Device - 图17 Azure IoT Edge入门(2)部署一台Edge Device - 图18
Debian 10 Azure IoT Edge入门(2)部署一台Edge Device - 图19 Azure IoT Edge入门(2)部署一台Edge Device - 图20 Azure IoT Edge入门(2)部署一台Edge Device - 图21
Mentor Embedded Linux Flex OS Azure IoT Edge入门(2)部署一台Edge Device - 图22 Azure IoT Edge入门(2)部署一台Edge Device - 图23 Azure IoT Edge入门(2)部署一台Edge Device - 图24
Mentor Embedded Linux Omni OS Azure IoT Edge入门(2)部署一台Edge Device - 图25 Azure IoT Edge入门(2)部署一台Edge Device - 图26
RHEL 7.5 Azure IoT Edge入门(2)部署一台Edge Device - 图27 Azure IoT Edge入门(2)部署一台Edge Device - 图28 Azure IoT Edge入门(2)部署一台Edge Device - 图29
Ubuntu 16.04 Azure IoT Edge入门(2)部署一台Edge Device - 图30 Azure IoT Edge入门(2)部署一台Edge Device - 图31 Azure IoT Edge入门(2)部署一台Edge Device - 图32
Ubuntu 18.04 Azure IoT Edge入门(2)部署一台Edge Device - 图33 Azure IoT Edge入门(2)部署一台Edge Device - 图34 Azure IoT Edge入门(2)部署一台Edge Device - 图35
Wind River 8 Azure IoT Edge入门(2)部署一台Edge Device - 图36
Yocto Azure IoT Edge入门(2)部署一台Edge Device - 图37 Azure IoT Edge入门(2)部署一台Edge Device - 图38 Azure IoT Edge入门(2)部署一台Edge Device - 图39
Raspbian Buster Azure IoT Edge入门(2)部署一台Edge Device - 图40 Azure IoT Edge入门(2)部署一台Edge Device - 图41

在Azure上准备一台虚拟机作为Edge设备使用

本案例中使用的是Windows Server 2019 Datacenter (zh-cn),当然可以选择其他第一层的操作系统。
Azure IoT Edge入门(2)部署一台Edge Device - 图42

创建Azure IoT Hub,并创建IoT Edge Device

在IoT Hub-IoT Edge中点击添加IoT Edge设备
Azure IoT Edge入门(2)部署一台Edge Device - 图43
输入设备ID,其余保持默认,点击保存
Azure IoT Edge入门(2)部署一台Edge Device - 图44

在Edge 设备上安装IoT Edge Runtime

在windows 中安装Edge Runtime,请参见:https://docs.azure.cn/zh-cn/iot-edge/how-to-install-iot-edge-windows
注意,本节中,我们选择安装和手动预配,手动预配的意思是,在安装Runtime过程中,需要手动输入IoT Edge Device的连接字符串。
1. 在线安装Azure IoT Edge Runtime:
登录到Windows Server中,以管理员权限运行如下Power Shell脚本:

  1. . {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; `
  2. Deploy-IoTEdge


画重点,如果此步骤,报网络错误,可以尝试打开连接 “https://aka.ms/iotedge-win”,如果打不开,可能存在网络问题,则此时需要使用离线安装方式。
2.离线安装Azure IoT Edge Runtime:
在页面上下载相应的 文件,https://github.com/Azure/azure-iotedge/releases
Azure IoT Edge入门(2)部署一台Edge Device - 图45
对于Windows 系统,需要根据系统是64/32位下载对应的cab文件和 vc_redist.exe(Visual C++ Redistributable Package)
注意,需要将下载的cab的包重命名为 Microsoft-Azure-IoTEdge.cab
vc_redist.exe 下载地址:vc_redist.exe
Azure IoT Edge入门(2)部署一台Edge Device - 图46
然后右键拷贝.ps1的路径,修改如如下的脚本中:
https://aka.ms/iotedge-win改为https://github.com/Azure/azure-iotedge/releases/download/1.0.9-rc5/IotEdgeSecurityDaemon.ps1,意味着按照更改后的脚本安装对应的runtime 版本。

  1. . {Invoke-WebRequest -useb https://github.com/Azure/azure-iotedge/releases/download/1.0.9-rc5/IotEdgeSecurityDaemon.ps1} | Invoke-Expression; `
  2. Deploy-IoTEdge -OfflineInstallationPath D:\Downloads\iotedgeoffline


在PowerShell 管理员权限先运行上述脚本,如提示重启,则重启后需执行如下脚本:
Azure IoT Edge入门(2)部署一台Edge Device - 图47

. {Invoke-WebRequest -useb https://aka.ms/iotedge-win} | Invoke-Expression; `
Initialize-IoTEdge


注意:脚本中的 https://aka.ms/iotedge-win,如果安装的是指定版本,也需要替换为指定版本的ps1文件路径。
执行过程中需要按找提示输入IoT Edge 的连接字符串
Azure IoT Edge入门(2)部署一台Edge Device - 图48
使用 如下命令检查 IoT Runtime 运行状态:

Get-Service iotedge

Azure IoT Edge入门(2)部署一台Edge Device - 图49
使用如下命令检查当前运行的模块:

iotedge list

初次安装完成,只有一个edgeagent 模块,此现象是正常的,其他模块由edge agent 负责安装,需要时间。
Azure IoT Edge入门(2)部署一台Edge Device - 图50

在Portal上可以查看IoT Edge 的运行状态和模块状态:
Azure IoT Edge入门(2)部署一台Edge Device - 图51

Azure IoT Edge入门(2)部署一台Edge Device - 图52