快速入门:使用 Azure 门户设置 IoT 中心设备预配服务Quickstart: Set up the IoT Hub Device Provisioning Service with the Azure portal

IoT 中心设备预配服务可以与 IoT 中心配合使用,无需人为干预即可零接触实时预配至所需 IoT 中心,客户可以采用安全且可缩放的方式预配数百万台 IoT 设备。The IoT Hub Device Provisioning Service can be used with IoT Hub to enable zero-touch, just-in-time provisioning to the desired IoT hub without requiring human intervention, enabling customers to provision millions of IoT devices in a secure and scalable manner. Azure IoT 中心设备预配服务支持使用 TPM、对称密钥和 x.509 证书身份验证的 IoT 设备。Azure IoT Hub Device Provisioning Service supports IoT devices with TPM, symmetric key and X.509 certificate authentications. 有关详细信息,请参阅IoT 中心设备预配服务概述For more information, please refer to IoT Hub Device Provisioning Service overview

本快速入门介绍如何在 Azure 门户中设置 IoT 中心设备预配服务,以便预配设备,步骤如下:In this quickstart, you will learn how to set up the IoT Hub Device Provisioning Service in the Azure Portal for provisioning your devices with the following steps:

  • 使用 Azure 门户创建 IoT 中心Use the Azure portal to create an IoT Hub
  • 使用 Azure 门户创建 IoT 中心设备预配服务并获取 ID 范围Use the Azure portal to create an IoT Hub Device Provisioning Service and get the ID scope
  • 将 IoT 中心链接到设备预配服务Link the IoT hub to the Device Provisioning Service

如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

创建 IoT 中心Create an IoT hub

此部分介绍如何使用 Azure 门户创建 IoT 中心。This section describes how to create an IoT hub using the Azure portal.

  1. 登录到 Azure 门户Sign in to the Azure portal.

  2. 从 Azure 主页中选择“+ 创建资源”按钮,然后在“搜索市场”字段中输入“IoT 中心”。 From the Azure homepage, select the + Create a resource button, and then enter IoT Hub in the Search the Marketplace field.

  3. 在搜索结果中选择“IoT 中心”,然后选择“创建” 。Select IoT Hub from the search results, and then select Create.

  4. 在“基本信息”选项卡上,按如下所示填写字段: On the Basics tab, complete the fields as follows:

    • 订阅:选择要用于中心的订阅。Subscription: Select the subscription to use for your hub.

    • 资源组:选择一个资源组或新建一个资源组。Resource Group: Select a resource group or create a new one. 若要新建资源组,请选择“新建”并填写要使用的名称。 To create a new one, select Create new and fill in the name you want to use. 若要使用现有的资源组,请选择它。To use an existing resource group, select that resource group. 有关详细信息,请参阅管理 Azure 资源管理器资源组For more information, see Manage Azure Resource Manager resource groups.

    • 区域:选择中心所在的区域。Region: Select the region in which you want your hub to be located. 选择最靠近你的位置。Select the location closest to you.

    • IoT 中心名称:输入中心的名称。IoT Hub Name: Enter a name for your hub. 此名称必须全局唯一。This name must be globally unique. 如果输入的名称可用,会显示一个绿色复选标记。If the name you enter is available, a green check mark appears.

    重要

    IoT 中心将公开为 DNS 终结点,因此,命名时请务必避免包含任何敏感信息。The IoT hub will be publicly discoverable as a DNS endpoint, so make sure to avoid any sensitive information while naming it.

    在 Azure 门户中创建中心

  5. 在完成时选择“下一步: 大小和规模”,以继续创建中心。Select Next: Size and scale to continue creating your hub.

    使用 Azure 门户为新的中心设置大小和规模

    在此屏幕中可以设置以下值:This screen allows you to set the following values:

    • 定价和缩放层:选择的层。Pricing and scale tier: Your selected tier. 可以根据你需要的功能数以及每天通过解决方案发送的消息数从多个层级中进行选择。You can choose from several tiers, depending on how many features you want and how many messages you send through your solution per day. 免费层适用于测试和评估。The free tier is intended for testing and evaluation. 允许 500 台设备连接到中心,每天最多可传输 8,000 条消息。It allows 500 devices to be connected to the hub and up to 8,000 messages per day. 每个 Azure 订阅可以在免费层中创建一个 IoT 中心。Each Azure subscription can create one IoT Hub in the free tier.

    • IoT 中心单元:每个单位每日允许的消息数取决于中心的定价层。IoT Hub units: The number of messages allowed per unit per day depends on your hub's pricing tier. 例如,如果希望中心支持 700,000 条消息引入,请选择两个 S1 层单位。For example, if you want the hub to support ingress of 700,000 messages, you choose two S1 tier units. 有关其他层选项的详细信息,请参阅选择合适的 IoT 中心层For details about the other tier options, see Choosing the right IoT Hub tier.

    • 高级设置 > 设备到云的分区:此属性将设备到云消息与这些消息的同步读取器数目相关联。Advanced Settings > Device-to-cloud partitions: This property relates the device-to-cloud messages to the number of simultaneous readers of the messages. 大多数中心只需要 4 个分区。Most hubs need only four partitions.

  6. 对于本文,请接受默认选项,然后选择“查看 + 创建”以查看所做的选择。 For this article, accept the default choices, and then select Review + create to review your choices. 会显示类似于以下的屏幕。You see something similar to this screen.

    查看用于创建新中心的信息

  7. 选择“创建”以创建新的中心 。Select Create to create your new hub. 创建中心需要几分钟时间。Creating the hub takes a few minutes.

创建新的 IoT 中心设备预配服务Create a new IoT Hub Device Provisioning Service

  1. 再次选择“+ 创建资源” 按钮。Select the + Create a resource button again.

  2. 在市场中搜索“设备预配服务” 。Search the Marketplace for the Device Provisioning Service. 选择“IoT 中心设备预配服务”,然后点击“创建”按钮 Select IoT Hub Device Provisioning Service and hit the Create button.

  3. 提供新的设备预配服务实例的以下信息,然后点击“创建” 。Provide the following information for your new Device Provisioning Service instance and hit Create.

    • 名称: 为新的设备预配服务实例提供一个唯一名称。Name: Provide a unique name for your new Device Provisioning Service instance. 如果输入的名称可用,会显示一个绿色复选标记。If the name you enter is available, a green check mark appears.

    • 订阅: 选择要用来创建此设备预配服务实例的订阅。Subscription: Choose the subscription that you want to use to create this Device Provisioning Service instance.

    • 资源组: 此字段允许你创建新的资源组,或选择现有资源组来包含新实例。Resource group: This field allows you to create a new resource group, or choose an existing one to contain the new instance. 选择包含你之前创建的 IoT 中心的同一资源组,例如 TestResourcesChoose the same resource group that contains the Iot hub you created above, for example, TestResources. 通过将所有相关资源都放在一个组中,可以一起管理它们。By putting all related resources in a group together, you can manage them together. 例如,删除资源组会删除包含在该组中的所有资源。For example, deleting the resource group deletes all resources contained in that group. 有关详细信息,请参阅管理 Azure 资源管理器资源组For more information, see Manage Azure Resource Manager resource groups.

    • 位置: 选择离你的设备最近的位置。Location: Select the closest location to your devices.

      在门户边栏选项卡中输入有关设备预配服务实例的基本信息

  4. 选择通知按钮可监视资源实例的创建过程。Select the notification button to monitor the creation of the resource instance. 成功部署服务以后,请选择“固定到仪表板”,然后选择“转到资源” 。Once the service is successfully deployed, select Pin to dashboard, and then Go to resource.

    监视部署通知

在本部分中,你将向设备预配服务实例添加配置。In this section, you will add a configuration to the Device Provisioning Service instance. 此配置设置将为其预配设备的 IoT 中心。This configuration sets the IoT hub for which devices will be provisioned.

  1. 在 Azure 门户的左侧菜单中选择“所有资源”按钮 。Select the All resources button from the left-hand menu of the Azure portal. 选择在上一部分创建的设备预配服务实例。Select the Device Provisioning Service instance that you created in the preceding section.

    如果菜单是使用浮出控件而不是门户设置中的停靠模式配置的,则需要单击左上角的 3 行才能打开左侧的门户菜单。If your menu is configured using Flyout instead of the Docked mode in the portal settings, you will need to click the 3 lines at the top left to open the portal menu on the left.

  2. 在设备预配服务的菜单中,选择“链接的 IoT 中心” 。From the Device Provisioning Service's menu, select Linked IoT hubs. 点击顶部的“+ 添加”按钮 。Hit the + Add button seen at the top.

  3. 在“添加 IoT 中心的链接” 页面上,提供以下信息来将新的设备预配服务实例链接到 IoT 中心。On the Add link to IoT hub page, provide the following information to link your new Device Provisioning Service instance to an IoT hub. 然后单击“保存” 。Then hit Save.

    • 订阅: 选择包含要与新的设备预配服务实例进行链接的 IoT 中心的订阅。Subscription: Select the subscription containing the IoT hub that you want to link with your new Device Provisioning Service instance.

    • IoT 中心: 选择要与新的设备预配服务实例进行链接的 IoT 中心。Iot hub: Select the IoT hub to link with your new Device Provisioning Service instance.

    • 访问策略: 选择“iothubowner”作为用于与 IoT 中心建立链接的凭据 。Access Policy: Select iothubowner as the credentials for establishing the link with the IoT hub.

      链接中心名称,以便链接到门户边栏选项卡中的设备预配服务实例

  4. 此时会在“链接的 IoT 中心”边栏选项卡下看到所选中心。 Now you should see the selected hub under the Linked IoT hubs blade. 可能需要点击“刷新”才能显示此内容 。You might need to hit Refresh for it to show up.

清理资源Clean up resources

本教程系列中的其他快速入门教程是在本文的基础上制作的。Other quickstarts in this collection build upon this quickstart. 如果打算继续学习后续的快速入门或相关教程,请不要清除在本快速入门中创建的资源。If you plan to continue on to work with subsequent quickstarts or with the tutorials, do not clean up the resources created in this quickstart. 如果不打算继续,请在 Azure 门户中执行以下步骤来删除此快速入门创建的所有资源。If you do not plan to continue, use the following steps to delete all resources created by this quickstart in the Azure portal.

  1. 在 Azure 门户的左侧菜单中选择“所有资源”,然后选择设备预配服务 。From the left-hand menu in the Azure portal, select All resources and then select your Device Provisioning Service. 在设备详细信息窗格顶部,选择“删除” 。At the top of the device detail pane, select Delete.
  2. 在 Azure 门户的左侧菜单中选择“所有资源”,然后选择 IoT 中心 。From the left-hand menu in the Azure portal, select All resources and then select your IoT hub. 在中心详细信息窗格顶部,选择“删除” 。At the top of the hub detail pane, select Delete.

后续步骤Next steps

在本快速入门中,你已部署 IoT 中心和设备预配服务实例,并链接了这两个资源。In this quickstart, you’ve deployed an IoT hub and a Device Provisioning Service instance, and linked the two resources. 若要了解如何使用此设置来预配模拟设备,请继续学习本快速入门中关于如何创建模拟设备的内容。To learn how to use this setup to provision a simulated device, continue to the quickstart for creating a simulated device.