将 Azure 云服务(经典)角色连接到 Azure 中托管的自定义 AD 域控制器

重要

新客户的云服务(经典版)现已弃用,并将于 2024 年 8 月 31 日对所有客户停用。 新部署应使用基于 Azure 资源管理器的新型部署模型 Azure 云服务(外延支持)

我们先在 Azure 中设置一个虚拟网络 (VNet)。 然后将 Active Directory 域控制器(托管在 Azure 虚拟机上)添加到该 VNet。 接下来,将现有云服务角色添加预先创建的 VNet,然后将它们连接到域控制器。

在开始之前,请特别注意以下几点:

  1. 本教程使用 PowerShell,因此请确保 Azure PowerShell 已安装并已准备就绪。 有关设置 Azure PowerShell 的帮助,请参阅如何安装和配置 Azure PowerShell
  2. AD 域控制器和 Web/辅助角色实例需要在 VNet 中。

请遵循以下分步指南,如果你遇到任何问题,请在本文末尾留言。 我们将回复你(没错,我们真的会阅读留言)。

由云服务引用的网络必须为经典虚拟网络

创建虚拟网络

可以使用 Azure 门户或 PowerShell 在 Azure 中创建虚拟网络。 在本教程中,使用 PowerShell。 要使用 Azure 门户创建虚拟网络,请参阅创建虚拟网络。 本文介绍创建虚拟网络(资源管理器),但必须创建用于云服务的虚拟网络(经典)。 为此,请在门户中选择“创建资源”,在“搜索”框中键入“虚拟网络”,然后按 Enter 。 在搜索结果的“所有内容”中,选择“虚拟网络” 。 在“选择部署模型” 下,选择“经典” ,然后选择“创建” 。 然后可以执行本文中的步骤。

#Create Virtual Network

$vnetStr =
@"<?xml version="1.0" encoding="utf-8"?>
<NetworkConfiguration xmlns:xsd="https://www.w3.org/2001/XMLSchema" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/ServiceHosting/2011/07/NetworkConfiguration">
    <VirtualNetworkConfiguration>
    <VirtualNetworkSites>
        <VirtualNetworkSite name="[your-vnet-name]" Location="China North">
        <AddressSpace>
            <AddressPrefix>[your-address-prefix]</AddressPrefix>
        </AddressSpace>
        <Subnets>
            <Subnet name="[your-subnet-name]">
            <AddressPrefix>[your-subnet-range]</AddressPrefix>
            </Subnet>
        </Subnets>
        </VirtualNetworkSite>
    </VirtualNetworkSites>
    </VirtualNetworkConfiguration>
</NetworkConfiguration>
"@;

$vnetConfigPath = "<path-to-vnet-config>"
Set-AzureVNetConfig -ConfigurationPath $vnetConfigPath

创建虚拟机

完成虚拟网络的设置后,需要创建 AD 域控制器。 在本教程中,我们会在 Azure 虚拟机上设置 AD 域控制器。

为此,请使用以下命令通过 PowerShell 创建虚拟机:

# Initialize variables
# VNet and subnet must be classic virtual network resources, not Azure Resource Manager resources.

$vnetname = '<your-vnet-name>'
$subnetname = '<your-subnet-name>'
$vmsvc1 = '<your-hosted-service>'
$vm1 = '<your-vm-name>'
$username = '<your-username>'
$password = '<your-password>'
$affgrp = '<your- affgrp>'

# Create a VM and add it to the Virtual Network

New-AzureQuickVM -Windows -ServiceName $vmsvc1 -Name $vm1 -ImageName $imgname -AdminUsername $username -Password $password -AffinityGroup $affgrp -SubnetNames $subnetname -VNetName $vnetname

将虚拟机提升为域控制器

要将虚拟机配置为 AD 域控制器,需要登录 VM 并对其进行配置。

若要登录 VM,你可以通过 PowerShell 获取 RDP 文件;请使用以下命令:

# Get RDP file
Get-AzureRemoteDesktopFile -ServiceName $vmsvc1 -Name $vm1 -LocalPath <rdp-file-path>

登录 VM 后,请根据如何设置客户 AD 域控制器中的分步指导,将虚拟机设置为 AD 域控制器。

将云服务添加到虚拟网络

接下来,需要将云服务部署添加到新的 VNet。 为此,请使用 Visual Studio 或选择的编辑器将相关节添加到 cscfg,以修改云服务 cscfg。

<ServiceConfiguration serviceName="[hosted-service-name]" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="[os-family]" osVersion="*">
    <Role name="[role-name]">
    <Instances count="[number-of-instances]" />
    </Role>
    <NetworkConfiguration>

    <!--optional-->
    <Dns>
        <DnsServers><DnsServer name="[dns-server-name]" IPAddress="[ip-address]" /></DnsServers>
    </Dns>
    <!--optional-->

    <!--VNet settings
        VNet and subnet must be classic virtual network resources, not Azure Resource Manager resources.-->
    <VirtualNetworkSite name="[virtual-network-name]" />
    <AddressAssignments>
        <InstanceAddress roleName="[role-name]">
        <Subnets>
            <Subnet name="[subnet-name]" />
        </Subnets>
        </InstanceAddress>
    </AddressAssignments>
    <!--VNet settings-->

    </NetworkConfiguration>
</ServiceConfiguration>

接下来,请生成云服务项目并将它部署到 Azure。 有关将云服务包部署到 Azure 的帮助,请参阅如何创建和部署云服务

将 Web/辅助角色连接到域

在 Azure 上部署云服务项目后,请使用 AD 域扩展将角色实例连接到自定义 AD 域。 要将 AD 域扩展添加到现有云服务部署并加入自定义域,请在 PowerShell 中执行以下命令:

# Initialize domain variables

$domain = '<your-domain-name>'
$dmuser = '$domain\<your-username>'
$dmpswd = '<your-domain-password>'
$dmspwd = ConvertTo-SecureString $dmpswd -AsPlainText -Force
$dmcred = New-Object System.Management.Automation.PSCredential ($dmuser, $dmspwd)

# Add AD Domain Extension to the cloud service roles

Set-AzureServiceADDomainExtension -Service <your-cloud-service-hosted-service-name> -Role <your-role-name> -Slot <staging-or-production> -DomainName $domain -Credential $dmcred -JoinOption 35

这就是所有的操作。

云服务应已加入自定义域控制器。 如果你想要深入了解用于配置 AD 域扩展的其他选项,请使用 PowerShell 帮助。 下面是一些示例:

help Set-AzureServiceADDomainExtension
help New-AzureServiceADDomainExtensionConfig