Membuat database dan grafik dengan autoscale untuk Azure Cosmos DB - Gremlin API
BERLAKU UNTUK:
Gremlin API
Catatan
Artikel ini menggunakan modul Azure Az PowerShell, yang merupakan modul PowerShell yang direkomendasikan untuk berinteraksi dengan Azure. Untuk mulai menggunakan modul Az PowerShell, lihat Menginstal Azure PowerShell. Untuk mempelajari cara bermigrasi ke modul Az PowerShell, lihat Memigrasikan Azure PowerShell dari AzureRM ke Az.
Sampel ini memerlukan Azure PowerShell Az 5.4.0 atau yang lebih baru. Jalankan Get-Module -ListAvailable Az untuk melihat versi mana yang dipasang.
Jika Anda perlu memasang, lihat Pasang modul Azure PowerShell.
Jalankan Connect-AzAccount untuk masuk ke Azure.
Skrip sampel
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Create Cosmos Gremlin API account, database, and graph
# with autoscale throughput
# --------------------------------------------------
Function New-RandomString{Param ([Int]$Length = 10) return $(-join ((97..122) + (48..57) | Get-Random -Count $Length | ForEach-Object {[char]$_}))}
# --------------------------------------------------
$uniqueId = New-RandomString -Length 7 # Random alphanumeric string for unique resource names
$apiKind = "Gremlin"
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$locations = @()
$locations += New-AzCosmosDBLocationObject -LocationName "East Us" -FailoverPriority 0 -IsZoneRedundant 0
$locations += New-AzCosmosDBLocationObject -LocationName "West Us" -FailoverPriority 1 -IsZoneRedundant 0
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "cosmos-$uniqueId" # Must be all lower case
$consistencyLevel = "Session"
$databaseName = "myDatabase"
$graphName = "myGraph"
$autoscaleMaxThroughput = 4000 #minimum = 4000
$partitionKeys = @("/myPartitionKey")
# --------------------------------------------------
Write-Host "Creating account $accountName"
$account = New-AzCosmosDBAccount -ResourceGroupName $resourceGroupName `
-LocationObject $locations -Name $accountName -ApiKind $apiKind `
-DefaultConsistencyLevel $consistencyLevel `
-EnableAutomaticFailover:$true
Write-Host "Creating database $databaseName"
$database = New-AzCosmosDBGremlinDatabase -ParentObject $account `
-Name $databaseName
Write-Host "Creating graph $graphName"
$graph = New-AzCosmosDBGremlinGraph -ParentObject $database `
-Name $graphName -AutoscaleMaxThroughput $autoscaleMaxThroughput `
-PartitionKeyKind Hash -PartitionKeyPath $partitionKeys
Membersihkan penyebaran
Setelah sampel skrip dijalankan, perintah berikut dapat digunakan untuk menghapus grup sumber daya dan semua sumber daya yang terkait.
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
Penjelasan skrip
Skrip ini menggunakan perintah berikut. Setiap perintah dalam tabel menautkan ke dokumentasi perintah tertentu.
| Perintah | Catatan |
|---|---|
| Azure Cosmos DB | |
| New-AzCosmosDBAccount | Membuat Akun Cosmos DB. |
| Baru-AzCosmosDBGremlinDatabase | Membuat Gremlin API Database. |
| New-AzCosmosDBGremlinGraph | Membuat Grafik API Gremlin. |
| Grup Sumber Daya Azure | |
| Remove-AzResourceGroup | Menghapus grup sumber daya termasuk semua sumber daya berlapis. |
Langkah berikutnya
Untuk informasi selengkapnya tentang Azure PowerShell, lihat dokumentasi Azure PowerShell.