PowerShell을 사용하여 Azure Content Delivery Network 관리

PowerShell은 Azure Content Delivery Network 프로필 및 엔드포인트를 관리하는 가장 유연한 방법 중 하나를 제공합니다. PowerShell을 대화형으로 또는 관리 작업을 자동화하는 스크립트를 작성하여 사용할 수 있습니다. 이 자습서에서는 PowerShell을 사용하여 Azure Content Delivery Network 프로필 및 엔드포인트를 관리하기 위해 수행할 수 있는 가장 일반적인 몇 가지 작업을 보여 줍니다.

필수 조건

참고 항목

Azure Az PowerShell 모듈을 사용하여 Azure와 상호 작용하는 것이 좋습니다. 시작하려면 Azure PowerShell 설치를 참조하세요. Az PowerShell 모듈로 마이그레이션하는 방법에 대한 자세한 내용은 Azure PowerShell을 AzureRM에서 Azure로 마이그레이션을 참조하세요.

PowerShell을 사용하여 Azure Content Delivery Network 프로필 및 엔드포인트를 관리하려면 Azure PowerShell 모듈이 설치되어 있어야 합니다. Azure PowerShell을 설치하고 Connect-AzAccount cmdlet을 사용하여 Azure에 연결하는 방법을 알아보려면 Azure PowerShell 설치 및 구성 방법을 참조하세요.

Important

Connect-AzAccount에 로그인해야 Azure PowerShell cmdlet을 실행할 수 있습니다.

Azure Content Delivery Network cmdlet 나열

cmdlet을 사용하여 모든 Azure Content Delivery Network cmdlet을 나열할 Get-Command 수 있습니다.

PS C:\> Get-Command -Module Az.Cdn

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Confirm-AzCdnEndpointProbeURL                      2.1.0      Az.Cdn
Cmdlet          Disable-AzCdnCustomDomain                          2.1.0      Az.Cdn
Cmdlet          Disable-AzCdnCustomDomainHttps                     2.1.0      Az.Cdn
Cmdlet          Enable-AzCdnCustomDomain                           2.1.0      Az.Cdn
Cmdlet          Enable-AzCdnCustomDomainHttps                      2.1.0      Az.Cdn
Cmdlet          Get-AzCdnCustomDomain                              2.1.0      Az.Cdn
Cmdlet          Get-AzCdnEdgeNode                                  2.1.0      Az.Cdn
Cmdlet          Get-AzCdnEndpoint                                  2.1.0      Az.Cdn
Cmdlet          Get-AzCdnEndpointResourceUsage                     2.1.0      Az.Cdn
Cmdlet          Get-AzCdnOrigin                                    2.1.0      Az.Cdn
Cmdlet          Get-AzCdnProfile                                   2.1.0      Az.Cdn
Cmdlet          Get-AzCdnProfileResourceUsage                      2.1.0      Az.Cdn
Cmdlet          Get-AzCdnProfileSupportedOptimizationType          2.1.0      Az.Cdn
Cmdlet          Get-AzCdnSubscriptionResourceUsage                 2.1.0      Az.Cdn
Cmdlet          New-AzCdnCustomDomain                              2.1.0      Az.Cdn
Cmdlet          New-AzCdnDeliveryPolicy                            2.1.0      Az.Cdn
Cmdlet          New-AzCdnDeliveryRule                              2.1.0      Az.Cdn
Cmdlet          New-AzCdnDeliveryRuleAction                        2.1.0      Az.Cdn
Cmdlet          New-AzCdnDeliveryRuleCondition                     2.1.0      Az.Cdn
Cmdlet          New-AzCdnEndpoint                                  2.1.0      Az.Cdn
Cmdlet          New-AzCdnProfile                                   2.1.0      Az.Cdn
Cmdlet          Remove-AzCdnCustomDomain                           2.1.0      Az.Cdn
Cmdlet          Remove-AzCdnEndpoint                               2.1.0      Az.Cdn
Cmdlet          Remove-AzCdnProfile                                2.1.0      Az.Cdn
Cmdlet          Set-AzCdnProfile                                   2.1.0      Az.Cdn
Cmdlet          Start-AzCdnEndpoint                                2.1.0      Az.Cdn
Cmdlet          Stop-AzCdnEndpoint                                 2.1.0      Az.Cdn

도움말 가져오기

Get-Help cmdlet을 사용하여 이러한 cmdlet에 대한 도움말을 볼 수 있습니다. Get-Help 는 사용량 및 구문을 제공하며 선택적으로 예제를 표시합니다.

PS C:\> Get-Help Get-AzCdnProfile

NAME
    Get-AzCdnProfile

SYNOPSIS
    Gets an Azure CDN profile.

SYNTAX
    Get-AzCdnProfile [-ProfileName <String>] [-ResourceGroupName <String>] [-InformationAction
    <ActionPreference>] [-InformationVariable <String>] [<CommonParameters>]

DESCRIPTION
    Gets an Azure CDN profile and all related information.

RELATED LINKS
    https://docs.microsoft.com/powershell/module/az.cdn/get-azcdnprofile

REMARKS
    To see the examples, type: "get-help Get-AzCdnProfile -examples".
    For more information, type: "get-help Get-AzCdnProfile -detailed".
    For technical information, type: "get-help Get-AzCdnProfile -full".
    For online help, type: "get-help Get-AzCdnProfile -online"

기존 Azure Content Delivery Network 프로필 나열

매개 변수가 없는 cmdlet은 Get-AzCdnProfile 모든 기존 콘텐츠 배달 네트워크 프로필을 검색합니다.

Get-AzCdnProfile

이 출력은 열거형에 대한 cmdlet으로 파이프될 수 있습니다.

# Output the name of all profiles on this subscription.
Get-AzCdnProfile | ForEach-Object { Write-Host $_.Name }

또한 프로필 이름 및 리소스 그룹을 지정하여 단일 프로필을 반환할 수 있습니다.

Get-AzCdnProfile -ProfileName CdnDemo -ResourceGroupName CdnDemoRG

서로 다른 리소스 그룹에 있는 한 동일한 이름의 여러 콘텐츠 배달 네트워크 프로필을 가질 수 있습니다. ResourceGroupName 매개 변수를 생략함년 일치하는 이름을 가진 모든 프로필이 반환됩니다.

기존 콘텐츠 배달 네트워크 엔드포인트 나열

Get-AzCdnEndpoint 은 개별 엔드포인트 또는 프로필의 모든 엔드포인트를 검색할 수 있습니다.

# Get a single endpoint.
Get-AzCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG -EndpointName cdndocdemo

# Get all of the endpoints on a given profile. 
Get-AzCdnEndpoint -ProfileName CdnDemo -ResourceGroupName CdnDemoRG

콘텐츠 배달 네트워크 프로필 및 엔드포인트 만들기

New-AzCdnProfile 콘텐츠 New-AzCdnEndpoint 배달 네트워크 프로필 및 엔드포인트를 만드는 데 사용됩니다. 다음 SKU가 지원됩니다.

  • Standard_Verizon
  • Premium_Verizon
  • Custom_Verizon
  • Standard_Microsoft
  • Standard_ChinaCdn
# Create a new profile
New-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Sku Standard_Microsoft -Location "Central US"

# Create a new endpoint
$origin = @{
    Name = "Contoso"
    HostName = "www.contoso.com"
};

New-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Location "Central US" -EndpointName cdnposhdoc -Origin $origin

사용자 지정 도메인 추가

New-AzCdnCustomDomain 은 기존 엔드포인트에 사용자 지정 도메인 이름을 추가합니다.

Important

Custom Do기본를 Content Delivery Network 엔드포인트매핑하는 방법에 설명된 대로 DNS 공급자를 사용하여 CNAME을 설정해야 합니다. Test-AzCdnCustomDomain를 사용하여 엔드포인트를 수정하기 전에 매핑을 시험해야 합니다.

# Create the custom domain on the endpoint
New-AzCdnCustomDomain -ResourceGroupName CdnDemoRG -ProfileName CdnPoshDemo -Name contoso -HostName "cdn.contoso.com" -EndpointName cdnposhdoc

엔드포인트 수정

Update-AzCdnEndpoint 은 기존 엔드포인트를 수정합니다.

# Update endpoint with compression settings
Update-AzCdnEndpoint -Name cdnposhdoc -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -IsCompressionEnabled -ContentTypesToCompress "text/javascript","text/css","application/json"

제거

Clear-AzCdnEndpointContent는 캐시된 자산을 제거합니다.

# Purge some assets.
Clear-AzCdnEndpointContent -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc -ContentFilePath @("/images/kitten.png","/video/rickroll.mp4")

일부 자산을 미리 로드

참고 항목

사전 로드는 Edgio 프로필의 Azure Content Delivery Network에서만 사용할 수 있습니다.

Import-AzCdnEndpointContent 자산을 콘텐츠 배달 네트워크 캐시에 미리 로드합니다.

Import-AzCdnEndpointContent -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc -ContentFilePath @("/images/kitten.png","/video/rickroll.mp4")`

콘텐츠 배달 네트워크 엔드포인트 시작/중지

Start-AzCdnEndpointStop-AzCdnEndpoint를 사용하여 개별 엔드포인트 또는 엔드포인트 그룹을 시작 및 중지할 수 있습니다.

# Stop the CdnPoshDemo endpoint
Stop-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Name cdnposhdoc

# Start the CdnPoshDemo endpoint
Start-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -Name cdnposhdoc

표준 규칙 엔진 정책 만들기 및 기존 콘텐츠 배달 네트워크 엔드포인트에 적용

다음 cmdlet 목록을 사용하여 표준 규칙 엔진 정책을 만들고 기존 콘텐츠 배달 네트워크 엔드포인트에 적용할 수 있습니다.

조건:

작업:

# Create a path based Response header modification rule. 
$cond1 = New-AzCdnDeliveryRuleUrlPathConditionObject -Name UrlPath -ParameterOperator BeginsWith -ParameterMatchValue "/images/"
$action1 = New-AzCdnDeliveryRuleResponseHeaderActionObject -Name ModifyResponseHeader -ParameterHeaderAction Overwrite -ParameterHeaderName "Access-Control-Allow-Origin" -ParameterValue "*"
$rule1 = New-AzCdnDeliveryRuleObject -Name "PathBasedCacheOverride" -Order 1 -Condition $cond1 -Action $action1

# Create a new http to https redirect rule
$cond1 = New-AzCdnDeliveryRuleRequestSchemeConditionObject -Name RequestScheme -ParameterMatchValue HTTPS
$action1 = New-AzCdnUrlRedirectActionObject -Name UrlRedirect -ParameterRedirectType Found -ParameterDestinationProtocol Https
$rule2 = New-AzCdnDeliveryRuleObject -Name "UrlRewriteRule" -Order 2 -Condition $cond1 -Action $action1

# Update existing endpoint with new rules
Update-AzCdnEndpoint -Name cdnposhdoc -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -DeliveryPolicyRule $rule1,$rule2

콘텐츠 배달 네트워크 리소스 삭제

Remove-AzCdnProfileRemove-AzCdnEndpoint를 사용하여 프로필 및 엔드포인트를 제거할 수 있습니다.

# Remove a single endpoint
Remove-AzCdnEndpoint -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG -EndpointName cdnposhdoc

# Remove a single profile
Remove-AzCdnProfile -ProfileName CdnPoshDemo -ResourceGroupName CdnDemoRG

다음 단계

  • .NET 또는 Node.js 사용하여 Azure Content Delivery Network를 자동화하는 방법을 알아봅니다.

  • 콘텐츠 배달 네트워크 기능에 대한 자세한 내용은 콘텐츠 배달 네트워크 개요를 참조 하세요.