Mengelola Azure Content Delivery Network dengan PowerShell

PowerShell menyediakan salah satu metode paling fleksibel untuk mengelola profil dan titik akhir Azure Content Delivery Network Anda. Anda dapat menggunakan PowerShell secara interaktif atau dengan menulis skrip untuk mengotomatiskan tugas manajemen. Tutorial ini menunjukkan beberapa tugas paling umum yang dapat Anda selesaikan dengan PowerShell untuk mengelola profil dan titik akhir Azure Content Delivery Network Anda.

Prasyarat

Catatan

Sebaiknya Anda menggunakan modul Azure Az PowerShell untuk berinteraksi dengan Azure. Lihat Menginstal Azure PowerShell untuk memulai. Untuk mempelajari cara bermigrasi ke modul Az PowerShell, lihat Memigrasikan Azure PowerShell dari AzureRM ke Az.

Untuk menggunakan PowerShell untuk mengelola profil dan titik akhir Azure Content Delivery Network, Anda harus menginstal modul Azure PowerShell. Untuk mempelajari cara menginstal Azure PowerShell dan menyambungkan ke Azure menggunakan cmdlet Connect-AzAccount, lihat Cara menginstal dan mengonfigurasi Azure PowerShell.

Penting

Anda harus masuk dengan Connect-AzAccount sebelum dapat menjalankan cmdlet Azure PowerShell.

Mencantumkan cmdlet Azure Content Delivery Network

Anda dapat mencantumkan semua cmdlet Azure Content Delivery Network menggunakan Get-Command cmdlet.

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

Mendapatkan bantuan

Anda bisa mendapatkan bantuan dengan salah satu cmdlet ini menggunakan cmdlet Get-Help. Get-Help menyediakan penggunaan dan sintaks, dan secara opsional menunjukkan contoh.

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"

Mencantumkan profil Azure Content Delivery Network yang sudah ada

Get-AzCdnProfile Cmdlet tanpa parameter mengambil semua profil jaringan pengiriman konten yang ada.

Get-AzCdnProfile

Output ini dapat disalurkan ke cmdlet untuk enumerasi.

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

Anda juga dapat mengembalikan satu profil dengan menentukan nama profil dan grup sumber daya.

Get-AzCdnProfile -ProfileName CdnDemo -ResourceGroupName CdnDemoRG

Tip

Dimungkinkan untuk memiliki beberapa profil jaringan pengiriman konten dengan nama yang sama, selama mereka berada di grup sumber daya yang berbeda. Menghilangkan parameter ResourceGroupName mengembalikan semua profil dengan nama yang cocok.

Mencantumkan titik akhir jaringan pengiriman konten yang ada

Get-AzCdnEndpoint dapat mengambil titik akhir individual atau semua titik akhir di 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

Membuat profil dan titik akhir jaringan pengiriman konten

New-AzCdnProfile dan New-AzCdnEndpoint digunakan untuk membuat profil dan titik akhir jaringan pengiriman konten. SKU berikut didukung:

  • 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

Menambahkan domain kustom

New-AzCdnCustomDomain menambahkan nama domain kustom ke titik akhir yang sudah ada.

Penting

Anda harus menyiapkan CNAME dengan penyedia DNS Anda seperti yang dijelaskan dalam Cara memetakan Domain Kustom ke titik akhir Content Delivery Network. Anda dapat menguji pemetaan sebelum memodifikasi titik akhir Anda menggunakan Test-AzCdnCustomDomain.

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

Mengubah titik akhir

Update-AzCdnEndpoint memodifikasi titik akhir yang ada.

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

Membersihkan

Clear-AzCdnEndpointContent menghapus menyeluruh aset yang di-cache.

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

Pra-muat beberapa aset

Catatan

Pra-pemuatan hanya tersedia di Azure Content Delivery Network dari profil Edgio.

Import-AzCdnEndpointContent pra-pemuatan aset ke dalam cache jaringan pengiriman konten.

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

Memulai/Menghentikan titik akhir jaringan pengiriman konten

Start-AzCdnEndpoint dan Stop-AzCdnEndpoint dapat digunakan untuk memulai dan menghentikan titik akhir atau kelompok titik akhir individu.

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

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

Membuat kebijakan mesin Aturan Standar dan menerapkan ke titik akhir jaringan pengiriman konten yang ada

Daftar cmdlet berikut dapat digunakan untuk membuat kebijakan mesin Aturan Standar dan menerapkannya ke titik akhir jaringan pengiriman konten yang ada.

Kondisi:

Tindakan:

# 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

Menghapus sumber daya jaringan pengiriman konten

Remove-AzCdnProfile dan Remove-AzCdnEndpointdapat digunakan untuk menghapus profil dan titik akhir.

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

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

Langkah berikutnya

  • Pelajari cara mengotomatiskan Azure Content Delivery Network dengan .NET atau Node.js.

  • Untuk mempelajari tentang fitur jaringan pengiriman konten, lihat Gambaran Umum jaringan pengiriman konten.