使用资源管理器模板,将 Windows Server 虚拟机加入到 Azure Active Directory 域服务托管域Join a Windows Server virtual machine to an Azure Active Directory Domain Services managed domain using a Resource Manager template

若要自动执行 Azure 虚拟机 (VM) 的部署和配置,可使用资源管理器模板。To automate the deployment and configuration of Azure virtual machines (VMs), you can use a Resource Manager template. 通过这些模板,可每次创建一致的部署。These templates let you create consistent deployments each time. 扩展也可以包含在模板中,以在部署过程中自动配置 VM。Extensions can also be included in templates to automatically configure a VM as part of the deployment. 一个实用的扩展可将 VM 加入到域中,该域可与 Azure Active Directory 域服务 (Azure AD DS) 托管域一起使用。One useful extension joins VMs to a domain, which can be used with Azure Active Directory Domain Services (Azure AD DS) managed domains.

本文介绍如何使用资源管理器模板创建 Windows Server VM 并将它加入到 Azure AD DS 托管域。This article shows you how to create and join a Windows Server VM to an Azure AD DS managed domain using Resource Manager templates. 你还可了解如何将现有的 Windows Server VM 加入到 Azure AD DS 域。You also learn how to join an existing Windows Server VM to an Azure AD DS domain.

先决条件Prerequisites

需有以下资源和特权才能完成本教程:To complete this tutorial, you need the following resources and privileges:

Azure 资源管理器模板概述Azure Resource Manager template overview

通过资源管理器模板,可在代码中定义 Azure 基础结构。Resource Manager templates let you define Azure infrastructure in code. 所有必需的资源、网络连接或 VM 配置均可在模板中进行定义。The required resources, network connections, or configuration of VMs can all be defined in a template. 这些模板每次都创建一致的可重现部署,并且可以在你进行更改时进行版本控制。These templates create consistent, reproducible deployments each time, and can be versioned as you make changes. 有关详细信息,请参阅 Azure 资源管理器模板概述For more information, see Azure Resource Manager templates overview.

使用 JavaScript 对象表示法 (JSON) 在模板中定义每个资源。Each resource is defined in a template using JavaScript Object Notation (JSON). 以下 JSON 示例使用 Microsoft.Compute/virtualMachines/extensions 资源类型来安装 Active Directory 域加入扩展。The following JSON example uses the Microsoft.Compute/virtualMachines/extensions resource type to install the Active Directory domain join extension. 使用在部署时指定的参数。Parameters are used that you specify at deployment time. 扩展部署完成后,VM 加入到指定的托管域。When the extension is deployed, the VM is joined to the specified managed domain.

 {
      "apiVersion": "2015-06-15",
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "name": "[concat(parameters('dnsLabelPrefix'),'/joindomain')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[concat('Microsoft.Compute/virtualMachines/', parameters('dnsLabelPrefix'))]"
      ],
      "properties": {
        "publisher": "Microsoft.Compute",
        "type": "JsonADDomainExtension",
        "typeHandlerVersion": "1.3",
        "autoUpgradeMinorVersion": true,
        "settings": {
          "Name": "[parameters('domainToJoin')]",
          "OUPath": "[parameters('ouPath')]",
          "User": "[concat(parameters('domainToJoin'), '\\', parameters('domainUsername'))]",
          "Restart": "true",
          "Options": "[parameters('domainJoinOptions')]"
        },
        "protectedSettings": {
          "Password": "[parameters('domainPassword')]"
        }
      }
    }

即使你不在同一个模板中创建 VM,此 VM 扩展也可进行部署。This VM extension can be deployed even if you don't create a VM in the same template. 本文中的示例演示了以下两种方法:The examples in this article show both of the following approaches:

创建 Windows Server VM 并将其加入托管域Create a Windows Server VM and join to a managed domain

如果你需要 Windows Server VM,可使用资源管理器模板创建并配置一个。If you need a Windows Server VM, you can create and configure one using a Resource Manager template. VM 部署后,安装一个扩展以将 VM 加入托管域。When the VM is deployed, an extension is then installed to join the VM to a managed domain. 如果你已有要加入托管域的 VM,请跳至将现有 Windows Server VM 加入托管域If you already have a VM you wish to join to a managed domain, skip to Join an existing Windows Server VM to a managed domain.

若要创建一个 Windows Server VM,然后将其加入托管域,请完成以下步骤:To create a Windows Server VM then join it to a managed domain, complete the following steps:

  1. 浏览到快速启动模板Browse to the quickstart template. 选择“部署到 Azure”选项。Select the option to Deploy to Azure.

  2. 在“自定义部署”页上,输入以下信息以创建 Windows Server VM 并将其加入托管域:On the Custom deployment page, enter the following information to create and join a Windows Server VM to the managed domain:

    设置Setting ValueValue
    订阅Subscription 请选择在其中启用了 Azure AD 域服务的同一个 Azure 订阅。Pick the same Azure subscription in which you have enabled Azure AD Domain Services.
    资源组Resource group 选择 VM 的资源组。Choose the resource group for your VM.
    位置Location 选择 VM 的位置。Select the location of for your VM.
    现有 VNET 名称Existing VNET Name 要与 VM 连接的现有虚拟网络的名称,例如 myVnet。The name of the existing virtual network to connect the VM to, such as myVnet.
    现有子网名称Existing Subnet Name 现有虚拟网络子网的名称,例如 Workloads。The name of the existing virtual network subnet, such as Workloads.
    DNS 标签前缀DNS Label Prefix 输入要用于 VM 的 DNS 名称,例如 myvmEnter a DNS name to use for the VM, such as myvm.
    VM 大小VM size 指定 VM 规格,例如 Standard_DS2_v2。Specify a VM size, such as Standard_DS2_v2.
    要加入的域Domain To Join 托管域 DNS 名称,例如 aaddscontoso.com。The managed domain DNS name, such as aaddscontoso.com.
    域用户名Domain Username 托管域中的用户帐户(例如 contosoadmin@aaddscontoso.com),应使用该帐户将 VM 加入托管域。The user account in the managed domain that should be used to join the VM to the managed domain, such as contosoadmin@aaddscontoso.com. 此帐户必须属于托管域。This account must be a part of the managed domain.
    域密码Domain Password 在上一设置中指定的用户帐户的密码。The password for the user account specified in the previous setting.
    可选 OU 路径Optional OU Path 要在其中添加 VM 的自定义 OU。The custom OU in which to add the VM. 如果你未指定此参数的值,VM 会被添加到默认的“AAD DC 计算机”OU。If you don't specify a value for this parameter, the VM is added to the default AAD DC Computers OU.
    VM 管理员用户名VM Admin Username 指定要在 VM 上创建的本地管理员帐户。Specify a local administrator account to create on the VM.
    VM 管理员密码VM Admin Password 为 VM 指定本地管理员密码。Specify a local administrator password for the VM. 创建本地管理员强密码,防范密码暴力破解攻击。Create a strong local administrator password to protect against password brute-force attacks.
  3. 查看条款和条件,然后勾选“我同意上述条款和条件”复选框。Review the terms and conditions, then check the box for I agree to the terms and conditions stated above. 准备就绪后,选择“购买”,创建 VM 并将其加入托管域。When ready, select Purchase to create and join the VM to the managed domain.

警告

请小心处理密码。Handle passwords with caution. 模板参数文件请求属于托管域的用户帐户的密码。The template parameter file requests the password for a user account that's a part of the managed domain. 不要手动向此文件中输入值,也不要使它在文件共享或其他共享位置保持可访问状态。Don't manually enter values into this file and leave it accessible on file shares or other shared locations.

需要几分钟才能成功完成部署。It takes a few minutes for the deployment to complete successfully. 完成后,Windows VM 已创建并已加入到托管域。When finished, the Windows VM is created and joined to the managed domain. 可使用域帐户管理或登录 VM。The VM can be managed or signed into using domain accounts.

将现有的 Windows Server VM 加入托管域Join an existing Windows Server VM to a managed domain

如果你有要加入托管域的现有 VM 或 VM 组,可使用资源管理器模板仅部署 VM 扩展。If you have an existing VM, or group of VMs, that you wish to join to a managed domain, you can use a Resource Manager template to just deploy the VM extension.

若要将现有的 Windows Server VM 加入托管域,请完成以下步骤:To join an existing Windows Server VM to a managed domain, complete the following steps:

  1. 浏览到快速启动模板Browse to the quickstart template. 选择“部署到 Azure”选项。Select the option to Deploy to Azure.

  2. 在“自定义部署”页上,输入以下信息,将 VM 加入托管域:On the Custom deployment page, enter the following information to join the VM to the managed domain:

    设置Setting ValueValue
    订阅Subscription 请选择在其中启用了 Azure AD 域服务的同一个 Azure 订阅。Pick the same Azure subscription in which you have enabled Azure AD Domain Services.
    资源组Resource group 选择包含现有 VM 的资源组。Choose the resource group with your existing VM.
    位置Location 选择现有 VM 的位置。Select the location of your existing VM.
    VM 列表VM list 输入要加入托管域的现有 VM 的逗号分隔列表,例如 myVM1,myVM2。Enter the comma-separated list of the existing VM(s) to join to the managed domain, such as myVM1,myVM2.
    域加入用户名Domain Join User Name 托管域中的用户帐户(例如 contosoadmin@aaddscontoso.com),应使用该帐户将 VM 加入托管域。The user account in the managed domain that should be used to join the VM to the managed domain, such as contosoadmin@aaddscontoso.com. 此帐户必须属于托管域。This account must be a part of the managed domain.
    域加入用户密码Domain Join User Password 在上一设置中指定的用户帐户的密码。The password for the user account specified in the previous setting.
    可选 OU 路径Optional OU Path 要在其中添加 VM 的自定义 OU。The custom OU in which to add the VM. 如果你未指定此参数的值,VM 会被添加到默认的“AAD DC 计算机”OU。If you don't specify a value for this parameter, the VM is added to the default AAD DC Computers OU.
  3. 查看条款和条件,然后勾选“我同意上述条款和条件”复选框。Review the terms and conditions, then check the box for I agree to the terms and conditions stated above. 准备就绪后,选择“购买”,将 VM 加入托管域。When ready, select Purchase to join the VM to the managed domain.

警告

请小心处理密码。Handle passwords with caution. 模板参数文件请求属于托管域的用户帐户的密码。The template parameter file requests the password for a user account that's a part of the managed domain. 不要手动向此文件中输入值,也不要使它在文件共享或其他共享位置保持可访问状态。Don't manually enter values into this file and leave it accessible on file shares or other shared locations.

需要一些时间才能成功完成部署。It takes a few moments for the deployment to complete successfully. 完成后,指定的 Windows VM 将加入到托管域,你可使用域帐户管理或登录 VM。When finished, the specified Windows VMs are joined to the managed domain and can be managed or signed into using domain accounts.

后续步骤Next steps

本文介绍了如何使用 Azure 门户通过模板配置和部署资源。In this article, you used the Azure portal to configure and deploy resources using templates. 你也可使用 Azure PowerShellAzure CLI,通过资源管理器模板部署资源。You can also deploy resources with Resource Manager templates using Azure PowerShell or the Azure CLI.