部署容错 Microsoft Active Directory 环境


本教程是系列教程中的第一篇,可帮助您使用 Microsoft Active Directory、SQL Server 和 Internet Information Services (IIS) 在 Google Cloud 上部署高可用性 Windows 架构。在本教程中,您将通过 Active Directory 使用新的 Virtual Private Cloud (VPC) 网络和多个子网设置具备冗余性的一对 Windows 网域控制器。

本系列教程包含以下内容:

每个教程都基于您在上一个教程中创建的基础架构。

您还可以使用本教程学习如何设置 Active Directory 配置,以在其他架构中使用。本指南未介绍如何将远程 Active Directory 环境复制到新的基于 Google Cloud 的 Active Directory 环境,不过此操作可以通过 Cloud VPN 和其他 Active Directory 配置来实现。

架构

Google Cloud 上可容错的 Active Directory 架构。

目标

  • 创建包含两个子网(跨两个地区)的自定义模式 VPC 网络。
  • 创建 Windows Server 虚拟实例并启用 Active Directory 网域服务。
  • 使用 Active Directory 配置新网域。
  • 将新的 Windows Server 实例联接到新网域。
  • 配置防火墙规则,以允许流量进入虚拟机。
  • 测试该配置。

费用

本教程使用 Google Cloud 的以下收费组件:

价格计算器估算,该环境的费用约为 $4/天。

准备工作

  1. 在 Google Cloud Console 中的项目选择器页面上,选择或创建一个 Google Cloud 项目

    转到“项目选择器”

  2. 确保您的 Google Cloud 项目已启用结算功能

  3. 启用 Compute Engine API。

    启用 API

初始化通用变量

您必须定义几个用于控制在何处部署基础架构元素的环境变量。

  1. 转至 Cloud Shell。

    打开 Cloud Shell

  2. 在 Cloud Shell 中创建以下环境变量,以设置在本教程后面的部分需要使用的值。

    这些命令将地区设置为 us-east-1。您可以使用其他地区,但请记住您使用的地区,以便可以在后续教程中使用此地区。

    export region=us-east1
    export zone_1=${region}-b
    export zone_2=${region}-c
    export vpc_name=webappnet
    export project_id=your-project-id
    

    your-project-id 替换为您正在使用的 Google Cloud 项目的 ID。

  3. 运行以下命令以设置默认区域和项目 ID,这样您就不必在每个后续命令中指定这些值:

    gcloud config set compute/region ${region}
    gcloud config set project ${project_id}
    

创建网络基础架构

定义基础架构变量后,即可创建 Active Directory 将使用的网络和子网。

  1. 在 Cloud Shell 中,运行以下命令以创建 VPC 网络:

    gcloud compute networks create ${vpc_name}  \
        --description "VPC network to deploy Active Directory" \
        --subnet-mode custom
    

    您将看到以下警告,可以忽略该警告,因为您将在后续步骤中创建这些防火墙规则。

    Instances on this network will not be reachable until firewall rules
    are created.
    
  2. 将两个子网添加到 VPC 网络:

    gcloud compute networks subnets create private-ad-zone-1 \
        --network ${vpc_name} \
        --range 10.1.0.0/24
    
    gcloud compute networks subnets create private-ad-zone-2 \
        --network ${vpc_name} \
        --range 10.2.0.0/24
    
  3. 创建内部防火墙规则,以允许子网之间传递流量:

    gcloud compute firewall-rules create allow-internal-ports-private-ad \
        --network ${vpc_name} \
        --allow tcp:1-65535,udp:1-65535,icmp \
        --source-ranges  10.1.0.0/24,10.2.0.0/24
    
  4. 创建防火墙规则,以允许从任意位置在端口 3389 上使用 RDP 连接:

    gcloud compute firewall-rules create allow-rdp \
        --network ${vpc_name} \
        --allow tcp:3389 \
        --source-ranges 0.0.0.0/0
    

创建第一个网域控制器

接下来,您将创建一个具有以下属性的网域控制器:

  • 名称:ad-dc1
  • IP 地址:10.1.0.100
  1. 创建 Windows Server 2016 的 Compute Engine 实例以用作第一个网域控制器:

    gcloud compute instances create ad-dc1 --machine-type n1-standard-2 \
        --boot-disk-type pd-ssd \
        --boot-disk-size 50GB \
        --image-family windows-2016 --image-project windows-cloud \
        --network ${vpc_name} \
        --zone ${zone_1} --subnet private-ad-zone-1 \
        --private-network-ip=10.1.0.100
    
  2. 请等待一分钟左右,然后为 Windows 实例 ad-dc1 创建一个密码:

    gcloud compute reset-windows-password ad-dc1 --zone ${zone_1} --quiet
    

    用户名是您的 Google 帐号用户名。请记好用户名和密码,以备将来使用。

  3. 使用您在上一步中创建的凭据,通过 RDP 连接到网域控制器实例。

  4. 以管理员身份打开 PowerShell 终端。(点击开始,输入 PowerShell,然后按 Shift+Ctrl+Enter。)

  5. 设置管理员帐号的 Windows 凭据:

    net user Administrator *
    

    系统会提示您创建密码。请使用安全系数高的密码,并将密码存储在安全的位置以备将来使用。

    您使用管理员帐号创建 Active Directory 林后,该帐号将成为网域管理员帐号。

  6. 启用帐号:

    net user Administrator /active:yes
    
  7. 安装 Active Directory 网域服务,包括管理工具:

    Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
    
  8. 设置以下变量:

    $DomainName = "example-gcp.com"
    $DomainMode = "7"
    $ForestMode = "7"
    $DatabasePath = "C:\Windows\NTDS"
    $SysvolPath = "C:\Windows\SYSVOL"
    $LogPath = "C:\Logs"
    
  9. 在 Windows Server 2016 模式下安装新的 Active Directory 林配置:

    Install-ADDSForest -CreateDnsDelegation:$false `
        -DatabasePath $DatabasePath `
        -LogPath $LogPath `
        -SysvolPath $SysvolPath `
        -DomainName $DomainName `
        -DomainMode $DomainMode `
        -ForestMode $ForestMode `
        -InstallDNS:$true `
        -NoRebootOnCompletion:$true `
        -Force:$true
    
  10. 出现提示时,输入“安全模式管理员”密码。将密码存储在安全的位置以备将来使用。

  11. 忽略以下警告。每个警告将出现两次,一次是在前提条件验证期间,另一次是在安装过程中。

    WARNING: Windows Server 2016 domain controllers have a default for the
    security setting named Allow cryptography algorithms compatible with
    Windows NT 4.0 that prevents weaker cryptography algorithms when
    establishing security channel sessions.
    For more information about this setting, see Knowledge Base article 942564 (http://go.microsoft.com/fwlink/?LinkId=104751).
    WARNING: This computer has at least one physical network adapter that does
    not have static IP address(es) assigned to its IP Properties. If both IPv4
    and IPv6 are enabled for a network adapter, both IPv4 and IPv6 static IP
    addresses should be assigned to both IPv4 and IPv6 Properties of the
    physical network adapter. Such static IP address(es) assignment should be
    done to all the physical network adapters for reliable Domain Name
    System (DNS) operation.
    
    WARNING: A delegation for this DNS server cannot be created because the
    authoritative parent zone cannot be found or it does not run Windows DNS
    server. If you are integrating with an existing DNS infrastructure, you
    should manually create a delegation to this DNS server in the parent zone
    to ensure reliable name resolution from outside the domain "example-gcp.com".
    Otherwise, no action is required.
    
  12. 重启虚拟机:

    Restart-Computer
    
  13. 使用您在 Active Directory 林安装期间定义的管理员凭据,通过 RDP 连接到网域控制器 ad-dc1。请务必将域名添加为前缀,如 EXAMPLE-GCP\Administrator

  14. 以管理员身份打开 PowerShell 终端。

  15. 设置以下变量:

    $DNSPrimary = "10.2.0.100"
    $DNSSecondary = "127.0.0.1"
    $LocalStaticIp = "10.1.0.100"
    $DefaultGateway = "10.1.0.1"
    
  16. 设置 IP 地址和默认网关:

    netsh interface ip set address name=Ethernet static `
        $LocalStaticIp 255.255.255.0 $DefaultGateway 1
    
  17. 配置主 DNS 服务器:

    netsh interface ip set dns Ethernet static $DNSPrimary
    

    DNS 服务器 ad-dc2 仅在部署第二个网域控制器后才可用,因此您可以忽略以下错误消息:

    The configured DNS server is incorrect or does not exist.
  18. 配置辅助 DNS 服务器:

    netsh interface ip add dns Ethernet $DNSSecondary index=2
    

    此网域控制器的 DNS 服务器条目 ad-dc1 应排在列表的第二位,以防止 Active Directory 频繁丢失与其他控制器的连接。请将第二个网域控制器 ad-dc2 用作主 DNS 服务器。在下一部分中,您将创建 ad-dc2 网域控制器。如果不遵循此模式,则服务器管理器 > Active Directory 网域服务下将显示以下错误:

    The DFS Replication service failed to update configuration in Active
    Directory Domain Services. The service will retry this operation
    periodically.
    

    在两台服务器完全配置妥当之前,ad-dc1 服务器上可能会显示错误。您可以忽略这些错误。

创建第二个网域控制器

接下来,您将在其他区域创建第二个网域控制器以提供容错能力。第二个网域控制器具有以下属性:

  • 名称:ad-dc2
  • IP 地址:10.2.0.100
  1. 如果您的 Cloud Shell 窗口已过期,请打开一个新的 Cloud Shell 实例并重置您之前设置的变量。为此,请修改以下脚本以指定先前使用的项目 ID 和地区。

    region=us-east1
    zone_2=${region}-c
    zone_1=${region}-b
    vpc_name=webappnet
    project_id=your-project-id
    
    gcloud config set compute/region ${region}
    gcloud config set project ${project_id}
    

    your-project-id 替换为您正在使用的 Google Cloud 项目的 ID。

  2. 将脚本复制到 Cloud Shell 窗口并运行。

  3. 使用 Cloud Shell 创建第二个网域控制器实例:

    gcloud compute instances create ad-dc2 --machine-type n1-standard-2 \
        --boot-disk-size 50GB \
        --boot-disk-type pd-ssd \
        --image-family windows-2016 --image-project windows-cloud \
        --can-ip-forward \
        --network ${vpc_name} \
        --zone ${zone_2} \
        --subnet private-ad-zone-2 \
        --private-network-ip=10.2.0.100
    
  4. 请等待一分钟左右,然后为 Windows 实例 ad-dc2 创建一个密码:

    gcloud compute reset-windows-password ad-dc2 --zone ${zone_2} --quiet
    

    用户名是您的 Google 帐号用户名。请记好用户名和密码,以备将来使用。

  5. 使用您在上一步中创建的凭据,通过 RDP 连接到网域控制器实例。

  6. 以管理员身份打开 PowerShell 终端。

  7. 安装 Active Directory 网域服务,包括管理工具:

    Install-WindowsFeature -Name AD-Domain-Services -IncludeManagementTools
    
  8. 设置以下变量:

    $DomainName = "example-gcp.com"
    $DomainPrefix = "EXAMPLE-GCP"
    $DNSPrimary = "10.1.0.100"
    $DNSSecondary = "127.0.0.1"
    $LocalStaticIp = "10.2.0.100"
    $DefaultGateway = "10.2.0.1"
    $DatabasePath = "C:\Windows\NTDS"
    $SysvolPath = "C:\Windows\SYSVOL"
    $LogPath = "C:\Logs"
    
  9. 配置主 DNS 服务器:

    netsh interface ip set dns Ethernet static $DNSPrimary
    
  10. 配置第二个服务器,使其充当自己的辅助 DNS 服务器:

    netsh interface ip add dns Ethernet $DNSSecondary index=2
    

    只有在 ad-dc2 作为网域控制器加入网域后,ad-dc2 DNS 服务器才可用。由于服务器尚未加入,您会看到以下消息,但可以忽略它:

    The configured DNS server is incorrect or does not exist.
  11. 设置 IP 地址和默认网关:

    netsh interface ip set address name=Ethernet static `
        $LocalStaticIp 255.255.255.0 $DefaultGateway 1
    
  12. 运行以下 PowerShell 脚本,该脚本将在第一个网域控制器运行时通知您。请等待显示 Domain controller is reachable 消息。

    $DomainIsReady=$False
    For ($i=0; $i -le 30; $i++) {
        nltest /dsgetdc:$DomainName
        if($LASTEXITCODE -ne 0) {
            Write-Host "Domain not ready, wait 1 more minute, then retry"
            Start-Sleep -s 60
        }
        else {
            $DomainIsReady=$True
            Write-Host "Domain controller is reachable"
            break
        }
    }
    if($DomainIsReady -eq $False) {
        Write-Host "Domain not ready. Check if it was deployed ok"
    }
    
  13. 将虚拟机作为第二个网域控制器添加到林:

    Install-ADDSDomainController `
        -Credential (Get-Credential "$DomainPrefix\Administrator") `
        -CreateDnsDelegation:$false `
        -DatabasePath $DatabasePath `
        -DomainName $DomainName `
        -InstallDns:$true `
        -LogPath $LogPath `
        -SysvolPath $SysvolPath `
        -NoGlobalCatalog:$false `
        -SiteName 'Default-First-Site-Name' `
        -NoRebootOnCompletion:$true `
        -Force:$true
    
  14. 当系统提示您为管理员帐号提供密码时,请使用您在 Active Directory 林安装期间定义的管理员凭据。请添加域名作为前缀,如 EXAMPLE-GCP\Administrator

  15. 当系统提示您输入“安全模式管理员”密码时,请使用用于第一个网域控制器的同一密码。

  16. 忽略以下警告。每个警告将出现两次:一次是在前提条件验证期间,另一次是在安装过程中。

    WARNING: Windows Server 2016 domain controllers have a default for the
    security setting named "Allow cryptography algorithms compatible with
    Windows NT 4.0" that prevents weaker cryptography algorithms when
    establishing security channel sessions.
    For more information about this setting, see Knowledge Base article 942564 (http://go.microsoft.com/fwlink/?LinkId=104751).
    WARNING: A delegation for this DNS server cannot be created because the
    authoritative parent zone cannot be found or it does not run Windows DNS
    server. If you are integrating with an existing DNS infrastructure, you
    should manually create a delegation to this DNS server in the parent zone
    to ensure reliable name resolution from outside the domain
    "example-gcp.com". Otherwise, no action is required.
    
  17. 重启虚拟机:

    Restart-Computer
    

测试安装

  1. 等待 5-10 分钟,确保两个网域控制器都可以正常运行并正在复制信息。

  2. 使用您在第一个网域控制器安装期间定义的管理员凭据,通过 RDP 连接到第一个网域控制器实例。请添加域名作为前缀,如 EXAMPLE-GCP\Administrator

  3. 以管理员身份打开 PowerShell 终端。

  4. 测试复制操作是否生效:

    repadmin /replsum
    

    输出应与以下内容类似,没有出错,也没有失败。

    测试复制的结果,显示零失败

    如果网域控制器不可用,您会看到如下所示的消息:

    Beginning data collection for replication summary, this may take awhile:
    .... Source DSA largest delta fails/total %% error
    Destination DSA largest delta fails/total %% error

    如果看到此消息,请等待几分钟,然后重试该命令。

清除数据

如果您想继续学习本系列中的下一个教程(部署多子网 SQL Server),请保留您在本教程中创建的资源。但是,如果您不打算使用本教程中创建的 Active Directory 环境,请清理您在 Google Cloud 上创建的资源,以避免日后为这些资源支付费用。以下部分介绍如何删除或关闭这些资源。

删除项目

为了避免产生费用,最简单的方法是删除您为本教程创建的项目。

如需删除项目,请执行以下操作:

  1. 在 Google Cloud 控制台中,进入管理资源页面。

    转到“管理资源”

  2. 在项目列表中,选择要删除的项目,然后点击删除
  3. 在对话框中输入项目 ID,然后点击关闭以删除项目。

删除实例

如需删除 Compute Engine 实例,请执行以下操作:

  1. 在 Google Cloud 控制台中,转到虚拟机实例页面。

    转到“虚拟机实例”

  2. 选中要删除的实例。
  3. 如需删除实例,请点击更多操作,点击删除,然后按照说明操作。

删除 VPC 网络

要删除 VPC 网络、子网和防火墙规则,请执行以下操作:

  1. 在 Google Cloud 控制台中,转到“VPC 网络”页面。

    转到“VPC 网络”页面

  2. 选择您创建的 VPC 网络。

  3. 点击页面顶部的删除按钮。

后续步骤