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

Azure 数据资源管理器是一项快速且高度可缩放的数据探索服务,适用于日志和遥测数据。Azure Data Explorer is a fast and highly scalable data exploration service for log and telemetry data. 若要使用 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 资源管理器模板创建 Azure 数据资源管理器群集和数据库。In this article, you create an Azure Data Explorer cluster and database by using an Azure Resource Manager template. 本文介绍如何定义要部署的资源以及如何定义执行部署时指定的参数。The article shows how to define which resources are deployed and how to define parameters that are specified when the deployment is executed. 可将此模板用于自己的部署,或自定义此模板以满足要求。You can use this template for your own deployments, or customize it to meet your requirements. 有关创建模板的信息,请参阅创作 Azure 资源管理器模板For information about creating templates, see authoring Azure Resource Manager templates. 有关要在模板中使用的 JSON 语法和属性,请参阅 Microsoft.Kusto 资源类型For the JSON syntax and properties to use in a template, see Microsoft.Kusto resource types.

如果没有 Azure 订阅,请在开始前创建一个试用帐户If you don't have an Azure subscription, create a trial account before you begin.

用于创建群集和数据库的 Azure 资源管理器模板Azure Resource Manager template for cluster and database creation

本文使用现有快速入门模板In this article, you use an existing quickstart template

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "clusters_kustocluster_name": {
          "type": "string",
          "defaultValue": "[concat('kusto', uniqueString(resourceGroup().id))]",
          "metadata": {
            "description": "Name of the cluster to create"
          }
      },
      "databases_kustodb_name": {
          "type": "string",
          "defaultValue": "kustodb",
          "metadata": {
            "description": "Name of the database to create"
          }
      },
      "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
          "description": "Location for all resources."
        }
      }
  },
  "variables": {},
  "resources": [
      {
          "name": "[parameters('clusters_kustocluster_name')]",
          "type": "Microsoft.Kusto/clusters",
          "sku": {
              "name": "Standard_D13_v2",
              "tier": "Standard",
              "capacity": 2
          },
          "apiVersion": "2019-09-07",
          "location": "[parameters('location')]",
          "tags": {
            "Created By": "GitHub quickstart template"
          }
      },
      {
          "name": "[concat(parameters('clusters_kustocluster_name'), '/', parameters('databases_kustodb_name'))]",
          "type": "Microsoft.Kusto/clusters/databases",
          "apiVersion": "2019-09-07",
          "location": "[parameters('location')]",
          "dependsOn": [
              "[resourceId('Microsoft.Kusto/clusters', parameters('clusters_kustocluster_name'))]"
          ],
          "properties": {
              "softDeletePeriodInDays": 365,
              "hotCachePeriodInDays": 31
          }
      }
  ]
}

若要查找更多模板示例,请参阅 Azure 快速入门模板To find more template samples, see Azure Quickstart Templates.

部署模板并验证模板部署Deploy the template and verify template deployment

可以通过 Azure 门户powershell 部署 Azure 资源管理器模板。You can deploy the Azure Resource Manager template by using the Azure portal or using powershell.

使用 Azure 门户部署模板并验证模板部署Use the Azure portal to deploy the template and verify template deployment

  1. 若要创建群集和数据库,请使用以下按钮开始部署。To create a cluster and database, use the following button to start the deployment. 右键单击并选择“在新窗口中打开” ,以便按本文中的剩余步骤操作。Right-click and select Open in new window, so you can follow the rest of the steps in this article.

    部署到 AzureDeploy to Azure

    “部署到 Azure” 按钮将转到 Azure 门户以填写部署窗体。The Deploy to Azure button takes you to the Azure portal to fill out a deployment form.

    “部署到 Azure”

    可以使用此窗体在 Azure 门户中编辑和部署模板You can edit and deploy the template in the Azure portal by using the form.

  2. 完成“基本情况”和“设置”部分。 Complete BASICS and SETTINGS sections. 选择唯一的群集和数据库名称。Select unique cluster and database names. 创建 Azure 数据资源管理器群集和数据库需要数分钟的时间。It takes a few minutes to create an Azure Data Explorer cluster and database.

  3. 若要验证部署,请在 Azure 门户中打开资源组,找到新的群集和数据库。To verify the deployment, you open the resource group in the Azure portal to find your new cluster and database.

使用 PowerShell 部署模板并验证模板部署Use powershell to deploy the template and verify template deployment

使用 PowerShell 部署模板Deploy the template using powershell

  1. 在 Azure Powershell 中运行以下代码块。Run the following code block in Azure PowerShell.

    $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
    $location = Read-Host -Prompt "Enter the location (i.e. chinaeast2)"
    $resourceGroupName = "${projectName}rg"
    $clusterName = "${projectName}cluster"
    $parameters = @{}
    $parameters.Add("clusters_kustocluster_name", $clusterName)
    $templateUri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-kusto-cluster-database/azuredeploy.json"
    New-AzResourceGroup -Name $resourceGroupName -Location $location
    New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -TemplateParameterObject $parameters
    Write-Host "Press [ENTER] to continue ..."
    
  2. 选择“复制”以复制 PowerShell 脚本。 Select Copy to copy the PowerShell script.

  3. 右键单击 shell 控制台并选择“粘贴” 。Right-click the shell console, and then select Paste. 创建 Azure 数据资源管理器群集和数据库需要数分钟的时间。It takes a few minutes to create an Azure Data Explorer cluster and database.

使用 PowerShell 验证部署Verify the deployment using PowerShell

若要验证部署,请使用以下 Azure PowerShell 脚本。To verify the deployment, use the following Azure PowerShell script. 如果 Azure PowerShell 仍处于打开状态,则无需复制/运行第一行 (Read-Host)。If the Azure PowerShell is still open, you don't need to copy/run the first line (Read-Host). 若要详细了解如何在 PowerShell 中管理 Azure 数据资源管理器资源,请阅读 Az.KustoFor more information regarding managing Azure Data Explorer resources in PowerShell, read Az.Kusto.

$projectName = Read-Host -Prompt "Enter the same project name that you used in the last procedure"

Install-Module -Name Az.Kusto
$resourceGroupName = "${projectName}rg"
$clusterName = "${projectName}cluster"

Get-AzKustoCluster -ResourceGroupName $resourceGroupName -Name $clusterName
Write-Host "Press [ENTER] to continue ..."

清理资源Clean up resources

不再需要 Azure 资源时,请通过删除资源组来清理部署的资源。When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.

使用 Azure 门户清理资源Clean up resources using the Azure portal

清理资源中的步骤删除 Azure 门户中的资源。Delete the resources in the Azure portal by following the steps in clean up resources.

使用 PowerShell 清理资源Clean up resources using PowerShell

$projectName = Read-Host -Prompt "Enter the same project name that you used in the last procedure"
$resourceGroupName = "${projectName}rg"

Remove-AzResourceGroup -ResourceGroupName $resourceGroupName

Write-Host "Press [ENTER] to continue ..."

后续步骤Next steps

将数据引入 Azure 数据资源管理器群集和数据库Ingest data into Azure Data Explorer cluster and database