您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

使用 Azure 门户创建 IoT 中心Create an IoT hub using the Azure portal

本文介绍如何使用 Azure 门户创建和管理 IoT 中心。This article describes how to create and manage IoT hubs using the Azure portal.

需要一个 Azure 订阅才能完成此教程中的步骤。To use the steps in this tutorial, you need an Azure subscription. 如果没有 Azure 订阅,请在开始之前创建一个免费帐户If you don't have an Azure subscription, create a free 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 中心设备流)仅适用于特定区域。Some features, such as IoT Hub device streams, are only available in specific regions. 对于这些受限功能,你必须选择受支持的区域之一。For these limited features, you must select one of the supported regions.

    • 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 终结点公开可发现,因此请务必避免在命名它时输入任何敏感信息或个人身份信息。Because the IoT hub will be publicly discoverable as a DNS endpoint, be sure to avoid entering any sensitive or personally identifiable information when you name it.

    在 Azure 门户中创建中心

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

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

    可在此处接受默认设置。You can accept the default settings here. 如果需要,可以修改以下任何字段:If desired, you can modify any of the following fields:

    • 定价和缩放层:选择的层。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 中心设备流的快速入门,请选择免费层。If you are working through a Quickstart for IoT Hub device streams, select 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.

    • Azure 安全中心:启用此功能可为 IoT 和设备添加额外的一层威胁防护。Azure Security Center: Turn this on to add an extra layer of threat protection to IoT and your devices. 此选项不可用于免费层的中心。This option is not available for hubs in the free tier. 有关此功能的详细信息,请参阅适用于 IoT 的 Azure 安全中心For more information about this feature, see Azure Security Center for IoT.

    • 高级设置 > 设备到云的分区:此属性将设备到云消息与这些消息的同步读取器数目相关联。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. 在完成时选择“下一步:标记”继续到下一屏幕。Select Next: Tags to continue to the next screen.

    标记是名称/值对。Tags are name/value pairs. 可以为多个资源和资源组分配相同的标记,以便对资源进行分类并合并计费。You can assign the same tag to multiple resources and resource groups to categorize resources and consolidate billing. 有关详细信息,请参阅使用标记来组织 Azure 资源for more information, see Use tags to organize your Azure resources.

    使用 Azure 门户为中心分配标记

  7. 在完成时选择“下一步:查看+创建”可查看选择。Select Next: Review + create to review your choices. 你会看到类似于此屏幕的内容,但其中包含创建中心时选择的值。You see something similar to this screen, but with the values you selected when creating the hub.

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

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

更改 IoT 中心的设置Change the settings of the IoT hub

通过“IoT 中心”窗格创建 IoT 中心后可以更改其设置。You can change the settings of an existing IoT hub after it's created from the IoT Hub pane.

显示了 IoT 中心设置的屏幕截图

下面是一些可以为 IoT 中心设置的属性:Here are some of the properties you can set for an IoT hub:

定价和缩放:可使用此属性迁移到其他层或设置 IoT 中心单元数。Pricing and scale: You can use this property to migrate to a different tier or set the number of IoT Hub units.

操作监视:打开或关闭不同的监视类别,如与设备到云消息或云到设备消息相关的事件的日志记录。Operations monitoring: Turn the different monitoring categories on or off, such as logging for events related to device-to-cloud messages or cloud-to-device messages.

IP 筛选器:可指定 IoT 中心会接受或拒绝的 IP 地址范围。IP Filter: Specify a range of IP addresses that will be accepted or rejected by the IoT hub.

属性:提供可在其他位置复制和使用的属性的列表,如资源 ID、资源组、位置等。Properties: Provides the list of properties that you can copy and use elsewhere, such as the resource ID, resource group, location, and so on.

共享访问策略Shared access policies

还可查看或修改共享的访问策略的列表,方法是单击“设置” 部分中的“共享访问策略” 。You can also view or modify the list of shared access policies by clicking Shared access policies in the Settings section. 这些策略定义设备与服务连接到 IoT 中心所需的权限。These policies define the permissions for devices and services to connect to IoT Hub.

单击“添加” 以打开“添加共享访问策略” 边栏选项卡。Click Add to open the Add a shared access policy blade. 可输入新的策略名称以及想要与此策略关联的权限,如下图所示:You can enter the new policy name and the permissions that you want to associate with this policy, as shown in the following figure:

显示了添加共享访问策略的屏幕截图

  • “注册表读取”和“注册表写入”策略用于向标识注册表授予读取和写入访问权限。 The Registry read and Registry write policies grant read and write access rights to the identity registry. 后端云服务使用这些权限来管理设备标识。These permissions are used by back-end cloud services to manage device identities. 选择写入选项会自动选择读取选项。Choosing the write option automatically chooses the read option.

  • “服务连接”策略授予访问服务终结点的权限。 The Service connect policy grants permission to access service endpoints. 后端云服务使用此权限发送消息和接收来自设备的消息,以及更新和读取设备孪生和模块孪生数据。This permission is used by back-end cloud services to send and receive messages from devices as well as to update and read device twin and module twin data.

  • “设备连接”策略授予使用 IoT 中心的设备端终结点发送和接收消息的权限。 The Device connect policy grants permissions for sending and receiving messages using the IoT Hub device-side endpoints. 设备使用此权限发送消息和接收来自 IoT 中心的消息、更新和读取设备孪生和模块孪生数据,以及执行文件上传。This permission is used by devices to send and receive messages from an IoT hub, update and read device twin and module twin data, and perform file uploads.

单击“创建” 将此新建策略添加到现有列表。Click Create to add this newly created policy to the existing list.

有关特定权限授予的访问权限的详细信息,请参阅 IoT 中心权限For more detailed information about the access granted by specific permissions, see IoT Hub permissions.

在 IoT 中心内注册新设备Register a new device in the IoT hub

本部分在 IoT 中心的标识注册表中创建设备标识。In this section, you create a device identity in the identity registry in your IoT hub. 设备无法连接到中心,除非它在标识注册表中具有条目。A device cannot connect to a hub unless it has an entry in the identity registry. 有关详细信息,请参阅 IoT 中心开发人员指南For more information, see the IoT Hub developer guide.

  1. 在 IoT 中心导航菜单中,打开“IoT 设备”,然后选择“新建”,在 IoT 中心添加设备 。In your IoT hub navigation menu, open IoT Devices, then select New to add a device in your IoT hub.

    在门户中创建设备标识

  2. 在“创建设备”中,提供新设备的名称(例如 myDeviceId),然后选择“保存”。In Create a device, provide a name for your new device, such as myDeviceId, and select Save. 此操作会为 IoT 中心创建设备标识。This action creates a device identity for your IoT hub.

    添加新设备

    重要

    收集的日志中可能会显示设备 ID 用于客户支持和故障排除,因此,在为日志命名时,请务必避免包含任何敏感信息。The device ID may be visible in the logs collected for customer support and troubleshooting, so make sure to avoid any sensitive information while naming it.

  3. 创建设备后,在“IoT 设备”窗格的列表中打开该设备。After the device is created, open the device from the list in the IoT devices pane. 复制“主连接字符串”以供稍后使用。Copy the Primary Connection String to use later.

    设备连接字符串

备注

IoT 中心标识注册表只存储设备标识,以启用对 IoT 中心的安全访问。The IoT Hub identity registry only stores device identities to enable secure access to the IoT hub. 它存储设备 ID 和密钥用作安全凭据,以及可用于禁用单个设备访问的启用/禁用标志。It stores device IDs and keys to use as security credentials, and an enabled/disabled flag that you can use to disable access for an individual device. 如果应用程序需要存储其他特定于设备的元数据,则应使用特定于应用程序的存储。If your application needs to store other device-specific metadata, it should use an application-specific store. 有关详细信息,请参阅 IoT 中心开发人员指南For more information, see IoT Hub developer guide.

IoT 中心的消息路由Message Routing for an IoT hub

单击“消息传送” 下的“消息路由” ,查看消息路由窗格,可在其中定义中心的路由和自定义终结点。Click Message Routing under Messaging to see the Message Routing pane, where you define routes and custom endpoints for the hub. 通过消息路由,可以管理数据从设备发送到终结点的方式。Message routing enables you to manage how data is sent from your devices to your endpoints. 第一步是添加新路由。The first step is to add a new route. 然后可以将现有的终结点添加到路由,或新建一个类型受支持的路由,例如 blob 存储类型。Then you can add an existing endpoint to the route, or create a new one of the types supported, such as blob storage.

“消息路由”窗格

路由Routes

路由是“消息路由”窗格上的第一个选项卡。Routes is the first tab on the Message Routing pane. 若要添加新路由,请单击“+”(添加) 。To add a new route, click +Add. 随即显示以下屏幕。You see the following screen.

显示了添加新路由的屏幕截图

为中心命名。Name your hub. 该名称在该中心的路由列表中必须是唯一的。The name must be unique within the list of routes for that hub.

对于“终结点” ,可从下拉列表中选择一个或新添加一个。For Endpoint, you can select one from the dropdown list, or add a new one. 在此示例中,已有存储帐户和容器。In this example, a storage account and container are already available. 若要将其添加为终结点,请单击终结点下拉列表旁的“+”(添加) 并选择“Blob 存储” 。To add them as an endpoint, click +Add next to the Endpoint dropdown and select Blob Storage. 以下屏幕显示指定存储帐户和容器的位置。The following screen shows where the storage account and container are specified.

屏幕截图显示为路由规则添加存储终结点。

单击“选取容器” 以选择存储帐户和容器。Click Pick a container to select the storage account and container. 如果已选择这些字段,会返回终结点窗格。When you have selected those fields, it returns to the Endpoint pane. 其余字段均采用默认值,并单击“创建” 创建存储帐户的终结点并将其添加到路由规则。Use the defaults for the rest of the fields and Create to create the endpoint for the storage account and add it to the routing rules.

数据源选择“设备遥测消息”。For Data source, select Device Telemetry Messages.

接下来,添加一个路由查询。Next, add a routing query. 在此示例中,具有名为 level 的应用程序属性且其值等于 critical 的消息被路由到存储帐户。In this example, the messages that have an application property called level with a value equal to critical are routed to the storage account.

屏幕截图显示保存新路由规则这一操作

单击“保存” 以保存路由规则。Click Save to save the routing rule. 随即返回消息路由窗格,并显示新的路由规则。You return to the Message Routing pane, and your new routing rule is displayed.

自定义终结点Custom endpoints

单击“自定义终结点” 选项卡。会显示所有已创建的自定义终结点。Click the Custom endpoints tab. You see any custom endpoints already created. 在此处,可添加新的终结点或删除现有终结点。From here, you can add new endpoints or delete existing endpoints.

备注

如果删除一个路由,不会删除分配到该路由的终结点。If you delete a route, it does not delete the endpoints assigned to that route. 若要删除终结点,单击“自定义终结点”选项卡,选择要删除的终结点并单击“删除”。To delete an endpoint, click the Custom endpoints tab, select the endpoint you want to delete, and click Delete.

有关自定义终结点的详细信息,请阅读参考 - IoT 中心终结点You can read more about custom endpoints in Reference - IoT hub endpoints.

可为一个 IoT 中心定义最多 10 个自定义终结点。You can define up to 10 custom endpoints for an IoT hub.

若要查看如何结合使用自定义终结点和路由的完整示例,请参阅IoT 中心消息路由To see a full example of how to use custom endpoints with routing, see Message routing with IoT Hub.

查找特定 IoT 中心Find a specific IoT hub

下面是两种在订阅中查找特定 IoT 中心的方法:Here are two ways to find a specific IoT hub in your subscription:

  1. 如果知道 IoT 中心所属的资源组,单击“资源组” ,然后从列表中选择资源组。If you know the resource group to which the IoT hub belongs, click Resource groups, then select the resource group from the list. 资源组屏幕会显示组中的所有资源,包括 IoT 中心。The resource group screen shows all of the resources in that group, including the IoT hubs. 单击所查找的中心。Click on the hub for which you're looking.

  2. 单击“所有资源” 。Click All resources. 在“所有资源” 窗格上,有一个下拉列表,默认为 All typesOn the All resources pane, there is a dropdown list that defaults to All types. 单击该下拉列表,取消选中 Select allClick on the dropdown list, uncheck Select all. 查找 IoT Hub 并选中。Find IoT Hub and check it. 单击下拉列表框将其关闭,系统将筛选所含条目,并仅显示所选的 IoT 中心。Click on the dropdown list box to close it, and the entries will be filtered, showing only your IoT hubs.

删除 IoT 中心Delete the IoT hub

若要删除 IoT 中心,查找要删除的 IoT 中心,然后单击该 IoT 中心名称下的“删除” 按钮。To delete an Iot hub, find the IoT hub you want to delete, then click the Delete button below the IoT hub name.

后续步骤Next steps

若要了解有关如何管理 Azure IoT 中心的详细信息,请参阅以下链接:Follow these links to learn more about managing Azure IoT Hub: