使用 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. 如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶If you don't have one, create a free account before you begin.

使用 Azure Cloud ShellUse Azure Cloud Shell

Azure Cloud Shell 是裝載於 Azure 中的互動式殼層環境,可在瀏覽器中使用。Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. 您可以使用 Bash 或 PowerShell 搭配 Cloud Shell,與 Azure 服務共同使用。You can use either Bash or PowerShell with Cloud Shell to work with Azure services. Azure Cloud Shell 已預先安裝一些命令,可讓您執行本文提到的程式碼,而不必在本機環境上安裝任何工具。You can use the Cloud Shell preinstalled commands to run the code in this article without having to install anything on your local environment.

要啟動 Azure Cloud Shell:To start Azure Cloud Shell:

選項Option 範例/連結Example/Link
選取程式碼區塊右上角的 [試試看] 。Select Try It in the upper-right corner of a code block. 選取 [試用] 並不會自動將程式碼複製到 Cloud Shell 中。Selecting Try It doesn't automatically copy the code to Cloud Shell. Azure Cloud Shell 的試試看範例
請前往 https://shell.azure.com 或選取 [啟動 Cloud Shell] 按鈕,在瀏覽器中開啟 Cloud Shell。Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser. 在新視窗中啟動 Cloud ShellLaunch Cloud Shell in a new window
選取 Azure 入口網站右上方功能表列上的 [Cloud Shell] 按鈕。Select the Cloud Shell button on the menu bar at the upper right in the Azure portal. Azure 入口網站中的 [Cloud Shell] 按鈕

若要在 Azure Cloud Shell 中執行本文中的程式碼:To run the code in this article in Azure Cloud Shell:

  1. 啟動 Cloud Shell。Start Cloud Shell.

  2. 選取程式碼區塊上的 [複製] 按鈕,複製程式碼。Select the Copy button on a code block to copy the code.

  3. 在 Windows 和 Linux 上選取 Ctrl+Shift+V;或在 macOS 上選取 Cmd+Shift+V,將程式碼貼到 Cloud Shell 工作階段中。Paste the code into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux or by selecting Cmd+Shift+V on macOS.

  4. 選取 Enter 鍵執行程式碼。Select Enter to run the code.

如果您選擇在本機安裝和使用 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.

設定 CLI 參數Configure the CLI parameters

如果您在 Azure Cloud Shell 中執行命令,則不需要執行下列步驟。The following steps are not required if you're running commands in Azure Cloud Shell. 如果您在本機執行 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 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 D11_v2 --resource-group testrg
    
    設定Setting 建議的值Suggested value 欄位描述Field description
    namename azureclitestazureclitest 所需的叢集名稱。The desired name of your cluster.
    SKUsku D13_v2D13_v2 將用於叢集的 SKU。The SKU that will be used for your cluster.
    resource-groupresource-group 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:

    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 --name clidatabase --resource-group testrg --soft-delete-period P365D --hot-cache-period P31D
    
    設定Setting 建議的值Suggested value 欄位描述Field description
    叢集名稱cluster-name azureclitestazureclitest 將在其中建立資料庫的叢集名稱。The name of your cluster where the database will be created.
    namename clidatabaseclidatabase 您的資料庫名稱。The name of your database.
    resource-groupresource-group testrgtestrg 將在其中建立叢集的資源群組名稱。The resource group name where the cluster will be created.
    soft-delete-periodsoft-delete-period P365DP365D 表示保留資料以供查詢的時間長度。Signifies the amount of time that data will be kept available to query. 如需詳細資訊,請參閱保留原則See retention policy for more information.
    hot-cache-periodhot-cache-period P31DP31D 表示資料保留在快取中的時間長度。Signifies the amount of time that data will be kept in cache. 如需詳細資訊,請參閱快取原則See cache policy for more information.
  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