Azure Cosmos DB için otomatik ölçeklendirme ile veritabanı ve grafik oluşturma - Gremlin IÇIN API

ŞUNLAR IÇIN GEÇERLIDIR: Gremlin

Not

Azure ile etkileşime geçmek için Azure Az PowerShell modülünü kullanmanızı öneririz. Başlamak için bkz. Azure PowerShell'i yükleme. Az PowerShell modülüne nasıl geçeceğinizi öğrenmek için bkz. Azure PowerShell’i AzureRM’den Az’ye geçirme.

Bu örnek az 5.4.0 veya sonraki Azure PowerShell gerektirir. Hangi sürümlerin yüklü olduğunu görmek için komutunu çalıştırın Get-Module -ListAvailable Az . Yüklemeniz gerekiyorsa bkz. Azure PowerShell modülünü yükleme.

Azure'da oturum açmak için Connect-AzAccount komutunu çalıştırın.

Örnek betik

# 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

Dağıtımı temizleme

Betik örneği çalıştırıldıktan sonra, kaynak grubunu ve onunla ilişkili tüm kaynakları kaldırmak için aşağıdaki komut kullanılabilir.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Betik açıklaması

Bu betik aşağıdaki komutları kullanır. Tablodaki her komut, komuta özgü belgelere yönlendirir.

Komut Notlar
Azure Cosmos DB
New-AzCosmosDBAccount Azure Cosmos DB Hesabı oluşturur.
New-AzCosmosDBGremlinDatabase Gremlin Veritabanı için bir API oluşturur.
New-AzCosmosDBGremlinGraph Gremlin Graph için bir API oluşturur.
Azure Kaynak Grupları
Remove-AzResourceGroup Bir kaynak grubunu tüm iç içe geçmiş kaynaklar dahil siler.

Sonraki adımlar

Azure PowerShell hakkında daha fazla bilgi için bkz. Azure PowerShell belgeleri.