使用 Azure CLI 创建 Azure 数据资源管理器群集和数据库Create an Azure Data Explorer cluster and database by using Azure CLI

Azure 数据资源管理器是一项快速、完全托管的数据分析服务,用于实时分析从应用程序、网站和 IoT 设备等资源流式传输的海量数据。Azure Data Explorer is a fast, fully managed data analytics service for real-time analysis on large volumes of data streaming from applications, websites, IoT devices, and more. 若要使用 Azure 数据资源管理器,请先创建群集,再在该群集中创建一个或多个数据库。To use Azure Data Explorer, you first create a cluster, and create one or more databases in that cluster. 然后将数据引入(加载)到数据库,以便对其运行查询。Then you ingest (load) data into a database so that you can run queries against it. 在本文中,将使用 Azure CLI 创建群集和数据库。In this article, you create a cluster and a database by using Azure CLI.

先决条件Prerequisites

若要完成本文,需要 Azure 订阅。To complete this article, you need an Azure subscription. 如果没有订阅,请在开始之前创建一个试用帐户If you don't have one, trial account before you begin.

如果选择在本地安装并使用 Azure CLI,本文需要 Azure CLI 2.0.4 或更高版本。If you choose to install and use the Azure CLI locally, this article requires the Azure CLI version 2.0.4 or later. 请运行 az --version 检查版本。Run az --version to check your version. 如果需要进行安装或升级,请参阅安装 Azure CLIIf you need to install or upgrade, see Install Azure CLI.

配置 CLI 参数Configure the CLI parameters

如果在 Azure CLI 中运行命令,则不需要执行以下步骤。The following steps are not required if you're running commands in Azure CLI. 如果在本地运行 CLI,请按以下步骤登录到 Azure 并设置当前订阅:If you're running the CLI locally, follow these steps to sign in to Azure and to set your current subscription:

  1. 运行以下命令来登录到 Azure:Run the following command to sign in to Azure:

    az cloud set -n AzureChinaCloud
    az login
    
  2. 设置将在其中创建群集的订阅。Set the subscription where you want your cluster to be created. MyAzureSub 替换为要使用的 Azure 订阅的名称:Replace MyAzureSub with the name of the Azure subscription that you want to use:

    az account set --subscription MyAzureSub
    

创建 Azure 数据资源管理器群集Create the Azure Data Explorer cluster

  1. 请使用以下命令创建群集:Create your cluster by using the following command:

    az kusto cluster create --name azureclitest --sku name="Standard_D13_v2" tier="Standard" --resource-group testrg --location chinaeast2
    
    设置Setting 建议的值Suggested value 字段说明Field description
    namename azureclitestazureclitest 所需的群集名称。The desired name of your cluster.
    skusku Standard_D13_v2Standard_D13_v2 将用于群集的 SKU。The SKU that will be used for your cluster. 参数:name - SKU 名称。Parameters: name - The SKU name. tier - SKU 层。tier - The SKU tier.
    resource-groupresource-group testrgtestrg 将在其中创建群集的资源组名称。The resource group name where the cluster will be created.
    locationlocation chinaeast2chinaeast2 将在其中创建群集的位置。The location where the cluster will be created.

    可以使用其他可选参数,例如群集的容量。There are additional optional parameters that you can use, such as the capacity of the cluster.

  2. 运行以下命令,检查群集是否已成功创建:Run the following command to check whether your cluster was successfully created:

    az kusto cluster show --name azureclitest --resource-group testrg
    

如果结果包含带 Succeeded 值的 provisioningState,则表示已成功创建群集。If the result contains provisioningState with the Succeeded value, then the cluster was successfully created.

在 Azure 数据资源管理器群集中创建数据库Create the database in the Azure Data Explorer cluster

  1. 请使用以下命令创建数据库:Create your database by using the following command:

    az kusto database create --cluster-name azureclitest --database-name clidatabase --resource-group testrg --read-write-database soft-delete-period=P365D hot-cache-period=P31D location=chinaeast2
    
    设置Setting 建议的值Suggested value 字段说明Field description
    cluster-namecluster-name azureclitestazureclitest 将在其中创建数据库的群集的名称。The name of your cluster where the database will be created.
    database-namedatabase-name clidatabaseclidatabase 数据库名称。The name of your database.
    resource-groupresource-group testrgtestrg 将在其中创建群集的资源组名称。The resource group name where the cluster will be created.
    read-write-databaseread-write-database P365D P31D chinaeast2P365D P31D chinaeast2 数据库类型。The database type. 参数:soft-delete-period - 表示供查询使用的数据的保留时间。Parameters: soft-delete-period - Signifies the amount of time the data will be kept available to query. 有关详细信息,请参阅保留策略See retention policy for more information. hot-cache-period - 表示数据将在缓存中保留的时间。hot-cache-period - Signifies the amount of time the data will be kept in cache. 有关详细信息,请参阅缓存策略See cache policy for more information. location - 这是会在其中创建数据库的位置。location -The location where the database will be created.
  2. 若要查看已创建的数据库,请运行以下命令:Run the following command to see the database that you created:

    az kusto database show --name clidatabase --resource-group testrg --cluster-name azureclitest
    

现在,你有了一个群集和一个数据库。You now have a cluster and a database.

清理资源Clean up resources

  • 如果计划学习我们的其他文章,请保留已创建的资源。If you plan to follow our other articles, keep the resources you created.

  • 若要清理资源,请删除群集。To clean up resources, delete the cluster. 删除群集时,也会删除其中的所有数据库。When you delete a cluster, it also deletes all the databases in it. 使用以下命令删除群集:Use the following command to delete your cluster:

    az kusto cluster delete --name azureclitest --resource-group testrg
    

后续步骤Next steps