安装或卸载 Azure IoT Edge for LinuxInstall or uninstall Azure IoT Edge for Linux

使用 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.

本文列出了在 Linux 设备上安装 Azure IoT Edge 运行时的步骤。This article lists the steps to install the Azure IoT Edge runtime on Linux devices.

先决条件Prerequisites

  • 已注册的设备 IDA registered device ID

    如果你已为设备注册了对称密钥身份验证,请准备好设备连接字符串。If you registered your device with symmetric key authentication, have the device connection string ready.

    如果你已为设备注册了 X.509 自签名证书身份验证,则至少需要有一个用来注册设备的标识证书及其可在设备上使用的匹配私钥。If you registered your device with X.509 self-signed certificate authentication, have at least one of the identity certificates that you used to register the device and its matching private key available on your device.

  • Linux 设备A Linux device

    具有 X64、ARM32 或 ARM64 Linux 设备。Have an X64, ARM32, or ARM64 Linux device. Microsoft 提供了适用于 Ubuntu Server 18.04 和 Raspberry Pi OS Stretch 操作系统的安装包。Microsoft provides installation packages for Ubuntu Server 18.04 and Raspberry Pi OS Stretch operating systems.

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

    备注

    对 ARM64 设备的支持为公共预览版Support for ARM64 devices is in public preview.

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

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

    • 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
      

    将生成的列表复制到 sources.list.d 目录。Copy the generated list to the sources.list.d directory.

    sudo cp ./microsoft-prod.list /etc/apt/sources.list.d/
    

    安装 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 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
./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 EdgeInstall IoT Edge

为设备预配其云标识Provision the device with its cloud identity

现在容器引擎和 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 set up the device with its cloud identity and authentication information.

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

选项 1:使用对称密钥进行身份验证Option 1: Authenticate with symmetric keys

此时,IoT Edge 运行时安装在 Linux 设备上,你需要使用设备的云标识和身份验证信息来预配设备。At this point, the IoT Edge runtime is installed on your Linux device, and you need to provision the device with its cloud identity and authentication information.

本部分逐步讲解了如何为设备预配对称密钥身份验证。This section walks through the steps to provision a device with symmetric key authentication. 你应当已在 IoT 中心注册了设备,并从设备信息中检索了连接字符串。You should have registered your device in IoT Hub, and retrieved the connection string from the device information. 如果没有,请按照在 IoT 中心注册 IoT Edge 设备中的步骤进行操作。If not, follow the steps in Register an IoT Edge device in IoT Hub.

选项 2:使用 X.509 证书进行身份验证Option 2: Authenticate with X.509 certificates

此时,IoT Edge 运行时安装在 Linux 设备上,你需要使用设备的云标识和身份验证信息来预配设备。At this point, the IoT Edge runtime is installed on your Linux device, and you need to provision the device with its cloud identity and authentication information.

本部分逐步讲解了如何为设备预配 X.509 证书身份验证。This section walks through the steps to provision a device with X.509 certificate authentication. 你应当已在 IoT 中心注册了设备,并提供了与 IoT Edge 设备上的证书和私钥相匹配的指纹。You should have registered your device in IoT Hub, providing thumbprints that match the certificate and private key located on your IoT Edge device. 如果没有,请按照在 IoT 中心注册 IoT Edge 设备中的步骤进行操作。If not, follow the steps in Register an IoT Edge device in IoT Hub.

验证成功的配置Verify successful configuration

验证是否已在 IoT Edge 设备上成功安装并配置运行时。Verify that the runtime was successfully installed and configured on your IoT Edge device.

提示

需要提升权限才能运行 iotedge 命令。You need elevated privileges to run iotedge commands. 安装 IoT Edge 运行时后从计算机中注销并第一次重新登录后,你的权限将自动更新。Once you sign out of your machine and sign back in the first time after installing the IoT Edge runtime, your permissions are automatically updated. 在此之前,请在命令前使用 sudoUntil then, use sudo in front of the commands.

检查以确保 IoT Edge 系统服务正在运行。Check to see that the IoT Edge system service is running.

若需排查服务问题,请检索服务日志。If you need to troubleshoot the service, retrieve the service logs.

使用 check 工具验证设备的配置和连接状态。Use the check tool to verify configuration and connection status of the device.

sudo iotedge check

提示

请始终使用 sudo 来运行检查工具,即使权限已更新。Always use sudo to run the check tool, even after your permissions are updated. 该工具需要提升的权限才能访问配置文件以验证配置状态。The tool needs elevated privileges to access the config file to verify configuration status.

查看在 IoT Edge 设备上运行的所有模块。View all the modules running on your IoT Edge device. 当服务首次启动时,你应当只会看到 edgeAgent 模块正在运行。When the service starts for the first time, you should only see the edgeAgent module running. edgeAgent 模块会默认运行,用于安装并启动部署到设备的任何其他模块。The edgeAgent module runs by default and helps to install and start any additional modules that you deploy to your device.

sudo iotedge list

脱机或特定版本安装(可选)Offline or specific version installation (optional)

本部分中的步骤适用于标准安装步骤未涵盖的方案。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

如果想要安装特定版本的无法通过 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.

现在容器引擎和 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 Provision the device with its cloud identity.

卸载 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.

如果要删除与 IoT Edge 关联的所有文件(包括配置文件),请使用 --purge 标记。Use the --purge flag if you want to delete all the files associated with IoT Edge, including your configuration files. 如果要重新安装 IoT Edge 并在以后使用相同的配置信息,请忽略此标记。Leave this flag out if you want to reinstall IoT Edge and use the same configuration information in the future.

删除 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 模块,了解如何将模块部署到设备上。Continue to deploy IoT Edge modules to learn how to deploy modules onto your device.