使用 Azure CLI 创建 IoT 中心Create an IoT hub using the Azure CLI

本文介绍如何使用 Azure CLI 创建 IoT 中心。This article shows you how to create an IoT hub using Azure CLI.

必备条件Prerequisites

若要完成本操作说明,需要 Azure 订阅。To complete this how-to, you need an Azure subscription. 如果没有 Azure 订阅,可在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

登录并设置 Azure 帐户Sign in and set your Azure account

登录到 Azure 帐户,并选择订阅。Sign in to your Azure account and select your subscription.

  1. 在命令提示符中,运行 login 命令At the command prompt, run the login command:

    az login
    

    按照说明使用代码进行身份验证,并通过 Web 浏览器登录 Azure 帐户。Follow the instructions to authenticate using the code and sign in to your Azure account through a web browser.

创建 IoT 中心Create an IoT Hub

使用 Azure CLI 创建资源组,并添加 IoT 中心。Use the Azure CLI to create a resource group and then add an IoT hub.

  1. 创建 IoT 中心时,必须在资源组中创建它。When you create an IoT hub, you must create it in a resource group. 使用现有资源组,或运行以下命令创建资源组Either use an existing resource group, or run the following command to create a resource group:

     az group create --name {your resource group name} --location chinaeast
    

    提示

    上一示例在中国东部位置创建资源组。The previous example creates the resource group in the China East location. 可以通过运行以下命令来查看可用位置列表:You can view a list of available locations by running this command:

    az account list-locations -o table
    
  2. 运行以下命令,使用 IoT 中心的全局唯一名称在资源组中创建 IoT 中心Run the following command to create an IoT hub in your resource group, using a globally unique name for your IoT hub:

    az iot hub create --name {your iot hub name} \
       --resource-group {your resource group name} --sku S1
    

    重要

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

备注

上一命令在计费的 S1 定价层中创建 IoT 中心。The previous command creates an IoT hub in the S1 pricing tier for which you are billed. 有关详细信息,请参阅 Azure IoT 中心定价For more information, see Azure IoT Hub pricing.

删除 IoT 中心Remove an IoT Hub

可使用 Azure CLI 删除单个资源(例如 IoT 中心),或删除资源组及其所有资源(包括任何 IoT 中心)。You can use Azure CLI to delete an individual resource, such as an IoT hub, or delete a resource group and all its resources, including any IoT hubs.

若要删除 IoT 中心,请运行以下命令:To delete an IoT hub, run the following command:

az iot hub delete --name {your iot hub name} -\
  -resource-group {your resource group name}

若要删除资源组及其所有资源,请运行以下命令:To delete a resource group and all its resources, run the following command:

az group delete --name {your resource group name}

后续步骤Next steps

若要详细了解如何使用 IoT 中心,请参阅以下文章:To learn more about using an IoT hub, see the following articles: