Hantera Azure Content Delivery Network med PowerShell

PowerShell innehåller en av de mest flexibla metoderna för att hantera dina Azure Content Delivery Network-profiler och slutpunkter. Du kan använda PowerShell interaktivt eller genom att skriva skript för att automatisera hanteringsuppgifter. Den här självstudien visar flera av de vanligaste uppgifterna du kan utföra med PowerShell för att hantera dina Azure Content Delivery Network-profiler och slutpunkter.

Förutsättningar

Kommentar

Vi rekommenderar att du använder Azure Az PowerShell-modulen för att interagera med Azure. Se Installera Azure PowerShell för att komma igång. Information om hur du migrerar till Az PowerShell-modulen finns i artikeln om att migrera Azure PowerShell från AzureRM till Az.

Om du vill använda PowerShell för att hantera dina Azure Content Delivery Network-profiler och slutpunkter måste du ha Azure PowerShell-modulen installerad. Information om hur du installerar Azure PowerShell och ansluter till Azure med hjälp av cmdleten Connect-AzAccount finns i Installera och konfigurera Azure PowerShell.

Viktigt!

Du måste logga in med Connect-AzAccount innan du kan köra Azure PowerShell-cmdletar.

Visa cmdletar för Azure Content Delivery Network

Du kan lista alla Cmdletar för Azure Content Delivery Network med hjälp av cmdleten 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

Få hjälp

Du kan få hjälp med någon av dessa cmdletar med hjälp av cmdleten Get-Help . Get-Help innehåller användning och syntax, och du kan också visa exempel.

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"

Visa en lista över befintliga Azure Content Delivery Network-profiler

Cmdleten Get-AzCdnProfile utan parametrar hämtar alla dina befintliga nätverksprofiler för innehållsleverans.

Get-AzCdnProfile

Dessa utdata kan skickas till cmdletar för uppräkning.

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

Du kan också returnera en enskild profil genom att ange profilnamnet och resursgruppen.

Get-AzCdnProfile -ProfileName CdnDemo -ResourceGroupName CdnDemoRG

Dricks

Det är möjligt att ha flera nätverksprofiler för innehållsleverans med samma namn, så länge de finns i olika resursgrupper. Om du utelämnar parametern ResourceGroupName returneras alla profiler med ett matchande namn.

Lista befintliga slutpunkter för innehållsleveransnätverk

Get-AzCdnEndpoint kan hämta en enskild slutpunkt eller alla slutpunkter i en profil.

# 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

Skapa nätverksprofiler och slutpunkter för innehållsleverans

New-AzCdnProfile och New-AzCdnEndpoint används för att skapa nätverksprofiler och slutpunkter för innehållsleverans. Följande SKU:er stöds:

  • 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

Lägga till en anpassad domän

New-AzCdnCustomDomain lägger till ett anpassat domännamn till en befintlig slutpunkt.

Viktigt!

Du måste konfigurera CNAME med DNS-providern enligt beskrivningen i Mappa anpassad domän till slutpunkten för innehållsleveransnätverket. Du kan testa mappningen innan du ändrar slutpunkten med hjälp av Test-AzCdnCustomDomain.

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

Ändra en slutpunkt

Update-AzCdnEndpoint ändrar en befintlig slutpunkt.

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

Rensning

Clear-AzCdnEndpointContent rensar cachelagrade tillgångar.

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

Läs in vissa tillgångar i förväg

Kommentar

Förinläsning är endast tillgängligt i Azure Content Delivery Network från Edgio-profiler.

Import-AzCdnEndpointContent förinläsning av tillgångar till innehållsleveransnätverkets cacheminne.

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

Starta/stoppa nätverksslutpunkter för innehållsleverans

Start-AzCdnEndpoint och Stop-AzCdnEndpoint kan användas för att starta och stoppa enskilda slutpunkter eller grupper av slutpunkter.

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

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

Skapa en standardregelmotorprincip och tillämpa den på en befintlig slutpunkt för innehållsleveransnätverket

Följande lista över cmdletar kan användas för att skapa en standardregelmotorprincip och tillämpa den på en befintlig slutpunkt för innehållsleveransnätverk.

Tillstånd:

Åtgärder:

# 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

Ta bort nätverksresurser för innehållsleverans

Remove-AzCdnProfile och Remove-AzCdnEndpoint kan användas för att ta bort profiler och slutpunkter.

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

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

Nästa steg