安装或卸载 Azure IoT Edge 运行时Install or uninstall the Azure IoT Edge runtime

使用 Azure IoT Edge 运行时可将设备转变为 IoT Edge 设备。The Azure IoT Edge runtime is what turns a device into an IoT Edge device. 该运行时可以部署在像 Raspberry Pi 一样小的设备上,也可以部署在像工业服务器一样大的设备上。The runtime can be deployed on devices as small as a Raspberry Pi or as large as an industrial server. 使用 IoT Edge 运行时配置设备后,即可开始从云中部署业务逻辑。Once a device is configured with the IoT Edge runtime, you can start deploying business logic to it from the cloud. 若要了解详细信息,请参阅了解 Azure IoT Edge 运行时及其体系结构To learn more, see Understand the Azure IoT Edge runtime and its architecture.

设置 IoT Edge 设备的过程包括两个步骤。There are two steps to setting up an IoT Edge device. 第一步是安装本文介绍的运行时及其依赖项。The first step is to install the runtime and its dependencies, which is covered by this article. 第二步是将设备连接到其在云中的标识,并使用 IoT 中心设置身份验证。The second step is to connect the device to its identity in the cloud and set up authentication with IoT Hub. 这些步骤会在后续文章中介绍。Those steps are in the next articles.

本文列出了在 Linux 或 Windows 设备上安装 Azure IoT Edge 运行时的步骤。This article lists the steps to install the Azure IoT Edge runtime on Linux or Windows devices. 对于 Windows 设备,还可选择使用 Linux 容器或 Windows 容器。For Windows devices, you have an additional choice of using Linux containers or Windows containers. 目前,建议对生产场景使用 Windows 上的 Windows 容器。Currently, Windows containers on Windows are recommended for production scenarios. Windows 上的 Linux 容器对于开发和测试方案非常有用,尤其是在 Windows 电脑上进行开发以部署到 Linux 设备时。Linux containers on Windows are useful for development and testing scenarios, especially if you're developing on a Windows PC in order to deploy to Linux devices.


有关生产方案目前支持哪些操作系统的最新信息,请参阅 Azure IoT Edge 支持的系统For the latest information about which operating systems are currently supported for production scenarios, see Azure IoT Edge supported systems

具有 X64、ARM32 或 ARM64 Linux 设备。Have an X64, ARM32, or ARM64 Linux device. Microsoft 为 Ubuntu Server 16.04、Ubuntu Server 18.04 和 Raspbian Stretch 操作系统提供安装包。Microsoft provides installation packages for Ubuntu Server 16.04, Ubuntu Server 18.04, and Raspbian Stretch operating systems.

准备设备以访问 Microsoft 安装包。Prepare your device to access the Microsoft installation packages.

  1. 安装与设备操作系统匹配的存储库配置。Install the repository configuration that matches your device operating system.

    • Ubuntu Server 16.04Ubuntu Server 16.04:

      curl https://packages.microsoft.com/config/ubuntu/16.04/multiarch/prod.list > ./microsoft-prod.list
    • Ubuntu Server 18.04Ubuntu Server 18.04:

      curl https://packages.microsoft.com/config/ubuntu/18.04/multiarch/prod.list > ./microsoft-prod.list
    • Raspberry Pi OS StretchRaspberry Pi OS Stretch:

      curl https://packages.microsoft.com/config/debian/stretch/multiarch/prod.list > ./microsoft-prod.list
  2. 将生成的列表复制到 sources.list.d 目录。Copy the generated list to the sources.list.d directory.

    sudo cp ./microsoft-prod.list /etc/apt/sources.list.d/
  3. 安装 Microsoft GPG 公钥。Install the Microsoft GPG public key.

    curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
    sudo cp ./microsoft.gpg /etc/apt/trusted.gpg.d/

Azure IoT Edge 软件包受制于每个包(usr/share/doc/{package-name}LICENSE 目录)中的许可条款。Azure IoT Edge software packages are subject to the license terms located in each package (usr/share/doc/{package-name} or the LICENSE directory). 请在使用包之前阅读许可条款。Read the license terms prior to using a package. 安装和使用包即表示你接受这些条款。Your installation and use of a package constitutes your acceptance of these terms. 如果不同意许可条款,请勿使用该包。If you do not agree with the license terms, do not use that package.

安装容器引擎Install a container engine

Azure IoT Edge 依赖于 OCI 兼容的容器运行时。Azure IoT Edge relies on an OCI-compatible container runtime. 对于生产方案,建议使用基于 Moby 的引擎。For production scenarios, we recommended that you use the Moby-based engine. Moby 引擎是官方唯一支持用于 Azure IoT Edge 的容器引擎。The Moby engine is the only container engine officially supported with Azure IoT Edge. Docker CE/EE 容器映像与 Moby 运行时兼容。Docker CE/EE container images are compatible with the Moby runtime.

更新设备上的包列表。Update package lists on your device.

sudo apt-get update

安装 Moby 引擎。Install the Moby engine.

sudo apt-get install moby-engine

如果在安装 Moby 容器引擎时出现错误,请验证 Linux 内核的 Moby 兼容性。If you get errors when installing the Moby container engine, verify your Linux kernel for Moby compatibility. 有些嵌入式设备制造商寄送的设备映像包含的自定义 Linux 内核没有确保容器引擎兼容所需的功能。Some embedded device manufacturers ship device images that contain custom Linux kernels without the features required for container engine compatibility. 运行以下命令,该命令使用 Moby 提供的 check-config 脚本来检查内核配置:Run the following command, which uses the check-config script provided by Moby, to check your kernel configuration:

curl -sSL https://raw.githubusercontent.com/moby/moby/master/contrib/check-config.sh -o check-config.sh
chmod +x check-config.sh

在该脚本的输出中,检查 Generally NecessaryNetwork Drivers 下的所有项是否都已启用。In the output of the script, check that all items under Generally Necessary and Network Drivers are enabled. 如果缺少某些功能,请启用它们,方法是通过源重新构建内核,然后选择关联的模块,将其包括在相应的内核 .config 中。同样,如果使用内核配置生成器(例如 defconfigmenuconfig),请找到并启用相应的功能,然后以相应方式重新构建内核。If you are missing features, enable them by rebuilding your kernel from source and selecting the associated modules for inclusion in the appropriate kernel .config. Similarly, if you are using a kernel configuration generator like defconfig or menuconfig, find and enable the respective features and rebuild your kernel accordingly. 部署新修改的内核以后,请再次运行 check-config 脚本,验证是否已成功启用所有必需功能。Once you have deployed your newly modified kernel, run the check-config script again to verify that all the required features were successfully enabled.

安装 IoT Edge 安全守护程序Install the IoT Edge security daemon

IoT Edge 安全守护程序提供和维护 IoT Edge 设备上的安全标准。The IoT Edge security daemon provides and maintains security standards on the IoT Edge device. 守护程序在每次开机时启动,并通过启动 IoT Edge 运行时的其余部分来启动设备。The daemon starts on every boot and bootstraps the device by starting the rest of the IoT Edge runtime.

这些部分中的步骤表示在具有 Internet 连接的设备上安装最新版本的典型过程。The steps in these section represent the typical process to install the latest version on a device that has internet connection. 如果需要安装特定版本(如预发行版)或需要在脱机状态下安装,请按照下一部分中的脱机或特定版本安装步骤进行操作。If you need to install a specific version, like a pre-release version, or need to install while offline, follow the Offline or specific version installation steps in the next section.

更新设备上的包列表。Update package lists on your device.

sudo apt-get update

查看可用的 IoT Edge 版本。Check to see which versions of IoT Edge are available.

apt list -a iotedge

如果要安装最新版本的安全守护程序,请使用以下命令,该命令还会安装最新版本的 libiothsm-std 包:If you want to install the most recent version of the security daemon, use the following command that also installs the latest version of the libiothsm-std package:

sudo apt-get install iotedge

如果要安装特定版本的安全守护程序,请从 apt 列表输出中指定该版本。If you want to install a specific version of the security daemon, specify the version from the apt list output. 还要为 libiothsm-std 包指定同一版本,否则将安装其最新版本。Also specify the same version for the libiothsm-std package, which otherwise would install its latest version. 例如,以下命令将安装最新版本 1.0.8 版本:For example, the following command installs the most recent version of the 1.0.8 release:

sudo apt-get install iotedge=1.0.8* libiothsm-std=1.0.8*

如果你要安装的版本未列出,请按照下一部分中的脱机或特定版本安装步骤进行操作。If the version that you want to install isn't listed, follow the Offline or specific version installation steps in the next section. 此部分说明了如何将 IoT Edge 安全守护程序的任何之前版本或候选发布版本作为目标。That section shows you how to target any previous version of the IoT Edge security daemon, or release candidate versions.

现在容器引擎和 IoT Edge 运行时已安装在设备上,你可开始下一步操作,即向 IoT 中心注册你的设备并使用其云标识和身份验证信息设置设备。Now that the container engine and the IoT Edge runtime are installed on your device, you're ready for the next step, which is to register your device with IoT Hub and set up the device with its cloud identity and authentication information.

根据要使用的身份验证类型,选择下一篇文章:Choose the next article based on which authentication type you want to use:

脱机或特定版本安装Offline or specific version installation

本部分中的步骤适用于标准安装步骤未涵盖的方案。The steps in this section are for scenarios not covered by the standard installation steps. 这可能包括:This may include:

  • 脱机安装 IoT EdgeInstall IoT Edge while offline
  • 安装候选发布版本Install a release candidate version
  • 在 Windows 上,安装非最新版本On Windows, install a version other than the latest

如果想要安装特定版本的无法通过 apt-get install 获取的 Azure IoT Edge 运行时,请使用本部分中的步骤。Use the steps in this section if you want to install a specific version of the Azure IoT Edge runtime that isn't available through apt-get install. Microsoft 包列表仅包含有限的一组最新版本及其子版本,因此,这些步骤适用于想要安装较旧版本或候选发布版本的任何用户。The Microsoft package list only contains a limited set of recent versions and their sub-versions, so these steps are for anyone who wants to install an older version or a release candidate version.

使用 curl 命令,可以直接从 IoT Edge GitHub 存储库将组件文件作为目标。Using curl commands, you can target the component files directly from the IoT Edge GitHub repository.

  1. 导航到 Azure IoT Edge 版本,找到需要将其作为目标的发行版。Navigate to the Azure IoT Edge releases, and find the release version that you want to target.

  2. 展开该版本的“资产”部分。Expand the Assets section for that version.

  3. 每个版本应该都有用于 IoT Edge 安全守护程序和 hsmlib 的新文件。Every release should have new files for the IoT Edge security daemon and the hsmlib. 使用以下命令更新这些组件。Use the following commands to update those components.

    1. 找到与 IoT Edge 设备的体系结构匹配的 libiothsm-std 文件。Find the libiothsm-std file that matches your IoT Edge device's architecture. 右键单击文件链接并复制链接地址。Right-click on the file link and copy the link address.

    2. 将复制的链接用在以下命令中,安装该版本的 hsmlib:Use the copied link in the following command to install that version of the hsmlib:

      curl -L <libiothsm-std link> -o libiothsm-std.deb && sudo dpkg -i ./libiothsm-std.deb
    3. 找到与 IoT Edge 设备的体系结构匹配的 iotedge 文件。Find the iotedge file that matches your IoT Edge device's architecture. 右键单击文件链接并复制链接地址。Right-click on the file link and copy the link address.

    4. 将复制的链接用在以下命令中,安装该版本的 IoT Edge 安全守护程序:Use the copied link in the following command to install that version of the IoT Edge security daemon.

      curl -L <iotedge link> -o iotedge.deb && sudo dpkg -i ./iotedge.deb

现在容器引擎和 IoT Edge 运行时已安装在设备上,你可开始下一步操作,即在 IoT 中心对 IoT Edge 设备进行身份验证Now that the container engine and the IoT Edge runtime are installed on your device, you're ready for the next step, which is to Authenticate an IoT Edge device in IoT Hub.

卸载 IoT EdgeUninstall IoT Edge

若要从设备中删除 IoT Edge 安装,请使用以下命令。If you want to remove the IoT Edge installation from your device, use the following commands.

删除 IoT Edge 运行时。Remove the IoT Edge runtime.

sudo apt-get remove --purge iotedge

删除 IoT Edge 运行时后,已创建的所有容器都会停止,但仍存在于设备上。When the IoT Edge runtime is removed, any containers that it created are stopped but still exist on your device. 查看所有容器以了解哪些容器仍然存在。View all containers to see which ones remain.

sudo docker ps -a

从设备中删除容器,包括两个运行时容器。Delete the containers from your device, including the two runtime containers.

sudo docker rm -f <container name>

最后,从设备中删除容器运行时。Finally, remove the container runtime from your device.

sudo apt-get remove --purge moby-cli
sudo apt-get remove --purge moby-engine

后续步骤Next steps

安装 IoT Edge 运行时后,将设备配置为与 IoT 中心连接。After installing the IoT Edge runtime, configure your device to connect with IoT Hub. 以下文章介绍如何在云中注册新设备,然后向设备提供其标识和身份验证信息。The following articles walk through registering a new device in the cloud and then providing the device with its identity and authentication info.

根据要使用的身份验证类型,选择下一篇文章:Choose the next article based on which type of authentication you want to use: