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

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. 在本文中,将使用 Powershell 创建群集和数据库。In this article, you create a cluster and a database by using Powershell. 可以在 Windows、Linux 或 Azure CLI 中使用 Az.Kusto 运行 PowerShell cmdlet 和脚本,以创建和配置 Azure 数据资源管理器群集和数据库。You can run PowerShell cmdlets and scripts on Windows, Linux, or in Azure CLI with Az.Kusto to create and configure Azure Data Explorer clusters and databases.

必备条件Prerequisites

备注

本文进行了更新,以便使用新的 Azure PowerShell Az 模块。This article has been updated to use the new Azure PowerShell Az module. 你仍然可以使用 AzureRM 模块,至少在 2020 年 12 月之前,它将继续接收 bug 修补程序。You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. 若要详细了解新的 Az 模块和 AzureRM 兼容性,请参阅新 Azure Powershell Az 模块简介To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. 有关 Az 模块安装说明,请参阅安装 Azure PowerShellFor Az module installation instructions, see Install Azure PowerShell.

如果没有 Azure 订阅,请在开始前创建一个试用帐户If you don't have an Azure subscription, 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 the Azure CLI.

配置参数Configure parameters

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

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

    Connect-AzAccount -EnvironmentName AzureChinaCloud
    
  2. 设置要在其中创建群集的订阅:Set the subscription where you want your cluster to be created:

     Set-AzContext -SubscriptionId "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
    
  3. 在本地或 Azure Powershell 中运行 Azure CLI 时,需要在设备上安装 Az.Kusto 模块:When running Azure CLI locally or in the Azure Powershell, you need to install the Az.Kusto module on your device:

     Install-Module -Name Az.Kusto
    

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

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

     New-AzKustoCluster -ResourceGroupName testrg -Name mykustocluster -Location 'China East 2' -Sku D13_v2 -Capacity 10
    
    设置Setting 建议的值Suggested value 字段说明Field description
    名称Name mykustocluster mykustocluster 所需的群集名称。The desired name of your cluster.
    SKUSku D13_v2D13_v2 将用于群集的 SKU。The SKU that will be used for your cluster.
    ResourceGroupNameResourceGroupName testrgtestrg 将在其中创建群集的资源组名称。The resource group name 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:

    Get-AzKustoCluster -Name mykustocluster -ResourceGroupName 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:

    New-AzKustoDatabase -ResourceGroupName testrg -ClusterName mykustocluster -Name mykustodatabase -SoftDeletePeriod 3650:00:00:00 -HotCachePeriod 3650:00:00:00
    
    设置Setting 建议的值Suggested value 字段说明Field description
    ClusterNameClusterName mykustocluster mykustocluster 将在其中创建数据库的群集的名称。The name of your cluster where the database will be created.
    名称Name mykustodatabase mykustodatabase 数据库名称。The name of your database.
    ResourceGroupNameResourceGroupName testrgtestrg 将在其中创建群集的资源组名称。The resource group name where the cluster will be created.
    SoftDeletePeriodSoftDeletePeriod 3650:00:00:003650:00:00:00 供查询使用的数据的保留时间。The amount of time that data will be kept available to query.
    HotCachePeriodHotCachePeriod 3650:00:00:003650:00:00:00 数据将在缓存中保留的时间。The amount of time that data will be kept in cache.
  2. 若要查看已创建的数据库,请运行以下命令:Run the following command to see the database that you created:

    Get-AzKustoDatabase -ClusterName mykustocluster -ResourceGroupName testrg -Name mykustodatabase
    

现在,你有了一个群集和一个数据库。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:

    Remove-AzKustoCluster -ResourceGroupName testrg -Name mykustocluster
    

后续步骤Next steps