使用 Azure Resource Manager 範本建立 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 Resource Manager 範本來建立 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 Resource Manager 範本For information about creating templates, see authoring Azure Resource Manager templates. 如需在範本中使用的 JSON 語法和屬性,請參閱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 free account before you begin.

建立叢集和資料庫的 Azure Resource Manager 範本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 Resource Manager 範本。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 Cloud Shell。Select Try it from the following code block, and then follow the instructions to sign in to the Azure Cloud shell.

    $projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
    $location = Read-Host -Prompt "Enter the location (i.e. centralus)"
    $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. 以滑鼠右鍵按一下殼層主控台,然後選取 [貼上]。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. 如果 Cloud Shell 仍為開啟狀態,您就不需要複製/執行第一行(讀取主機)。If the Cloud Shell 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

如果 Cloud Shell 仍為開啟狀態,您就不需要複製/執行第一行(讀取主機)。If the Cloud Shell is still open, you don't need to copy/run the first line (Read-Host).

$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