이 페이지에서는 Microsoft Active Directory용 관리형 서비스의 자동 도메인 조인 기능을 사용하여 Windows Compute Engine VM 인스턴스를 도메인에 조인하는 방법을 설명합니다.
관리형 Microsoft AD가 Windows VM을 도메인에 자동으로 조인하는 방법
관리형 Microsoft AD를 사용하여 VM에서 실행되는 애플리케이션을 인증하려면 VM을 관리형 Microsoft AD 도메인에 조인해야 합니다. 도메인 조인 프로세스에는 일반적으로 몇 가지 수동 단계를 수행하는 것이 포함됩니다.
Windows Compute Engine VM을 만들거나 업데이트할 때 스크립트를 사용해 수동 접근 방식을 자동화하여 VM을 관리형 Microsoft AD 도메인에 조인할 수 있습니다. 그러나 Compute Engine VM에서 이러한 스크립트를 실행하려면 안전하게 저장하고 유지보수해야 하는 AD 사용자 인증 정보와 이러한 스크립트를 프로비저닝하고 실행할 환경이 필요합니다. 사용자 인증 정보 및 추가 서비스를 사용할 필요가 없도록 관리형 Microsoft AD에서 제공하는 바로 활용할 수 있는 스크립트를 사용하여 도메인 조인 프로세스를 자동화할 수 있습니다.
Compute Engine VM을 만들 때 스크립트를 사용하여 VM을 관리형 Microsoft AD 도메인에 자동으로 조인할 수 있습니다. Compute Engine이 VM을 만들면 관리형 Microsoft AD가 도메인 조인 요청을 시작하고 VM을 도메인과 조인하려고 시도합니다. 도메인 조인 요청이 성공하면 관리형 Microsoft AD가 생성된 VM을 도메인에 조인합니다. 도메인 조인 요청이 실패하면 생성된 VM이 계속 실행됩니다. 보안 또는 청구 목적으로 이 동작을 맞춤설정할 수 있으며 관리형 Microsoft AD는 도메인 조인 요청 실패 시 VM을 중지할 수 있습니다.
Compute Engine VM을 업데이트할 때 스크립트를 사용하여 기존 VM을 관리형 Microsoft AD 도메인에 자동으로 조인할 수 있습니다. 도메인 조인 요청이 성공하려면 관리형 Microsoft AD가 스크립트를 실행한 후 VM을 다시 시작해야 합니다.
관리형 Microsoft AD 도메인과 VM 네트워크 간에 도메인 피어링을 구성하거나 관리형 Microsoft AD 도메인과 VM을 모두 동일한 네트워크에 배치합니다.
관리형 Microsoft AD 도메인이 있는 프로젝트에서 Google Cloud 관리형 ID 도메인 조인(roles/managedidentities.domainJoin) IAM 역할을 사용하여 서비스 계정을 만듭니다. 자세한 내용은 Cloud 관리형 ID 역할을 참조하세요.
VM에 이 URL에 액세스할 수 없는 경우 지원되는 다른 메서드 중 하나를 사용하여 시작 스크립트를 전달할 수 있습니다. 자세한 내용은 Windows VM에서 시작 스크립트 사용을 참고하세요.
managed-ad-domain
이 메타데이터 키를 사용하여 projects/PROJECT_ID/locations/global/domains/DOMAIN_NAME 형식으로 조인할 관리형 Microsoft AD 도메인의 전체 리소스 이름을 지정합니다. 예를 들면 projects/my-project-123/locations/global/domains/my-domain.example.com입니다.
managed-ad-domain-join-failure-stop
(선택사항) 기본적으로 VM은 도메인 조인 요청이 실패한 후에도 계속 실행됩니다. 요청이 실패할 때 VM을 중지하려면 이 메타데이터 키를 TRUE로 설정하면 됩니다. 관리 Microsoft AD는 이 메타데이터 키를 설정한 후 VM을 중지할 수 있지만 VM을 삭제하지는 않습니다.
enable-guest-attributes
(선택사항) 기본적으로 VM에서는 게스트 속성이 사용 중지되어 있습니다. VM의 게스트 속성을 사용하여 시작 스크립트 실행 후 도메인 조인 상태를 기록하려면 이 메타데이터 키를 TRUE로 설정할 수 있습니다.
관리형 Microsoft AD는 guest-attributes의 managed-ad 네임스페이스 아래에 있는 다음 키에 도메인 조인 상태를 기록합니다.
domain-join-status: 이 키는 스크립트 실행 후 도메인 조인 요청의 상태를 제공합니다.
domain-join-failure-message: 도메인 조인 요청이 실패하면 이 키에서 오류 메시지를 제공합니다.
게스트 속성을 가져오면 이러한 네임스페이스와 키를 사용하여 도메인 가입 상태를 확인할 수 있습니다.
managed-ad-ou-name
(선택사항) 기본적으로 관리형 Microsoft AD는 정책을 더 잘 관리하기 위해 Cloud OU 아래에 사전 생성된 GCE Instances 조직 단위(OU)에 VM을 조인합니다. Cloud OU에 대한 자세한 내용은 조직 단위를 참고하세요.
VM을 커스텀 OU에 조인하려면 관리형 Microsoft AD의 GCE Instances OU 또는 Cloud OU에서 커스텀 OU를 만들고 이 메타데이터 키를 사용하여 커스텀 OU를 지정합니다. 관리형 Microsoft AD는 Cloud OU 또는 GCE Instances OU 이외의 위치에 만든 맞춤 OU를 지원하지 않습니다.
Cloud OU 아래에 커스텀 OU를 만드는 경우 /cloud/SUB_OU1/SUB_OU2/…/CUSTOM_OU 형식으로 커스텀 OU의 경로를 지정합니다. 예, /cloud/my-sub-ou/my-custom-ou
(선택사항) 도메인에 조인한 VM을 삭제하면 VM의 컴퓨터 계정은 관리형 Microsoft AD에 계속 존재합니다. 동일한 컴퓨터 계정으로 다른 VM에 가입하려고 하면 기본적으로 도메인 가입 요청이 실패합니다. 이 메타데이터 키를 TRUE로 설정하면 관리형 Microsoft AD에서 기존 컴퓨터 계정을 재사용할 수 있습니다.
Windows VM에 조인
Windows VM을 만들거나 기존 VM을 업데이트할 때 이러한 메타데이터 키를 사용할 수 있습니다.
다음 섹션에서는 VM을 만들거나 VM을 업데이트할 때 gcloud CLI 명령어에서 이러한 메타데이터 키를 사용하는 방법을 보여줍니다.
그러나 다른 사용 가능한 옵션을 사용하여 VM에서 이러한 메타데이터 키를 사용할 수 있습니다. Windows Compute Engine VM에서 메타데이터를 사용하는 방법에 관한 자세한 내용은 커스텀 메타데이터 설정을 참고하세요.
생성 중에 Windows VM에 조인
Windows Compute Engine VM을 만들고 참여하려면 다음 gcloud CLI 명령어를 실행합니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-12-21(UTC)"],[],[],null,["# Join a Windows VM automatically to a domain\n\nThis page explains how to join a Windows Compute Engine VM instance to a domain using the automated domain join feature in Managed Service for Microsoft Active Directory.\n\nHow Managed Microsoft AD joins a Windows VM automatically to a domain\n---------------------------------------------------------------------\n\nTo use Managed Microsoft AD for authenticating the applications running on your VMs, you need to join the VMs to your Managed Microsoft AD domain. The domain join process usually involves performing some manual steps.\n\nWhen you create or update a Windows Compute Engine VM, you can join the VM to your Managed Microsoft AD domain by automating [the manual approach](/managed-microsoft-ad/docs/quickstart-domain-join-windows) using scripts. However, to execute these scripts on a Compute Engine VM, you require AD credentials that need to be securely stored and maintained, and an environment to provision and run these scripts. To eliminate the need for credentials and an additional service, you can automate the domain join process with ready-made scripts that are available from Managed Microsoft AD.\n\nWhen you create Compute Engine VMs, you can use scripts to automatically join the VMs to your Managed Microsoft AD domain. After Compute Engine creates the VMs, Managed Microsoft AD initiates the domain join request and attempts to join the VMs with your domain. If the domain join request succeeds, Managed Microsoft AD joins the created VMs to your domain. If the domain join request fails, the created VMs continue to run. For security or billing purposes, you can customize this behavior and Managed Microsoft AD can stop the VMs when the domain join request fails.\n\nWhen you update Compute Engine VMs, you can use scripts to automatically join the existing VMs to your Managed Microsoft AD domain. For the domain join request to succeed, Managed Microsoft AD restarts the VMs after running the scripts.\n\nBefore you begin\n----------------\n\n1. [Create a Managed Microsoft AD domain](/managed-microsoft-ad/docs/create-domain).\n\n2. Make sure that the VM name has a maximum of 15 characters.\n\n3. Make sure that the VM runs on a [Windows version that Managed Microsoft AD supports](/managed-microsoft-ad/docs/os-versions#windows-domain-join).\n\n4. [Configure domain peering](/managed-microsoft-ad/docs/quickstart-domain-peering) between the Managed Microsoft AD domain and the VM's network, or have both the Managed Microsoft AD domain and the VM in the same network.\n\n5. Create a service account with the Google Cloud Managed Identities Domain Join (`roles/managedidentities.domainJoin`) IAM role on the project that has the Managed Microsoft AD domain. For more information, see [Cloud Managed Identities roles](/iam/docs/understanding-roles#cloud-managed-identities-roles).\n\n - For more information about granting roles, see [Grant a single role](/iam/docs/manage-access-service-accounts#grant-single-role).\n\n - For information about creating a service account, see [Authenticate workloads using service accounts](/compute/docs/access/create-enable-service-accounts-for-instances).\n\n6. Set the full `cloud-platform` access scope on the VM. For more information, see [Authorization](/compute/docs/access/service-accounts#authorization).\n\nMetadata\n--------\n\nYou need the following metadata keys to join a Windows VM to a domain.\n\nJoin the Windows VM\n-------------------\n\nYou can use these [metadata keys](/managed-microsoft-ad/docs/seamless-domain-join-gce#metadata) when you either create a Windows VM or update an existing VM.\nThe following sections illustrate how to use these metadata keys in gcloud CLI commands when you create a VM or update a VM.\n\nHowever, you can use these metadata keys with a VM using the other available options as well. For more information about using metadata with a Windows Compute Engine VM, see [Set custom metadata](/compute/docs/metadata/setting-custom-metadata).\n\n### Join a Windows VM during creation\n\nTo create and join a Windows Compute Engine VM, run the following gcloud CLI command: \n\n```\ngcloud compute instances create INSTANCE_NAME \\\n --metadata=windows-startup-script-url=URL,managed-ad-domain=DOMAIN_RESOURCE_PATH,managed-ad-domain-join-failure-stop=TRUE,enable-guest-attributes=TRUE \\\n --service-account=SERVICE_ACCOUNT \\\n --scopes=https://www.googleapis.com/auth/cloud-platform \\\n --image-project windows-cloud \\\n --image-family IMAGE_FAMILY\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eINSTANCE_NAME\u003c/var\u003e: Name of the Windows Compute Engine VM to create. For example, `my-instance-1`.\n- \u003cvar translate=\"no\"\u003eURL\u003c/var\u003e: A publicly-accessible location of the Windows startup script that the VM executes during the startup process.\n- \u003cvar translate=\"no\"\u003eDOMAIN_RESOURCE_PATH\u003c/var\u003e: Full resource name of your Managed Microsoft AD domain to join. For example, `projects/my-project-123/locations/global/domains/my-domain.example.com`.\n- \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT\u003c/var\u003e: A service account that you want to attach to the VM. For example, `my-sa-123@my-project-123.iam.gserviceaccount.com`.\n- `--scopes`: The default access scopes configured in the VM restricts the domain join request. You need to set the full `cloud-platform` access scope on the VM. For more information, see [Authorization](/compute/docs/access/service-accounts#authorization).\n- `--image-project`: You need to set this flag as `windows-cloud` to create a Windows VM. For more information, see [`gcloud compute instances create`](/sdk/gcloud/reference/compute/instances/create).\n- \u003cvar translate=\"no\"\u003eIMAGE_FAMILY\u003c/var\u003e: Specify one of the [public image families](/compute/docs/images#os-compute-support) that has images for the [supported Windows versions](/managed-microsoft-ad/docs/os-versions#windows-domain-join). For example, `windows-2019-core`.\n\nFor more information about adding metadata during VM creation, see [Set metadata during VM creation](/compute/docs/metadata/setting-custom-metadata#set_during_creation).\n\n### Join an existing Windows VM\n\nYou can update the [metadata keys](/managed-microsoft-ad/docs/seamless-domain-join-gce#metadata) on an existing Windows Compute Engine VM and join the VM to your domain. After you add these metadata keys to the VM, restart the VM so that the domain join request succeeds.\n| **Caution:** If you already have a startup script that is passed to the VM using the `windows-startup-script-url` metadata key, the following approach can replace the existing startup script with the automated domain join startup script. Instead, you can use any other suitable [metadata key](/compute/docs/instances/startup-scripts/windows#metadata-keys) to pass the existing startup script, except the `windows-startup-script-url` metadata key. For example, `windows-startup-script-ps1`. For information about the script execution sequence, see [Order of execution of Windows startup scripts](/compute/docs/instances/startup-scripts/windows#order_of_execution_of_windows_startup_scripts).\n\nTo join an existing Windows Compute Engine VM, run the following gcloud CLI command: \n\n```\ngcloud compute instances add-metadata INSTANCE_NAME \\\n --metadata=windows-startup-script-url=URL,managed-ad-domain=DOMAIN_RESOURCE_PATH,managed-ad-domain-join-failure-stop=TRUE,enable-guest-attributes=TRUE \\\n --service-account=SERVICE_ACCOUNT \\\n --scopes=https://www.googleapis.com/auth/cloud-platform\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eINSTANCE_NAME\u003c/var\u003e: Name of the Windows Compute Engine VM that you want to join. For example, `my-instance-1`.\n- \u003cvar translate=\"no\"\u003eURL\u003c/var\u003e: A publicly-accessible location of the Windows startup script that the VM executes after restart.\n- \u003cvar translate=\"no\"\u003eDOMAIN_RESOURCE_PATH\u003c/var\u003e: Full resource name of your Managed Microsoft AD domain to join. For example, `projects/my-project-123/locations/global/domains/my-domain.example.com`.\n- \u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT\u003c/var\u003e: The service account that you have attached the VM during creation. For example, `my-sa-123@my-project-123.iam.gserviceaccount.com`.\n- `--scopes`: The default access scopes configured in the VM restricts the domain join request. You need to set the full `cloud-platform` access scope on the VM. For more information, see [Authorization](/compute/docs/access/service-accounts#authorization).\n\nFor more information about adding metadata to an existing VM, see [Updating metadata on a running VM](/compute/docs/metadata/setting-custom-metadata#update_metadata).\n\nClean up unjoined VMs\n---------------------\n\nWe recommend to delete the computer account manually from Managed Microsoft AD in the following scenarios:\n\n- If you delete a VM that you have joined with the Managed Microsoft AD domain.\n- If a VM has failed to join with the Managed Microsoft AD domain.\n\nView debug logs\n---------------\n\nIf the domain join request fails, you can check the logs for the startup script to identify and troubleshoot the issue. To check the logs for the startup script, you can [view Serial port 1 output](/compute/docs/troubleshooting/viewing-serial-port-output#viewing_serial_port_output). If you have enabled guest attributes on the VM, you can [get the guest attributes](/compute/docs/metadata/manage-guest-attributes#get_guest_attributes) to view the logs.\n\nFor information about the common errors that you can encounter while joining a VM to a domain, see [Unable to join a Windows VM automatically to a domain](/managed-microsoft-ad/docs/troubleshooting#domain-join-windows).\n\nWhat's next\n-----------\n\n- [Join GKE Windows Server nodes automatically to a\n Managed Microsoft AD domain](/managed-microsoft-ad/docs/automated-domain-join-gke)."]]