次の方法で共有


PowerShell を使用した Azure Content Delivery Network (CDN) の管理

PowerShell により、Azure Content Delivery Network のプロファイルとエンドポイントを柔軟に管理することができます。 この PowerShell は対話的に使用することも、スクリプトを記述して、管理タスクを自動化することもできます。 このチュートリアルでは、Azure Content Delivery Network のプロファイルとエンドポイントを管理するために、PowerShell で実行できる一般的なタスクをいくつか紹介します。

前提条件

Note

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、「Azure PowerShell のインストール」を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

PowerShell を使用して Azure Content Delivery Network のプロファイルとエンドポイントを管理するには、Azure PowerShell モジュールをインストールする必要があります。 Connect-AzAccount コマンドレットを使用して Azure PowerShell をインストールし、Azure に接続する方法については、「 Azure PowerShell のインストールおよび構成方法」を参照してください。

重要

Azure PowerShell コマンドレットを実行する前に、Connect-AzAccount でログインする必要があります。

Azure Content Delivery Network コマンドレットの一覧表示

Azure Content Delivery Network コマンドレットの一覧を表示するには、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 コマンドレットを使用します。 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 プロファイルの一覧表示

パラメーターを指定せずに Get-AzCdnProfile コマンドレットを実行すると、既存の Content Delivery Network プロファイルをすべて取得できます。

Get-AzCdnProfile

この出力は、列挙のコマンドレットにパイプ処理できます。

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

また、プロファイル名とリソース グループを指定して、1 つのプロファイルを返すこともできます。

Get-AzCdnProfile -ProfileName CdnDemo -ResourceGroupName CdnDemoRG

ヒント

複数のリソース グループがある場合は、それぞれのグループに同じ名前の Content Delivery Network プロファイルが存在する可能性があります。 ResourceGroupName パラメーターを省略すると、名前が一致するすべてのプロファイルが返されます。

既存の Content Delivery Network エンドポイントの一覧表示

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

Content Delivery Network のプロファイルとエンドポイントの作成

New-AzCdnProfileNew-AzCdnEndpoint が Content Delivery Network のプロファイルとエンドポイントの作成に使用されます。 次の 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 は、カスタム ドメイン名を既存のエンドポイントに追加します。

重要

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")

一部の資産を事前に読み込む

Note

事前読み込みは、Edgio プロファイルからの Azure Content Delivery Network でのみ使用できます。

Import-AzCdnEndpointContent は、Content Delivery Network キャッシュにアセットを事前に読み込みます。

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

Content Delivery Network エンドポイントの開始/停止

Start-AzCdnEndpoint および Stop-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

標準ルール エンジン ポリシーの作成と、既存の Content Delivery Network エンドポイントへの適用

次のコマンドレットの一覧を使用して、標準ルール エンジン ポリシーを作成し、既存の Content Delivery Network エンドポイントに適用できます。

条件:

アクション:

# 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

Content Delivery Network リソースの削除

Remove-AzCdnProfile および Remove-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 を自動化する方法について学習します。

  • Content Delivery Network 機能の詳細については、Content Delivery Network の概要に関するページを参照してください。