Share via


Hulpprogramma voor schalen instellen met Behulp van Azure Automation en Azure Logic Apps voor Azure Virtual Desktop

In dit artikel vindt u informatie over het schaalprogramma dat gebruikmaakt van een Azure Automation-runbook en Azure Logic App voor het automatisch schalen van sessiehost-VM's in uw Azure Virtual Desktop-omgeving. Zie Sessiehosts schalen met Behulp van Azure Automation en Azure Logic Apps voor meer informatie over het schaalprogramma.

Notitie

  • De systeemeigen oplossing voor automatische schaalaanpassing van Azure Virtual Desktop is algemeen beschikbaar voor pool- en persoonlijke hostpools en wordt automatisch in- of uitschalen van sessiehost-VM's op basis van schaalschema. U wordt aangeraden automatische schaalaanpassing te gebruiken voor een eenvoudigere configuratie. Zie Abonnementen voor automatisch schalen voor meer informatie.

  • U kunt sessiehosts niet schalen met behulp van Azure Automation en Azure Logic Apps, samen met automatische schaalaanpassing in dezelfde hostgroep. U moet een of de andere gebruiken.

Vereisten

Voordat u begint met het instellen van het schaalprogramma, moet u ervoor zorgen dat u klaar bent met het volgende:

De computer die u gebruikt om het hulpprogramma te implementeren, moet het volgende hebben:

Als u alles klaar hebt, gaan we aan de slag.

Een Azure Automation-account maken of bijwerken

Notitie

Als u al een Azure Automation-account hebt met een runbook met een oudere versie van het schaalscript, hoeft u alleen de onderstaande instructies te volgen om te controleren of het is bijgewerkt.

Eerst hebt u een Azure Automation-account nodig om het PowerShell-runbook uit te voeren. Het proces dat in deze sectie wordt beschreven, is geldig, zelfs als u een bestaand Azure Automation-account hebt dat u wilt gebruiken om het PowerShell-runbook in te stellen. U kunt het als volgt instellen:

  1. Open PowerShell.

  2. Voer de volgende cmdlet uit om u aan te melden bij uw Azure-account.

    Login-AzAccount
    

    Notitie

    Uw account moet inzenderrechten hebben voor het Azure-abonnement waar u het schaalprogramma wilt implementeren.

  3. Voer de volgende cmdlet uit om het script voor het maken van het Azure Automation-account te downloaden:

    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. Voer de volgende cmdlet uit om het script uit te voeren en het Azure Automation-account te maken. U kunt waarden invullen voor de parameters of opmerkingen toevoegen om hun standaardwaarden te gebruiken.

    $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
    

    Notitie

    Als u met uw beleid geen schaalaanpassingsscriptbronnen in een specifieke regio kunt maken, werkt u de beleidstoewijzing bij en voegt u de regio toe die u wilt toevoegen aan de lijst met toegestane regio's.

  5. Als u nog geen Automation-account hebt gemaakt, bevat de uitvoer van de cmdlet een versleutelde webhook-URI in de automation-accountvariabele. Zorg ervoor dat u een record van de URI bewaart, omdat u deze gebruikt als parameter bij het instellen van het uitvoeringsschema voor de logische Azure-app. Als u een bestaand Automation-account bijwerkt, kunt u de webhook-URI ophalen met behulp van PowerShell voor toegang tot variabelen.

  6. Als u de parameter WorkspaceName voor Log Analytics hebt opgegeven, bevat de uitvoer van de cmdlet ook de Log Analytics-werkruimte-id en de primaire sleutel. Noteer de werkruimte-id en primaire sleutel, omdat u deze later opnieuw moet gebruiken met parameters wanneer u het uitvoeringsschema voor de logische Azure-app instelt.

  7. Nadat u uw Azure Automation-account hebt ingesteld, meldt u zich aan bij uw Azure-abonnement en controleert u of uw Azure Automation-account en het relevante runbook zijn weergegeven in de opgegeven resourcegroep, zoals wordt weergegeven in de volgende afbeelding:

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

    Als u wilt controleren of uw webhook de locatie moet zijn, selecteert u de naam van uw runbook. Ga vervolgens naar de sectie Resources van uw runbook en selecteer Webhooks.

Een beheerde identiteit maken

Nu u een Azure Automation-account hebt, moet u ook een beheerde identiteit instellen als u dat nog niet hebt gedaan. Beheerde identiteiten helpen uw runbook toegang te krijgen tot andere aan Microsoft Entra gerelateerde resources en belangrijke automatiseringsprocessen te verifiëren.

Als u een beheerde identiteit wilt instellen, volgt u de instructies in Het gebruik van een door het systeem toegewezen beheerde identiteit voor een Azure Automation-account. Zodra u een beheerde identiteit hebt gemaakt, wijst u deze toe met de juiste inzendermachtigingen voor Azure Virtual Desktop-resources, zoals hostgroepen, VM's, enzovoort. Zodra u klaar bent, gaat u terug naar dit artikel en maakt u de logische Azure-app en het uitvoeringsschema om het eerste installatieproces te voltooien.

De logische Azure-app en het uitvoeringsschema maken

Ten slotte moet u de logische Azure-app maken en een uitvoeringsschema instellen voor uw nieuwe schaalprogramma. Download en importeer eerst de PowerShell-module desktopvirtualisatie die u in uw PowerShell-sessie wilt gebruiken als u dat nog niet hebt gedaan.

  1. Open PowerShell.

  2. Voer de volgende cmdlet uit om u aan te melden bij uw Azure-account.

    Login-AzAccount
    
  3. Voer de volgende cmdlet uit om het script te downloaden voor het maken van de logische Azure-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. Voer het volgende PowerShell-script uit om de logische Azure-app en het uitvoeringsschema voor uw hostgroep te maken

    Notitie

    U moet dit script uitvoeren voor elke hostgroep die u automatisch wilt schalen, maar u hebt slechts één Azure Automation-account nodig.

    $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
    

    Nadat u het script hebt uitgevoerd, moet de logische Azure-app worden weergegeven in een resourcegroep, zoals wordt weergegeven in de volgende afbeelding.

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

    Als u wijzigingen wilt aanbrengen in het uitvoeringsschema, zoals het wijzigen van het terugkeerinterval of de tijdzone, gaat u naar de planner voor automatische schaalaanpassing van Azure Logic App en selecteert u Bewerken om naar de ontwerpfunctie voor logische apps van Azure te gaan.

    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.

Uw schaalprogramma beheren

Nu u het schaalprogramma hebt gemaakt, hebt u toegang tot de uitvoer. In deze sectie worden enkele functies beschreven die nuttig kunnen zijn.

De taakstatus weergeven

U kunt een samengevatte status van alle runbooktaken bekijken of een uitgebreidere status van een specifieke runbooktaak bekijken in Azure Portal.

Aan de rechterkant van uw geselecteerde Azure Automation-account, onder Taakstatistieken, kunt u een lijst met samenvattingen van alle runbooktaken weergeven. Als u de pagina Taken aan de linkerkant van het venster opent, worden de huidige taakstatussen, begintijden en voltooiingstijden weergegeven.

A screenshot of the job status page.

Uitvoer van logboeken en hulpprogramma's voor schalen weergeven

U kunt de logboeken van uit- en inschaalbewerkingen bekijken door uw runbook te openen en de taak te selecteren.

Navigeer naar het runbook in uw resourcegroep dat als host fungeert voor het Azure Automation-account en selecteer Overzicht. Selecteer op de overzichtspagina een taak onder Recente taken om de uitvoer van het schaalprogramma weer te geven, zoals wordt weergegeven in de volgende afbeelding.

An image of the output window for the scaling tool.

Controleer het versienummer van het runbookscript

U kunt controleren welke versie van het runbookscript u gebruikt door het runbookbestand in uw Azure Automation-account te openen en Weergave te selecteren. Aan de rechterkant van het scherm wordt een script voor het runbook weergegeven. In het script ziet u het versienummer in de notatie v#.#.# onder de SYNOPSIS sectie. Hier vindt u het meest recente versienummer. Als u geen versienummer in uw runbookscript ziet, betekent dit dat u een eerdere versie van het script uitvoert en dat u het meteen moet bijwerken. Als u uw runbookscript wilt bijwerken, volgt u de instructies in Een Azure Automation-account maken of bijwerken.

Problemen melden

Wanneer u een probleem meldt, moet u de volgende informatie opgeven om ons te helpen bij het oplossen van problemen:

  • Een volledig logboek van het tabblad Alle logboeken in de taak die het probleem heeft veroorzaakt. Als u wilt weten hoe u het logboek kunt ophalen, volgt u de instructies in Logboeken weergeven en de uitvoer van het hulpprogramma voor schalen. Als er gevoelige of persoonlijke gegevens in het logboek staan, kunt u deze verwijderen voordat u het probleem bij ons indient.

  • De versie van het runbookscript dat u gebruikt. Zie Het versienummer van het runbookscript controleren om erachter te komen hoe u het versienummer van het runbook kunt ophalen

  • Het versienummer van elk van de volgende PowerShell-modules die zijn geïnstalleerd in uw Azure Automation-account. Als u deze modules wilt vinden, opent u het Azure Automation-account, selecteert u Modules onder de sectie Gedeelde resources in het deelvenster aan de linkerkant van het venster en zoekt u naar de naam van de module.

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

Log Analytics

Als u hebt besloten Om Log Analytics te gebruiken, kunt u alle logboekgegevens weergeven in een aangepast logboek met de naam WVDTenantScale_CL onder Aangepaste logboeken in de weergave Logboeken van uw Log Analytics-werkruimte. We hebben enkele voorbeeldquery's vermeld die u mogelijk nuttig vindt.

  • Als u alle logboeken voor een hostgroep wilt zien, voert u de volgende query in:

    WVDTenantScale_CL
    | where hostpoolName_s == "<host_pool_name>"
    | project TimeStampUTC = TimeGenerated, TimeStampLocal = TimeStamp_s, HostPool = hostpoolName_s, LineNumAndMessage = logmessage_s, AADTenantId = TenantId
    
  • Als u het totale aantal actieve sessiehost-VM's en actieve gebruikerssessies in uw hostgroep wilt weergeven, voert u de volgende query in:

    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
    
  • Als u de status van alle sessiehost-VM's in een hostgroep wilt weergeven, voert u de volgende query in:

    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
    
  • Voer de volgende query in om eventuele fouten en waarschuwingen weer te geven:

    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
    

Beperkingen

Hier volgen enkele beperkingen voor het schalen van sessiehost-VM's met dit schaalscript:

  • Het schaalscript beschouwt geen tijdswijzigingen tussen standaard- en zomertijd.