PowerShell을 사용하여 Azure Cloud Services(클래식)에 진단 사용

Important

신규 고객에게는 Cloud Services(클래식)가 사용되지 않으며 모든 고객에 대해 2024년 8월 31일에 사용 중지됩니다. 새 배포에서는 새로운 Azure Resource Manager 기반 배포 모델인 Azure Cloud Services(추가 지원)를 사용해야 합니다.

Azure Diagnostics 확장을 사용하여 클라우드 서비스로부터 애플리케이션 로그, 성능 카운터 등과 같은 진단 데이터를 수집할 수 있습니다. 이 문서는 PowerShell을 사용하여 클라우드 서비스에 대해 Azure Diagnostics 확장을 사용하도록 설정하는 방법을 설명합니다. 이 문서에 필요한 필수 조건은 Azure PowerShell 설치 및 구성하는 방법 을 참조하세요.

클라우드 서비스 배포의 일부로 진단 확장을 사용하도록 설정

이 접근 방식은 진단 확장이 클라우드 서비스의 배포 중 일부로 사용될 수 있는 연속 통합 형식의 시나리오에 적용됩니다. 새 클라우드 서비스 배포를 생성할 때 ExtensionConfiguration 매개 변수를 New-Azure Deployment cmdlet에 전달하여 진단 확장을 사용하도록 설정할 수 있습니다. ExtensionConfiguration 매개 변수는 New-AzureServiceDiagnosticsExtensionConfig cmdlet을 사용하여 만들 수 있는 진단 구성 배열을 사용합니다.

다음 예제는 각각 진단 구성이 다른 WebRole 및 WorkerRole을 사용하여 클라우드 서비스에 대해 진단을 사용하도록 설정하는 방법을 보여줍니다.

$service_name = "MyService"
$service_package = "CloudService.cspkg"
$service_config = "ServiceConfiguration.Cloud.cscfg"
$webrole_diagconfigpath = "MyService.WebRole.PubConfig.xml"
$workerrole_diagconfigpath = "MyService.WorkerRole.PubConfig.xml"

$webrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WebRole" -DiagnosticsConfigurationPath $webrole_diagconfigpath
$workerrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WorkerRole" -DiagnosticsConfigurationPath $workerrole_diagconfigpath

New-AzureDeployment -ServiceName $service_name -Slot Production -Package $service_package -Configuration $service_config -ExtensionConfiguration @($webrole_diagconfig,$workerrole_diagconfig)

진단 구성 파일이 스토리지 계정 이름으로 StorageAccount 요소를 지정할 경우 New-AzureServiceDiagnosticsExtensionConfig cmdlet에서 해당 스토리지 계정을 자동으로 사용합니다. 이 구성이 작동하려면, 스토리지 계정이 배포된 클라우드 서비스와 동일한 구독에 있어야 합니다.

Azure SDK 2.6 이후부터 MSBuild 게시 대상 출력에 의해 생성된 확장 구성 파일은 서비스 구성 파일(.cscfg)에 지정된 진단 구성 문자열에 기반한 스토리지 계정 이름을 포함합니다. 다음 스크립트에서는 게시 대상 출력에서 확장 구성 파일을 구문 분석하고 클라우드 서비스를 배포할 때 각 역할에 대한 진단 확장을 구성하는 방법을 보여 줍니다.

$service_name = "MyService"
$service_package = "C:\build\output\CloudService.cspkg"
$service_config = "C:\build\output\ServiceConfiguration.Cloud.cscfg"

#Find the Extensions path based on service configuration file
$extensionsSearchPath = Join-Path -Path (Split-Path -Parent $service_config) -ChildPath "Extensions"

$diagnosticsExtensions = Get-ChildItem -Path $extensionsSearchPath -Filter "PaaSDiagnostics.*.PubConfig.xml"
$diagnosticsConfigurations = @()
foreach ($extPath in $diagnosticsExtensions)
{
    #Find the RoleName based on file naming convention PaaSDiagnostics.<RoleName>.PubConfig.xml
    $roleName = ""
    $roles = $extPath -split ".",0,"simplematch"
    if ($roles -is [system.array] -and $roles.Length -gt 1)
    {
        $roleName = $roles[1]
        $x = 2
        while ($x -le $roles.Length)
            {
               if ($roles[$x] -ne "PubConfig")
                {
                    $roleName = $roleName + "." + $roles[$x]
                }
                else
                {
                    break
                }
                $x++
            }
        $fullExtPath = Join-Path -path $extensionsSearchPath -ChildPath $extPath
        $diagnosticsconfig = New-AzureServiceDiagnosticsExtensionConfig -Role $roleName -DiagnosticsConfigurationPath $fullExtPath
        $diagnosticsConfigurations += $diagnosticsconfig
    }
}
New-AzureDeployment -ServiceName $service_name -Slot Production -Package $service_package -Configuration $service_config -ExtensionConfiguration $diagnosticsConfigurations

Visual Studio Codespace는 진단 확장으로 Cloud Services의 자동화된 배포에 대해 유사한 접근 방식을 사용합니다. 전체 예제는 Publish-AzureCloudDeployment.ps1 을 참조하세요.

진단 구성에 StorageAccount가 지정되지 않은 경우 cmdlet에 StorageAccountName 매개 변수를 전달해야 합니다. StorageAccountName 매개 변수를 지정한 경우 cmdlet은 진단 구성 파일에 지정된 스토리지 계정이 아닌 매개 변수에 지정된 스토리지 계정을 사용합니다.

진단 스토리지 계정이 클라우드 서비스와 다른 구독에 있는 경우 StorageAccountNameStorageAccountKey 매개 변수를 cmdlet에 명시적으로 전달해야 합니다. 진단 스토리지 계정이 동일한 구독에 있는 경우 진단 확장을 사용하도록 설정하면 cmdlet이 키 값을 자동으로 쿼리하고 설정할 수 있으므로 StorageAccountKey 매개 변수가 필요하지 않습니다. 하지만 진단 스토리지 계정이 다른 구독에 있는 경우에는 cmdlet이 자동으로 키를 얻지 못할 수 있으며, 사용자가 StorageAccountKey 매개 변수를 통해 키를 명시적으로 지정해야 합니다.

$webrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WebRole" -DiagnosticsConfigurationPath $webrole_diagconfigpath -StorageAccountName $diagnosticsstorage_name -StorageAccountKey $diagnosticsstorage_key
$workerrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WorkerRole" -DiagnosticsConfigurationPath $workerrole_diagconfigpath -StorageAccountName $diagnosticsstorage_name -StorageAccountKey $diagnosticsstorage_key

기존 클라우드 서비스에 진단 확장을 사용하도록 설정

Set-AzureServiceDiagnosticsExtension cmdlet을 사용하여 이미 실행 중인 클라우드 서비스에 진단 구성을 사용하거나 업데이트할 수 있습니다.

Warning

기존 역할에서 진단을 사용하도록 설정한 경우 패키지를 배포하면 이미 설정한 모든 확장이 비활성화됩니다. 여기에는 다음이 포함됩니다.

  • Microsoft Monitoring Agent 진단
  • Microsoft Azure 보안 모니터링
  • Microsoft Antimalware
  • Microsoft Monitoring Agent
  • Microsoft Service Profiler Agent
  • Windows Azure 도메인 확장
  • Windows Azure Diagnostics 확장
  • Windows Azure 원격 데스크톱 확장
  • Windows Azure 로그 수집기

업데이트 된 역할을 배포한 후에 Azure Portal 또는 PowerShell을 통해 확장을 재설정할 수 있습니다.

$service_name = "MyService"
$webrole_diagconfigpath = "MyService.WebRole.PubConfig.xml"
$workerrole_diagconfigpath = "MyService.WorkerRole.PubConfig.xml"

$webrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WebRole" -DiagnosticsConfigurationPath $webrole_diagconfigpath
$workerrole_diagconfig = New-AzureServiceDiagnosticsExtensionConfig -Role "WorkerRole" -DiagnosticsConfigurationPath $workerrole_diagconfigpath

Set-AzureServiceDiagnosticsExtension -DiagnosticsConfiguration @($webrole_diagconfig,$workerrole_diagconfig) -ServiceName $service_name

현재 진단 확장 구성 가져오기

Get-AzureServiceDiagnosticsExtension cmdlet을 사용하여 클라우드 서비스에 대한 현재 진단 구성을 가져올 수 있습니다.

Get-AzureServiceDiagnosticsExtension -ServiceName "MyService"

진단 확장 제거

클라우드 서비스에서 진단을 해제하려면 Remove-AzureServiceDiagnosticsExtension cmdlet을 사용합니다.

Remove-AzureServiceDiagnosticsExtension -ServiceName "MyService"

‘역할’ 매개 변수 없이 Set-AzureServiceDiagnosticsExtension 또는 New-AzureServiceDiagnosticsExtensionConfig를 사용하여 진단 확장을 사용하도록 설정한 경우에는 ‘역할’ 매개 변수 없이 Remove-AzureServiceDiagnosticsExtension을 사용하여 확장을 제거할 수 있습니다. ‘역할’ 매개 변수가 확장을 사용하도록 설정할 때 사용되었으면, 확장을 제거할 때도 사용되어야 합니다.

각각의 개별 역할에서 진단 확장을 제거하려면:

Remove-AzureServiceDiagnosticsExtension -ServiceName "MyService" -Role "WebRole"

다음 단계