使用 Azure 资源管理器模板创建 Azure 时序见解 Gen 1 资源Create Azure Time Series Insights Gen 1 resources using Azure Resource Manager templates

本文介绍如何使用 Azure 资源管理器模板、PowerShell 和 Azure 时序见解资源提供程序创建和部署 Azure 时序见解资源。This article describes how to create and deploy Azure Time Series Insights resources using Azure Resource Manager templates, PowerShell, and the Azure Time Series Insights resource provider.

Azure 时序见解支持以下资源:Azure Time Series Insights supports the following resources:

资源Resource 说明Description
环境Environment Azure 时序见解环境是从事件中转站读取的、经存储的并可供查询使用的事件的逻辑分组。A Azure Time Series Insights environment is a logical grouping of events that are read from event brokers, stored, and made available for query. 有关详细信息,请阅读规划 Azure 时序见解环境For more information, read Plan your Azure Time Series Insights environment
事件源Event Source 事件源是与事件中转站建立的连接,Azure 时序见解从该中转站读取和引入事件至环境。An event source is a connection to an event broker from which Azure Time Series Insights reads and ingests events into the environment. 目前支持的事件源是 IoT 中心和事件中心。Currently supported event sources are IoT Hub and Event Hub.
引用数据集Reference Data Set 引用数据集提供有关环境中事件的元数据。Reference data sets provide metadata about the events in the environment. 在引入期间,引用数据集中的元数据将与事件联接。Metadata in the reference data sets will be joined with events during ingress. 引用数据集根据其事件键属性定义为资源。Reference data sets are defined as resources by their event key properties. 构成引用数据集的实际元数据通过数据平面 API 上传或修改。The actual metadata that makes up the reference data set is uploaded or modified through data plane APIs.
访问策略Access Policy 访问策略授予的权限适用于:发出数据查询、操作环境中的引用数据,以及共享已保存的与环境关联的查询和透视。Access policies grant permissions to issue data queries, manipulate reference data in the environment, and share saved queries and perspectives associated with the environment. 有关详细信息,请参阅使用 Azure 门户授予对 Azure 时序见解环境的数据访问权限For more information, read Grant data access to a Azure Time Series Insights environment using Azure portal

资源管理器模板是用于定义资源组中资源的基础结构和配置的 JSON 文件。A Resource Manager template is a JSON file that defines the infrastructure and configuration of resources in a resource group. 以下文档更详细地介绍了模板文件:The following documents describe template files in greater detail:

GitHub 上已发布 201-timeseriesinsights-environment-with-eventhub 快速入门模板。The 201-timeseriesinsights-environment-with-eventhub quickstart template is published on GitHub. 此模板创建一个 Azure 时序见解环境、一个配置为使用事件中心的事件的子事件源,以及授予环境数据访问权限的访问策略。This template creates a Azure Time Series Insights environment, a child event source configured to consume events from an Event Hub, and access policies that grant access to the environment's data. 如果未指定现有的事件中心,则会连同部署创建一个事件中心。If an existing Event Hub isn't specified, one will be created with the deployment.

备注

本文进行了更新,以便使用新的 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.

指定部署模板和参数Specify deployment template and parameters

以下过程描述如何使用 PowerShell 部署一个 Azure 资源管理器模板,该模板创建一个 Azure 时序见解环境、一个配置为使用事件中心的事件的子事件源,以及授予环境数据访问权限的访问策略。The following procedure describes how to use PowerShell to deploy an Azure Resource Manager template that creates a Azure Time Series Insights environment, a child event source configured to consume events from an Event Hub, and access policies that grant access to the environment's data. 如果未指定现有的事件中心,则会连同部署创建一个事件中心。If an existing Event Hub isn't specified, one will be created with the deployment.

  1. 按照 Azure PowerShell 入门中的说明安装 Azure PowerShell。Install Azure PowerShell by following the instructions in Getting started with Azure PowerShell.

  2. 从 GitHub 克隆或复制 201-timeseriesinsights-environment-with-eventhub 模板。Clone or copy the 201-timeseriesinsights-environment-with-eventhub template from GitHub.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "eventHubNamespaceName": {
          "value": "GEN-UNIQUE"
      },
      "eventHubName": {
          "value": "GEN-UNIQUE"
      },
      "consumerGroupName": {
          "value": "GEN-UNIQUE"
      },
      "environmentName": {
        "value": "GEN-UNIQUE"
      },
      "eventSourceName": {
        "value": "GEN-UNIQUE"
      }
  }
}
<div id="required-parameters"></div>
  • 必需的参数Required Parameters

    参数Parameter 说明Description
    eventHubNamespaceNameeventHubNamespaceName 源事件中心的命名空间。The namespace of the source event hub.
    eventHubNameeventHubName 源事件中心的名称。The name of the source event hub.
    consumerGroupNameconsumerGroupName 由 Azure 时序见解服务用来从事件中心读取数据的使用者组的名称。The name of the consumer group that the Azure Time Series Insights service will use to read the data from the event hub. 注意: 为了避免资源争用,此使用者组必须专门用于 Azure 时序见解服务,而不能与其他读者共享。NOTE: To avoid resource contention, this consumer group must be dedicated to the Azure Time Series Insights service and not shared with other readers.
    environmentNameenvironmentName 环境的名称。The name of the environment. 此名称不能包含:<>%&:\\?/ 和任何控制字符。The name cannot include: <, >, %, &, :, \\, ?, /, and any control characters. 允许其他所有字符。All other characters are allowed.
    eventSourceNameeventSourceName 事件源子资源的名称。The name of the event source child resource. 此名称不能包含:<>%&:\\?/ 和任何控制字符。The name cannot include: <, >, %, &, :, \\, ?, /, and any control characters. 允许其他所有字符。All other characters are allowed.
<div id="optional-parameters"></div>
  • 可选参数Optional Parameters

    参数Parameter 说明Description
    existingEventHubResourceIdexistingEventHubResourceId 要通过事件源连接到 Azure 时序见解环境的现有事件中心的可选资源 ID。An optional resource ID of an existing Event Hub that will be connected to the Azure Time Series Insights environment through the event source. 注意: 部署模板的用户必须有权对事件中心执行 listkeys 操作。NOTE: The user deploying the template must have privileges to perform the listkeys operation on the Event Hub. 如果未传递任何值,则模板会创建新的事件中心。If no value is passed, a new event hub will be created by the template.
    environmentDisplayNameenvironmentDisplayName 要在工具或用户界面中显示的可选友好名称,而不是环境名称。An optional friendly name to show in tooling or user interfaces instead of the environment name.
    environmentSkuNameenvironmentSkuName SKU 的名称。The name of the sku. 有关详细信息,请阅读“Azure 时序见解定价”页For more information, read the Azure Time Series Insights Pricing page.
    environmentSkuCapacityenvironmentSkuCapacity SKU 的单位容量。The unit capacity of the Sku. 有关详细信息,请阅读“Azure 时序见解定价”页For more information, read the Azure Time Series Insights Pricing page.
    environmentDataRetentionTimeenvironmentDataRetentionTime 环境事件可供查询的最小时间跨度。The minimum timespan the environment’s events will be available for query. 必须以 ISO 8601 格式指定该值,例如 P30D 表示保留策略为 30 天。The value must be specified in the ISO 8601 format, for example P30D for a retention policy of 30 days.
    eventSourceDisplayNameeventSourceDisplayName 要在工具或用户界面中显示的可选友好名称,而不是事件源名称。An optional friendly name to show in tooling or user interfaces instead of the event source name.
    eventSourceTimestampPropertyNameeventSourceTimestampPropertyName 用作事件源时间戳的事件属性。The event property that will be used as the event source's timestamp. 如果未为 timestampPropertyName 指定值,或者指定 null 或空字符串,则会使用事件创建时间。If a value isn't specified for timestampPropertyName, or if null or empty-string is specified, the event creation time will be used.
    eventSourceKeyNameeventSourceKeyName 由 Azure 时序见解服务用来连接到事件中心的共享访问密钥的名称。The name of the shared access key that the Azure Time Series Insights service will use to connect to the event hub.
    accessPolicyReaderObjectIdsaccessPolicyReaderObjectIds Azure AD 中应该对环境拥有“读取者”访问权限的用户或应用程序的对象 ID 列表。A list of object IDs of the users or applications in Azure AD that should have Reader access to the environment. 可以通过调用 Get-AzADUser 或 Get-AzADServicePrincipal cmdlet 获取服务主体 objectId。The service principal objectId can be obtained by calling the Get-AzADUser or the Get-AzADServicePrincipal cmdlets. 目前不支持创建 Azure AD 组的访问策略。Creating an access policy for Azure AD groups is not yet supported.
    accessPolicyContributorObjectIdsaccessPolicyContributorObjectIds Azure AD 中应该对环境拥有“参与者”访问权限的用户或应用程序的对象 ID 列表。A list of object IDs of the users or applications in Azure AD that should have Contributor access to the environment. 可以通过调用 Get-AzADUser 或 Get-AzADServicePrincipal cmdlet 获取服务主体 objectId。The service principal objectId can be obtained by calling the Get-AzADUser or the Get-AzADServicePrincipal cmdlets. 目前不支持创建 Azure AD 组的访问策略。Creating an access policy for Azure AD groups is not yet supported.
  • 例如,以下参数文件将用于创建环境,以及可从现有事件中心读取事件的事件源。As an example, the following parameters file would be used to create an environment and an event source that reads events from an existing event hub. 此外,它会创建两个访问策略,用于授予对环境的“参与者”访问权限。It also creates two access policies that grant Contributor access to the environment.

    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "eventHubNamespaceName": {
                "value": "tsiTemplateTestNamespace"
            },
            "eventHubName": {
                "value": "tsiTemplateTestEventHub"
            },
            "consumerGroupName": {
                "value": "tsiTemplateTestConsumerGroup"
            },
            "environmentName": {
                "value": "tsiTemplateTestEnvironment"
            },
            "eventSourceName": {
                "value": "tsiTemplateTestEventSource"
            },
            "existingEventHubResourceId": {
                "value": "/subscriptions/{yourSubscription}/resourceGroups/MyDemoRG/providers/Microsoft.EventHub/namespaces/tsiTemplateTestNamespace/eventhubs/tsiTemplateTestEventHub"
            },
            "accessPolicyContributorObjectIds": {
                "value": [
                    "AGUID001-0000-0000-0000-000000000000",
                    "AGUID002-0000-0000-0000-000000000000"
                ]
            }    
        }
    }
    
* <span data-ttu-id="b6409-190">有关详细信息,请阅读[参数](../azure-resource-manager/templates/parameter-files.md)一文。</span><span class="sxs-lookup"><span data-stu-id="b6409-190">For more information, read the [Parameters](../azure-resource-manager/templates/parameter-files.md) article.</span></span>

使用 PowerShell 在本地部署快速入门模板Deploy the quickstart template locally using PowerShell

重要

下面显示的命令行操作描述 Az PowerShell 模块The command-line operations displayed below describe the Az PowerShell module.

  1. 在 PowerShell 中,登录到 Azure 帐户。In PowerShell, log in to your Azure account.

    • 在 PowerShell 提示符下,运行以下命令:From a PowerShell prompt, run the following command:

      Connect-AzAccount -Environment AzureChinaCloud
      
    • 系统会提示登录到 Azure 帐户。You are prompted to log on to your Azure account. 登录后,运行以下命令以查看可用订阅:After logging on, run the following command to view your available subscriptions:

      Get-AzSubscription
      
    • 此命令返回可用 Azure 订阅的列表。This command returns a list of available Azure subscriptions. 通过运行以下命令为当前会话选择订阅。Choose a subscription for the current session by running the following command. <YourSubscriptionId> 替换为要使用的 Azure 订阅的 GUID:Replace <YourSubscriptionId> with the GUID for the Azure subscription you want to use:

      Set-AzContext -SubscriptionID <YourSubscriptionId>
      
  2. 创建新资源组(如果不存在)。Create a new resource group if one does not exist.

    • 如果目前没有资源组,请使用 New-AzResourceGroup 命令创建新的资源组。If you do not have an existing resource group, create a new resource group with the New-AzResourceGroup command. 提供资源组的名称,以及要使用的位置。Provide the name of the resource group and location you want to use. 例如:For example:

      New-AzResourceGroup -Name MyDemoRG -Location "China East 2"
      
    • 如果成功,则会显示新的资源组的摘要。If successful, a summary of the new resource group is displayed.

      ResourceGroupName : MyDemoRG
      Location          : chinaeast2
      ProvisioningState : Succeeded
      Tags              :
      ResourceId        : /subscriptions/<GUID>/resourceGroups/MyDemoRG
      
  3. 测试部署。Test the deployment.

    • 通过运行 Test-AzResourceGroupDeployment cmdlet 验证部署。Validate your deployment by running the Test-AzResourceGroupDeployment cmdlet. 测试部署时,请提供与执行部署时所提供的完全相同的参数。When testing the deployment, provide parameters exactly as you would when executing the deployment.

      Test-AzResourceGroupDeployment -ResourceGroupName MyDemoRG -TemplateFile <path to template file>\azuredeploy.json -TemplateParameterFile <path to parameters file>\azuredeploy.parameters.json
      
  4. 创建部署Create the deployment

    • 若要创建新部署,请运行 New-AzResourceGroupDeployment cmdlet,并在出现提示时提供必需的参数。To create the new deployment, run the New-AzResourceGroupDeployment cmdlet, and provide the necessary parameters when prompted. 参数包括部署的名称、资源组的名称,以及模板文件的路径或 URL。The parameters include a name for your deployment, the name of your resource group, and the path or URL to the template file. 如果未指定 Mode 参数,将使用 Incremental 的默认值。If the Mode parameter is not specified, the default value of Incremental is used. 有关详细信息,请阅读增量部署和完整部署For more information, read Incremental and complete deployments.

    • 以下命令提示在 PowerShell 窗口中输入五个必需的参数:The following command prompts you for the five required parameters in the PowerShell window:

      New-AzResourceGroupDeployment -Name MyDemoDeployment -ResourceGroupName MyDemoRG -TemplateFile <path to template file>\azuredeploy.json
      
    • 若要改为指定参数文件,请使用以下命令:To specify a parameters file instead, use the following command:

      New-AzResourceGroupDeployment -Name MyDemoDeployment -ResourceGroupName MyDemoRG -TemplateFile <path to template file>\azuredeploy.json -TemplateParameterFile <path to parameters file>\azuredeploy.parameters.json
      
    • 运行部署 cmdlet 时,还可以使用内联参数。You can also use inline parameters when you run the deployment cmdlet. 该命令如下所示:The command is as follows:

      New-AzResourceGroupDeployment -Name MyDemoDeployment -ResourceGroupName MyDemoRG -TemplateFile <path to template file>\azuredeploy.json -parameterName "parameterValue"
      
    • 要运行完整部署,请将 Mode 参数设置为 CompleteTo run a complete deployment, set the Mode parameter to Complete:

      New-AzResourceGroupDeployment -Name MyDemoDeployment -Mode Complete -ResourceGroupName MyDemoRG -TemplateFile <path to template file>\azuredeploy.json
      
  5. 验证部署Verify the deployment

    • 如果资源已成功部署,会在 PowerShell 窗口中显示部署的摘要:If the resources are deployed successfully, a summary of the deployment is displayed in the PowerShell window:

       DeploymentName          : MyDemoDeployment
       ResourceGroupName       : MyDemoRG
       ProvisioningState       : Succeeded
       Timestamp               : 10/11/2019 3:20:37 AM
       Mode                    : Incremental
       TemplateLink            :
       Parameters              :
                                 Name                                Type                       Value
                                 ==================================  =========================  ==========
                                 eventHubNewOrExisting               String                     new
                                 eventHubResourceGroup               String                     MyDemoRG
                                 eventHubNamespaceName               String                     tsiquickstartns
                                 eventHubName                        String                     tsiquickstarteh
                                 consumerGroupName                   String                     tsiquickstart
                                 environmentName                     String                     tsiquickstart
                                 environmentDisplayName              String                     tsiquickstart
                                 environmentSkuName                  String                     S1
                                 environmentSkuCapacity              Int                        1
                                 environmentDataRetentionTime        String                     P30D
                                 eventSourceName                     String                     tsiquickstart
                                 eventSourceDisplayName              String                     tsiquickstart
                                 eventSourceTimestampPropertyName    String
                                 eventSourceKeyName                  String                     manage
                                 accessPolicyReaderObjectIds         Array                      []
                                 accessPolicyContributorObjectIds    Array                      []
                                 location                            String                     chinaeast2
      
       Outputs                 :
                                  Name              Type                       Value
                                  ================  =========================  ==========
                                  dataAccessFQDN    String
                                  11aa1aa1-a1aa-1a1a-a11a-aa111a111a11.env.timeseries.azure.com
      
       DeploymentDebugLogLevel :
      
  6. 通过 Azure 门户部署快速入门模板Deploy the quickstart template through the Azure portal

    • GitHub 上的快速入门模板主页还包含“部署到 Azure”按钮。The quickstart template's home page on GitHub also includes a Deploy to Azure button. 单击此按钮可在 Azure 门户中打开“自定义部署”页。Clicking it opens a Custom Deployment page in the Azure portal. 从此页中,可以输入或选择必需的参数可选参数表中每个参数的值。From this page, you can enter or select values for each of the parameters from the required parameters or optional parameters tables. 填写设置后,单击“购买”按钮会启动模板部署。After filling out the settings, clicking the Purchase button will initiate the template deployment.

      The Deploy to Azure button.

后续步骤Next steps