使用 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 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 中心的设置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 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: