Azure Virtual Desktop용 Azure Logic Apps 및 Azure Automation을 사용하여 크기 조정 도구 설정

이 문서에서는 Azure Virtual Desktop 환경에서 Azure Automation Runbook 및 Azure Logic App을 사용하여 세션 호스트 VM의 크기를 자동으로 조정하는 크기 조정 도구에 대해 알아봅니다. 크기 조정 도구에 대한 자세한 내용은 Azure Automation 및 Azure Logic Apps를 사용하여 세션 호스트 크기 조정을 참조하세요.

참고 항목

  • Azure Virtual Desktop의 네이티브 자동 크기 조정 솔루션은 일반적으로 풀링된 호스트 풀과 개인 호스트 풀에 사용할 수 있으며 크기 조정 일정에 따라 세션 호스트 VM을 자동으로 스케일 인하거나 스케일 아웃합니다. 보다 쉬운 구성을 위해 자동 크기 조정을 사용하는 것이 좋습니다. 자세한 내용은 크기 조정 계획 자동 크기 조정을 참조하세요.

  • 동일한 호스트 풀에서 자동 크기 조정을 사용하여 Azure Automation 및 Azure Logic Apps를 사용하는 세션 호스트의 크기를 함께 조정할 수는 없습니다. 둘 중 하나만 사용해야 합니다.

필수 조건

크기 조정 도구를 설정하기 전에 먼저 다음을 준비해야 합니다.

  • Azure Virtual Desktop 호스트 풀.
  • Azure Virtual Desktop 서비스를 사용하여 구성 및 등록된 세션 호스트 풀 VM.
  • 리소스를 만들기 위해 Azure 구독에 할당된 기여자 RBAC(역할 기반 액세스 제어) 역할이 있는 사용자입니다. 또한 관리 ID를 만들려면 애플리케이션 관리자 및/또는 소유자 RBAC 역할이 필요합니다.
  • Log Analytics 작업 영역(선택 사항).

도구를 배포하는 데 사용할 머신에는 다음이 필요합니다.

모든 준비가 되었다면 시작할 예정입니다.

Azure Automation 계정 만들기 또는 업데이트

참고 항목

이전 버전의 크기 조정 스크립트를 실행 하는 Runbook이 있는 Azure Automation 계정이 이미 있는 경우 다음 지침에 따라 업데이트되었는지 확인해야 합니다.

먼저 PowerShell Runbook을 실행할 Azure Automation 계정이 필요합니다. 이 섹션에서 설명하는 프로세스는 PowerShell Runbook을 설정하는 데 사용하려는 기존 Azure Automation 계정이 있는 경우에도 유효합니다. 설정 방법은 다음과 같습니다.

  1. PowerShell을 엽니다.

  2. 다음 cmdlet을 실행하여 Azure 계정에 로그인합니다.

    Login-AzAccount
    

    참고

    계정에는 크기 조정 도구를 배포할 Azure 구독에 대한 기여자 권한이 있어야 합니다.

  3. 다음 cmdlet을 실행하여 Azure Automation 계정을 만드는 스크립트를 다운로드합니다.

    New-Item -ItemType Directory -Path "C:\Temp" -Force
    Set-Location -Path "C:\Temp"
    $Uri = "https://raw.githubusercontent.com/Azure/RDS-Templates/master/wvd-templates/wvd-scaling-script/CreateOrUpdateAzAutoAccount.ps1"
    # Download the script
    Invoke-WebRequest -Uri $Uri -OutFile ".\CreateOrUpdateAzAutoAccount.ps1"
    
  4. 다음 cmdlet을 실행하여 스크립트를 실행하고 Azure Automation 계정을 만듭니다. 매개 변수에 대한 값을 입력하거나 기본값을 사용하도록 주석을 지정할 수 있습니다.

    $Params = @{
         "AADTenantId"           = "<Azure_Active_Directory_tenant_ID>"   # Optional. If not specified, it will use the current Azure context
         "SubscriptionId"        = "<Azure_subscription_ID>"              # Optional. If not specified, it will use the current Azure context
         "UseARMAPI"             = $true
         "ResourceGroupName"     = "<Resource_group_name>"                # Optional. Default: "WVDAutoScaleResourceGroup"
         "AutomationAccountName" = "<Automation_account_name>"            # Optional. Default: "WVDAutoScaleAutomationAccount"
         "Location"              = "<Azure_region_for_deployment>"
         "WorkspaceName"         = "<Log_analytics_workspace_name>"       # Optional. If specified, Log Analytics will be used to configure the custom log table that the runbook PowerShell script can send logs to
    }
    
    .\CreateOrUpdateAzAutoAccount.ps1 @Params
    

    참고 항목

    정책이 특정 지역에 조정 스크립트 리소스를 만들도록 허용하지 않는 경우 정책 할당을 업데이트하고 허용되는 지역 목록에 원하는 지역을 추가합니다.

  5. 이전에 자동화 계정을 만든 적이 없는 경우 cmdlet의 출력에는 자동화 계정 변수에 암호화된 웹후크 URI가 포함됩니다. URI를 기록해 두세요. 이 값은 Azure Logic App에 대해 실행 일정을 설정할 때 매개 변수로 사용합니다. 기존 자동화 계정을 업데이트하는 경우 PowerShell을 사용하여 변수에 액세스하여 웹후크 URI를 검색할 수 있습니다.

  6. Log Analytics에 대해 WorkspaceName 매개 변수를 지정한 경우 cmdlet의 출력에는 Log Analytics 작업 영역 ID 및 해당 기본 키도 포함됩니다. Azure Logic App에 대한 실행 일정을 설정할 때 나중에 매개 변수와 함께 작업 영역 ID 및 기본 키를 다시 사용해야 하기 때문에 작업 영역 ID 및 기본 키를 기록해 둡니다.

  7. Azure Automation 계정을 설정한 후에는 Azure 구독에 로그인하고 다음 그림과 같이 Azure Automation 계정 및 관련 Runbook이 지정된 리소스 그룹에 표시되는지 확인합니다.

    An image of the Azure overview page showing the newly created Azure Automation account and runbook.

    웹후크가 제자리에 있는지 확인하려면 Runbook의 이름을 선택합니다. 그런 다음 Runbook의 리소스 섹션으로 이동하여 웹후크를 선택합니다.

관리 ID 만들기

이제 Azure Automation 계정이 있으므로 관리 ID를 설정해야 합니다(아직 없는 경우). 관리 ID는 Runbook이 다른 Microsoft Entra 관련 리소스에 액세스하고 중요한 자동화 프로세스를 인증하는 데 도움이 됩니다.

관리 ID를 설정하려면 Azure Automation 계정에 시스템이 할당한 관리 ID 사용의 지침을 따릅니다. 관리 ID를 만든 후에는 호스트 풀, VM 등과 같은 Azure Virtual Desktop 리소스에 대한 적절한 기여자 권한을 할당합니다. 완료한 후 이 문서로 돌아와서 Azure 논리 앱 및 실행 일정 만들기를 수행하여 초기 설정 프로세스를 완료합니다.

Azure Logic App 및 실행 일정 만들기

마지막으로, Azure Logic App을 만들고 새 크기 조정 도구의 실행 일정을 설정해야 합니다. 먼저 PowerShell 세션에서 사용할 Virtual Desktop PowerShell 모듈을 다운로드하고 가져옵니다(아직 없는 경우).

  1. PowerShell을 엽니다.

  2. 다음 cmdlet을 실행하여 Azure 계정에 로그인합니다.

    Login-AzAccount
    
  3. 다음 cmdlet을 실행하여 Azure Logic App을 만들기 위한 스크립트를 다운로드합니다.

    New-Item -ItemType Directory -Path "C:\Temp" -Force
    Set-Location -Path "C:\Temp"
    $Uri = "https://raw.githubusercontent.com/Azure/RDS-Templates/master/wvd-templates/wvd-scaling-script/CreateOrUpdateAzLogicApp.ps1"
    # Download the script
    Invoke-WebRequest -Uri $Uri -OutFile ".\CreateOrUpdateAzLogicApp.ps1"
    
  4. 다음 PowerShell 스크립트를 실행하여 호스트 풀에 대한 Azure Logic App 및 실행 일정을 만듭니다.

    참고 항목

    자동 크기 조정을 수행하려는 각 호스트 풀에 대해 이 스크립트를 실행해야 하지만 Azure Automation 계정은 하나만 필요합니다.

    $AADTenantId = (Get-AzContext).Tenant.Id
    
    $AzSubscription = Get-AzSubscription | Out-GridView -OutputMode:Single -Title "Select your Azure Subscription"
    Select-AzSubscription -Subscription $AzSubscription.Id
    
    $ResourceGroup = Get-AzResourceGroup | Out-GridView -OutputMode:Single -Title "Select the resource group for the new Azure Logic App"
    
    $WVDHostPool = Get-AzResource -ResourceType "Microsoft.DesktopVirtualization/hostpools" | Out-GridView -OutputMode:Single -Title "Select the host pool you'd like to scale"
    
    $LogAnalyticsWorkspaceId = Read-Host -Prompt "If you want to use Log Analytics, enter the Log Analytics Workspace ID returned by when you created the Azure Automation account, otherwise leave it blank"
    $LogAnalyticsPrimaryKey = Read-Host -Prompt "If you want to use Log Analytics, enter the Log Analytics Primary Key returned by when you created the Azure Automation account, otherwise leave it blank"
    $RecurrenceInterval = Read-Host -Prompt "Enter how often you'd like the job to run in minutes, e.g. '15'"
    $BeginPeakTime = Read-Host -Prompt "Enter the start time for peak hours in local time, e.g. 9:00"
    $EndPeakTime = Read-Host -Prompt "Enter the end time for peak hours in local time, e.g. 18:00"
    $TimeDifference = Read-Host -Prompt "Enter the time difference between local time and UTC in hours, e.g. +5:30"
    $SessionThresholdPerCPU = Read-Host -Prompt "Enter the maximum number of sessions per CPU that will be used as a threshold to determine when new session host VMs need to be started during peak hours"
    $MinimumNumberOfRDSH = Read-Host -Prompt "Enter the minimum number of session host VMs to keep running during off-peak hours"
    $MaintenanceTagName = Read-Host -Prompt "Enter the name of the Tag associated with VMs you don't want to be managed by this scaling tool"
    $LimitSecondsToForceLogOffUser = Read-Host -Prompt "Enter the number of seconds to wait before automatically signing out users. If set to 0, any session host VM that has user sessions, will be left untouched"
    $LogOffMessageTitle = Read-Host -Prompt "Enter the title of the message sent to the user before they are forced to sign out"
    $LogOffMessageBody = Read-Host -Prompt "Enter the body of the message sent to the user before they are forced to sign out"
    
    $WebhookURI = Read-Host -Prompt "Enter the webhook URI that has already been generated for this Azure Automation account. The URI is stored as encrypted in the above Automation Account variable. To retrieve the value, see https://learn.microsoft.com/azure/automation/shared-resources/variables?tabs=azure-powershell#powershell-cmdlets-to-access-variables"
    
    $Params = @{
         "AADTenantId"                   = $AADTenantId                             # Optional. If not specified, it will use the current Azure context
         "SubscriptionID"                = $AzSubscription.Id                       # Optional. If not specified, it will use the current Azure context
         "ResourceGroupName"             = $ResourceGroup.ResourceGroupName         # Optional. Default: "WVDAutoScaleResourceGroup"
         "Location"                      = $ResourceGroup.Location                  # Optional. Default: "West US2"
         "UseARMAPI"                     = $true
         "HostPoolName"                  = $WVDHostPool.Name
         "HostPoolResourceGroupName"     = $WVDHostPool.ResourceGroupName           # Optional. Default: same as ResourceGroupName param value
         "LogAnalyticsWorkspaceId"       = $LogAnalyticsWorkspaceId                 # Optional. If not specified, script will not log to the Log Analytics
         "LogAnalyticsPrimaryKey"        = $LogAnalyticsPrimaryKey                  # Optional. If not specified, script will not log to the Log Analytics
         "RecurrenceInterval"            = $RecurrenceInterval                      # Optional. Default: 15
         "BeginPeakTime"                 = $BeginPeakTime                           # Optional. Default: "09:00"
         "EndPeakTime"                   = $EndPeakTime                             # Optional. Default: "17:00"
         "TimeDifference"                = $TimeDifference                          # Optional. Default: "-7:00"
         "SessionThresholdPerCPU"        = $SessionThresholdPerCPU                  # Optional. Default: 1
         "MinimumNumberOfRDSH"           = $MinimumNumberOfRDSH                     # Optional. Default: 1
         "MaintenanceTagName"            = $MaintenanceTagName                      # Optional.
         "LimitSecondsToForceLogOffUser" = $LimitSecondsToForceLogOffUser           # Optional. Default: 1
         "LogOffMessageTitle"            = $LogOffMessageTitle                      # Optional. Default: "Machine is about to shutdown."
         "LogOffMessageBody"             = $LogOffMessageBody                       # Optional. Default: "Your session will be logged off. Please save and close everything."
         "WebhookURI"                    = $WebhookURI
    }
    
    .\CreateOrUpdateAzLogicApp.ps1 @Params
    

    스크립트를 실행한 후 다음 그림처럼 Azure Logic App이 리소스 그룹에 표시됩니다.

    An image of the overview page for an example Azure Logic App.

    되풀이 간격이나 표준 시간대를 변경하는 등 실행 일정을 변경하려면 Azure Logic App 자동 스케일링 스케줄러로 이동하고 편집을 선택하여 Azure Logic App 디자이너로 이동합니다.

    An image of the Azure Logic App Designer. The Recurrence and webhook menus that let the user edit recurrence times and the webhook file are open.

크기 조정 도구 관리

크기 조정 도구를 만들었으니 이제 출력에 액세스할 수 있습니다. 이 섹션에서는 몇 가지 유용한 기능에 대해 설명합니다.

작업 상태 보기

모든 Runbook 작업의 요약 상태를 보거나 Azure Portal에서 특정 Runbook 작업의 세부 상태를 볼 수 있습니다.

선택한 Azure Automation 계정 오른쪽에 있는 “작업 통계” 아래에서 모든 Runbook 작업의 요약을 볼 수 있습니다. 창 왼쪽에서 작업 페이지를 열면 현재 작업 상태, 시작 시간 및 완료 시간이 표시됩니다.

A screenshot of the job status page.

로그 및 크기 조정 도구 출력 보기

Runbook을 열고 작업을 선택하여 스케일 아웃 및 스케일 인 작업의 로그를 볼 수 있습니다.

Azure Automation 계정을 호스트하는 리소스 그룹의 Runbook으로 이동하여 개요를 선택합니다. 다음 그림처럼 개요 페이지의 최근 작업 아래에서 작업을 선택하면 크기 조정 도구 출력을 볼 수 있습니다.

An image of the output window for the scaling tool.

Runbook 스크립트 버전 번호 확인

Azure Automation 계정에서 Runbook 파일을 열고 보기를 선택하여 사용 중인 Runbook 스크립트 버전을 확인할 수 있습니다. Runbook에 대한 스크립트가 화면 오른쪽에 표시됩니다. 스크립트에서 버전 번호는 v#.#.# 형식으로 SYNOPSIS 섹션 아래에 표시됩니다. 최신 버전은 여기에서 찾을 수 있습니다. Runbook 스크립트에 버전 번호가 표시되지 않으면 이전 버전의 스크립트를 실행 중임을 의미하며, 즉시 업데이트해야 합니다. Runbook 스크립트를 업데이트해야 하는 경우 Azure Automation 계정 만들기 또는 업데이트의 지침을 따르세요.

문제 보고

문제를 보고하는 경우 문제 해결에 도움이 되도록 다음 정보를 제공해야 합니다.

  • 문제의 원인이 된 작업의 모든 로그 탭에 있는 전체 로그입니다. 로그를 가져오는 방법을 알아보려면 로그 보기 및 크기 조정 도구 출력의 지침을 따르세요. 로그에 중요한 정보나 개인 정보가 있는 경우 문제를 Microsoft에 제출하기 전에 제거할 수 있습니다.

  • 사용 중인 Runbook 스크립트의 버전입니다. 버전 번호를 가져오는 방법을 알아보려면 Runbook 스크립트 버전 번호 확인을 참조하세요.

  • Azure Automation 계정에 설치된 다음 PowerShell 모듈의 버전 번호입니다. 이러한 모듈을 찾으려면 Azure Automation 계정을 열고 창의 왼쪽 창에 있는 공유 리소스 섹션에서 모듈을 선택한 다음, 모듈의 이름을 검색합니다.

    • Az.Accounts
    • Az.Compute
    • Az.Resources
    • Az.Automation
    • OMSIngestionAPI
    • Az.DesktopVirtualization

Log Analytics

Log Analytics를 사용하기로 결정한 경우 Log Analytics 작업 영역의 로그 보기에서 사용자 지정 로그 아래의 WVDTenantScale_CL이라는 사용자 지정 로그의 모든 로그 데이터를 볼 수 있습니다. 다음은 유용하게 사용할 수 있는 몇 가지 샘플 쿼리를 나열한 것입니다.

  • 호스트 풀의 모든 로그를 보려면 다음 쿼리를 입력합니다.

    WVDTenantScale_CL
    | where hostpoolName_s == "<host_pool_name>"
    | project TimeStampUTC = TimeGenerated, TimeStampLocal = TimeStamp_s, HostPool = hostpoolName_s, LineNumAndMessage = logmessage_s, AADTenantId = TenantId
    
  • 호스트 풀에서 현재 실행 중인 세션 호스트 VM 및 활성 사용자 세션의 총 수를 보려면 다음 쿼리를 입력합니다.

    WVDTenantScale_CL
    | where logmessage_s contains "Number of running session hosts:"
         or logmessage_s contains "Number of user sessions:"
         or logmessage_s contains "Number of user sessions per Core:"
    | where hostpoolName_s == "<host_pool_name>"
    | project TimeStampUTC = TimeGenerated, TimeStampLocal = TimeStamp_s, HostPool = hostpoolName_s, LineNumAndMessage = logmessage_s, AADTenantId = TenantId
    
  • 호스트 풀에 있는 모든 세션 호스트 VM의 상태를 보려면 다음 쿼리를 입력합니다.

    WVDTenantScale_CL
    | where logmessage_s contains "Session host:"
    | where hostpoolName_s == "<host_pool_name>"
    | project TimeStampUTC = TimeGenerated, TimeStampLocal = TimeStamp_s, HostPool = hostpoolName_s, LineNumAndMessage = logmessage_s, AADTenantId = TenantId
    
  • 오류 및 경고를 보려면 다음 쿼리를 입력합니다.

    WVDTenantScale_CL
    | where logmessage_s contains "ERROR:" or logmessage_s contains "WARN:"
    | project TimeStampUTC = TimeGenerated, TimeStampLocal = TimeStamp_s, HostPool = hostpoolName_s, LineNumAndMessage = logmessage_s, AADTenantId = TenantId
    

제한 사항

다음은 이 크기 조정 스크립트를 사용하는 크기 조정 세션 호스트 VM에 관한 몇 가지 제한 사항입니다.

  • 크기 조정 스크립트는 표준 시간제와 일광 절약 시간제 사이의 시간 변경을 고려하지 않습니다.