教程:使用资源管理器模板部署 Azure 机器学习工作区Tutorial: Deploy an Azure machine learning workspace using a Resource Manager template

适用于:是基本版是企业版               (升级到企业版APPLIES TO: yesBasic edition yesEnterprise edition                    (Upgrade to Enterprise edition)

本教程演示如何使用 Azure 资源管理器模板创建 Azure 机器学习工作区。This tutorial will show you how to create an Azure machine learning workspace using an Azure Resource Manager template. Azure 机器学习工作区可将你的所有机器学习资产从基线数据集组织到已部署的模型中。Azure machine learning workspaces organize all your machine learning assets from baseline datasets to deployed models. 工作区是一个单一位置,可供你与同事合作创建、运行和查看试验,管理训练和推理计算资源,以及对部署的模型进行监视和版本控制。Workspaces are a single location to collaborate with colleagues on creating, running, and reviewing experiments, manage your training and inferencing compute resources, and monitor and version deployed models.

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

先决条件Prerequisites

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

  • 若要从本地环境**** 使用本文档中的 CLI 命令,需要使用 Azure CLITo use the CLI commands in this document from your local environment, you need the Azure CLI

创建工作区Create a workspace

查看模板Review the template

本快速入门中使用的模板来自 Azure 快速启动模板The template used in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "workspaceName": {
        "type": "string",
        "metadata": {
          "description": "Specifies the name of the Azure Machine Learning workspace."
        }
      },
      "location": {
        "type": "string",
        "allowedValues": [
            "chinaeast",
            "chinaeast2",
            "chinanorth",
            "chinanorth2"
        ],
        "metadata": {
          "description": "Specifies the location for all resources."
        }
      },
      "sku": {
        "type": "string",
        "defaultValue": "basic",
        "allowedValues": [
          "basic",
          "enterprise"
        ],
        "metadata": {
          "description": "Specifies the sku, also referred as 'edition' of the Azure Machine Learning workspace."
        }
      },
      "storageAccountNewOrExisting": {
        "type": "string",
        "defaultValue": "new",
        "allowedValues": [
          "new",
          "existing"
        ]
      },
      "storageAccountName": {
        "type": "string",
        "defaultValue": "[concat('sa',uniqueString(resourceGroup().id))]"
      },
      "storageAccountType": {
        "type": "string",
        "defaultValue": "Standard_LRS",
        "allowedValues": [
          "Standard_LRS",
          "Standard_GRS",
          "Standard_RAGRS",
          "Standard_ZRS",
          "Premium_LRS",
          "Premium_ZRS",
          "Standard_GZRS",
          "Standard_RAGZRS"
        ]
      },
      "storageAccountResourceGroupName": {
        "type": "string",
        "defaultValue": "[resourceGroup().name]"
      },
      "keyVaultNewOrExisting": {
        "type": "string",
        "defaultValue": "new",
        "allowedValues": [
          "new",
          "existing"
        ],
        "metadata": {
          "description": "Determines whether or not a key vault should be provisioned."
        }
      },
      "keyVaultName": {
        "type": "string",
        "defaultValue": "[concat('kv',uniqueString(resourceGroup().id))]"
      },
      "keyVaultResourceGroupName": {
        "type": "string",
        "defaultValue": "[resourceGroup().name]"
      },
      "applicationInsightsNewOrExisting": {
        "type": "string",
        "defaultValue": "new",
        "allowedValues": [
          "new",
          "existing"
        ]
      },
      "applicationInsightsName": {
        "type": "string",
        "defaultValue": "[concat('ai',uniqueString(resourceGroup().id))]"
      },
      "applicationInsightsResourceGroupName": {
        "type": "string",
        "defaultValue": "[resourceGroup().name]"
      },
      "containerRegistry": {
        "type": "string",
        "defaultValue": "",
        "metadata": {
          "description": "The container registry resource id if you want to create a link to the workspace."
        }
      },
       "adbWorkspace": {
        "type": "string",
        "defaultValue": "",
        "metadata": {
          "description": "Azure Databrick workspace resource id to be linked to the workspace"
        }
      },
      "confidential_data":{
        "type": "string",
        "defaultValue": "false",
          "allowedValues": [
            "false",
            "true"
          ],
          "metadata": {
            "description": "Specifies that the Azure Machine Learning workspace holds highly confidential data."
          }
      },
      "encryption_status":{
        "type": "string",
        "defaultValue": "Disabled",
          "allowedValues": [
            "Enabled",
            "Disabled"
          ],
          "metadata": {
            "description": "Specifies if the Azure Machine Learning workspace should be encrypted with customer managed key."
          }
      },
      "cmk_keyvault":{
        "type": "string",
        "defaultValue": "",
        "metadata": {
          "description": "Specifies the customer managed keyVault arm id."
        }
      },
      "resource_cmk_uri":{
        "type": "string",
        "defaultValue": "",
        "metadata": {
          "description": "Specifies if the customer managed keyvault key uri."
        }
      }
  },
  "variables": {
      "tenantId": "[subscription().tenantId]",
      "storageAccount": "[resourceId(parameters('storageAccountResourceGroupName'), 'Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
      "keyVault": "[resourceId(parameters('keyVaultResourceGroupName'), 'Microsoft.KeyVault/vaults', parameters('keyVaultName'))]",
      "applicationInsights": "[resourceId(parameters('applicationInsightsResourceGroupName'), 'Microsoft.Insights/components', parameters('applicationInsightsName'))]"
  },
  "resources": [
      {
          "condition": "[equals(parameters('storageAccountNewOrExisting'), 'new')]",
          "type": "Microsoft.Storage/storageAccounts",
          "apiVersion": "2019-04-01",
          "name": "[parameters('storageAccountName')]",
          "location": "[parameters('location')]",
          "sku": {
              "name": "[parameters('storageAccountType')]"
          },
          "kind": "StorageV2",
          "properties": {
              "encryption": {
                  "services": {
                      "blob": {
                          "enabled": true
                      },
                      "file": {
                          "enabled": true
                      }
                  },
                  "keySource": "Microsoft.Storage"
              },
              "supportsHttpsTrafficOnly": true
          }
      },
      {
          "condition": "[equals(parameters('keyVaultNewOrExisting'), 'new')]",
          "type": "Microsoft.KeyVault/vaults",
          "apiVersion": "2019-09-01",
          "name": "[parameters('keyVaultName')]",
          "location": "[parameters('location')]",
          "properties": {
              "tenantId": "[variables('tenantId')]",
              "sku": {
                  "name": "standard",
                  "family": "A"
              },
              "accessPolicies": []
          }
      },
      {
          "condition": "[equals(parameters('applicationInsightsNewOrExisting'), 'new')]",
          "type": "Microsoft.Insights/components",
          "apiVersion": "2018-05-01-preview",
          "name": "[parameters('applicationInsightsName')]",
          "location": "[if(or(equals(parameters('location'),'eastus2'), equals(parameters('location'),'westcentralus')),'southcentralus',parameters('location'))]",
          "kind": "web",
          "properties": {
              "Application_Type": "web"
          }
      },
      {
          "type": "Microsoft.MachineLearningServices/workspaces",
          "apiVersion": "2020-03-01",
          "name": "[parameters('workspaceName')]",
          "location": "[parameters('location')]",
          "dependsOn": [
              "[variables('storageAccount')]",
              "[variables('keyVault')]",
              "[variables('applicationInsights')]"
          ],
          "identity": {
              "type": "systemAssigned"
          },
          "sku": {
              "tier": "[parameters('sku')]",
              "name": "[parameters('sku')]"
          },
          "properties": {
              "friendlyName": "[parameters('workspaceName')]",
              "storageAccount": "[variables('storageAccount')]",
              "keyVault": "[variables('keyVault')]",
              "applicationInsights": "[variables('applicationInsights')]",
              "containerRegistry": "[if(empty(parameters('containerRegistry')), json('null'), parameters('containerRegistry'))]",
              "adbWorkspace": "[if(empty(parameters('adbWorkspace')), json('null'), parameters('adbWorkspace'))]",
              "encryption": {
                  "status": "[parameters('encryption_status')]",
                  "keyVaultProperties": {
                      "keyVaultArmId": "[parameters('cmk_keyvault')]",
                      "keyIdentifier": "[parameters('resource_cmk_uri')]"
                  }
              },
              "hbiWorkspace": "[parameters('confidential_data')]"
          }
      }
  ]
}

该模板中定义了以下资源:The following resources are defined in the template:

部署模板Deploy the template

若要通过 Azure CLI 使用该模板,请登录并选择你的订阅(请参阅使用 Azure CLI 登录)。To use the template from the Azure CLI, login and choose your subscription (See Sign in with Azure CLI). 运行:Then run:

read -p "Enter a project name that is used for generating resource names:" projectName &&
read -p "Enter the location (i.e. centralus):" location &&
templateUri="https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-machine-learning-create/azuredeploy.json" &&
resourceGroupName="${projectName}rg" &&
workspaceName="${projectName}ws" &&
az group create --name $resourceGroupName --location "$location" &&
az deployment group create --resource-group $resourceGroupName --template-uri $templateUri --parameters workspaceName=$workspaceName location=$location && 
echo "Press [ENTER] to continue ..." &&
read

运行上述命令时,请输入:When you run the above command, enter:

  1. 项目名称,它将作为创建的资源组和 Azure ML 工作区名称的基础A project name that will form the basis of the names of the created resource group and Azure ML workspace
  2. 要在其中进行部署的 Azure 位置The Azure location in which you wish to make the deployment

查看已部署的资源Review deployed resources

若要查看 Azure ML 工作区,请执行以下操作:To see your Azure ML workspace:

  1. 转到 https://portal.azure.cnGo to https://portal.azure.cn
  2. 登录Sign in
  3. 选择刚创建的工作区Choose the workspace you just created

你将看到 Azure 机器学习主页:You'll see the Azure Machine Learning homepage:

Azure ML 工作区的屏幕截图

若要查看与部署相关的所有资源,请单击左上方带有工作区名称(在屏幕截图中为 my_templated_ws)的链接。To see all the resources associated with the deployment, click the link in the upper left with the workspace name (in the screenshot, my_templated_ws). 该链接会转到 Azure 门户中的资源组。That link takes you to the resource group in the Azure portal. 资源组的名称为 {projectName}rg,工作区的名称为 {projectName}wsThe resource group name is {projectName}rg and the workspace is named {projectName}ws.

清理资源Clean up resources

如果不想使用此工作区,请删除它。If you don't want to use this workspace, delete it. 由于此工作区与其他资源(例如存储帐户)关联,因此可能需要删除创建的整个资源组。Since the workspace is associated with other resources such as a storage account, you'll probably want to delete the entire resource group you created. 可以使用门户删除资源组,方法是单击“删除”按钮并进行确认。You can delete the resource group using the portal by clicking on the "Delete" button and confirming. 也可以从 CLI 中使用以下命令删除资源组:Or, you can delete the resource group from the CLI with:

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

后续步骤Next steps

在本教程中,你通过 Azure 资源管理器模板创建了 Azure 机器学习工作区。In this tutorial, you created an Azure Machine Learning workspace from an Azure Resource Manager template. 若要探索 Azure 机器学习,请继续学习以下教程。If you'd like to explore Azure Machine Learning, continue with the tutorial.