建立 Azure 資料總管叢集與資料庫
Azure 資料總管是快速、完全受控的資料分析服務,可即時分析來自應用程式、網站、IoT 裝置等的大量資料流。 若要使用 Azure 資料總管,請先建立叢集,然後在該叢集中建立一或多個資料庫。 然後,您可以內嵌 (將數據載入資料庫) ,並對其執行查詢。
在本文中,您將瞭解如何使用 C#、Python、Go、Azure CLI、PowerShell 或 Azure Resource Manager (ARM) 範本來建立叢集和資料庫。 若要瞭解如何使用 Azure 入口網站 建立叢集和資料庫,請參閱快速入門:建立 Azure Data Explorer 叢集和資料庫。
如需以舊版 SDK 為基礎的程式代碼範例,請參閱 封存文章。
必要條件
依叢集和資料庫建立方法的必要條件:
- Azure 訂用帳戶。 建立 Azure 免費帳戶。
- Visual Studio 2022 Community Edition。 在 Visual Studio 設定期間開啟 Azure 開發 。
- 安裝 Microsoft.Azure.Management.Kusto NuGet 套件。
- 可存取資源的 Microsoft Entra 應用程式和服務主體。 儲存 目錄 (租使用者) 識別碼、 應用程式識別碼和 客戶端密碼。
建立 Azure Data Explorer 叢集
本節會引導您完成建立 Azure Data Explorer 叢集的程式。 選擇慣用方法的相關索引標籤,以建立叢集。
使用下列程式碼建立您的叢集:
var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Directory (tenant) ID var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Application ID var clientSecret = "PlaceholderClientSecret"; //Client Secret var subscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; var credentials = new ClientSecretCredential(tenantId, clientId, clientSecret); var resourceManagementClient = new ArmClient(credentials, subscriptionId); var resourceGroupName = "testrg"; var subscription = await resourceManagementClient.GetDefaultSubscriptionAsync(); var resourceGroup = (await subscription.GetResourceGroupAsync(resourceGroupName)).Value; var clusters = resourceGroup.GetKustoClusters(); var clusterName = "mykustocluster"; var skuName = KustoSkuName.StandardE8adsV5; var skuTier = KustoSkuTier.Standard; var capacity = 5; var clusterData = new KustoClusterData( location: AzureLocation.CentralUS, sku: new KustoSku(skuName, skuTier) { Capacity = capacity } ); await clusters.CreateOrUpdateAsync(WaitUntil.Completed, clusterName, clusterData);
設定 建議的值 欄位描述 clusterName mykustocluster 所需的叢集名稱。 skuName Standard_E8ads_v5 將用於叢集的 SKU。 tier 標準 SKU 層。 處理能力 number 叢集的實例數目。 resourceGroupName testrg 將在其中建立叢集的資源群組名稱。 注意
建立叢集 是長時間執行的作業,因此強烈建議使用 CreateOrUpdateAsync,而不是 CreateOrUpdate。
執行下列命令來檢查是否已成功建立叢集:
clusterData = (await clusters.GetAsync(clusterName)).Value.Data;
確認結果包含
provisioningState
Succeeded
作為 ,以確認叢集成功建立。
建立 Azure Data Explorer 資料庫
在本節中,您將在上一節中建立的叢集內建立資料庫。
使用下列程式碼建立您的資料庫:
var cluster = (await clusters.GetAsync(clusterName)).Value; var databases = cluster.GetKustoDatabases(); var databaseName = "mykustodatabase"; var softDeletePeriod = TimeSpan.FromDays(3650); var hotCachePeriod = TimeSpan.FromDays(3650); var databaseData = new KustoReadWriteDatabase { Location = clusterData.Location, SoftDeletePeriod = softDeletePeriod, HotCachePeriod = hotCachePeriod }; await databases.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, databaseData);
注意
如果您使用 C# 2.0.0 版或更新版本,請使用 Database 而不是 ReadWriteDatabase。
設定 建議的值 欄位描述 clusterName mykustocluster 將在其中建立資料庫的叢集名稱。 databaseName mykustodatabase 您的資料庫名稱。 resourceGroupName testrg 將在其中建立叢集的資源群組名稱。 softDeletePeriod 3650:00:00:00 將保留資料以供查詢的時間長度。 hotCachePeriod 3650:00:00:00 資料將保留在快取中的時間長度。 執行下列命令以查看您所建立的資料庫:
databaseData = (await databases.GetAsync(databaseName)).Value.Data as KustoReadWriteDatabase;
後續步驟
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應