Megosztás a következőn keresztül:


Kulcstér és tábla létrehozása automatikus skálázással az Azure Cosmos DB-hez – API a Cassandra-hoz

A KÖVETKEZŐKRE VONATKOZIK: Cassandra

Feljegyzés

Javasoljuk, hogy az Azure Az PowerShell modult használja az Azure-ral való interakcióhoz. Első lépésként tekintse meg az Azure PowerShell telepítését ismertető témakört. Az Az PowerShell-modulra történő migrálás részleteiről lásd: Az Azure PowerShell migrálása az AzureRM modulból az Az modulba.

Ehhez a mintához az Azure PowerShell Az 5.4.0-s vagy újabb verziója szükséges. Futtassa Get-Module -ListAvailable Az a telepített verziókat. Ha telepítenie kell, tekintse meg az Azure PowerShell-modul telepítését ismertető témakört.

A Connect-AzAccount futtatásával jelentkezzen be az Azure-ba.

Példaszkript

# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Create Cosmos Cassandra API account with automatic failover,
# a keyspace, and a table with defined schema 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 = "Cassandra"
# --------------------------------------------------
# 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 = "mjbArmTest"#"myResourceGroup" # Resource Group must already exist
$accountName = "cosmos-$uniqueId" # Must be all lower case
$consistencyLevel = "Session"
$keyspaceName = "mykeyspace"
$tableName = "mytable"
$autoscaleMaxThroughput = 4000 #minimum = 4000
$partitionKeys = @("machine", "cpu", "mtime")
$clusterKeys = @( 
    @{ name = "loadid"; orderBy = "Asc" };
    @{ name = "duration"; orderBy = "Desc" }
)
$columns = @(
    @{ name = "loadid"; type = "uuid" };
    @{ name = "machine"; type = "uuid" };
    @{ name = "cpu"; type = "int" };
    @{ name = "mtime"; type = "int" };
    @{ name = "load"; type = "float" };
    @{ name = "duration"; type = "float" }
)
# --------------------------------------------------
Write-Host "Creating account $accountName"
$account = New-AzCosmosDBAccount -ResourceGroupName $resourceGroupName `
    -LocationObject $locations -Name $accountName -ApiKind $apiKind `
    -DefaultConsistencyLevel $consistencyLevel `
    -EnableAutomaticFailover:$true

Write-Host "Creating keyspace $keyspaceName"
$keyspace = New-AzCosmosDBCassandraKeyspace -ParentObject $account `
    -Name $keyspaceName

# Table Schema
$psClusterKeys = @()
ForEach ($clusterKey in $clusterKeys) {
    $psClusterKeys += New-AzCosmosDBCassandraClusterKey -Name $clusterKey.name -OrderBy $clusterKey.orderBy
}

$psColumns = @()
ForEach ($column in $columns) {
    $psColumns += New-AzCosmosDBCassandraColumn -Name $column.name -Type $column.type
}

$schema = New-AzCosmosDBCassandraSchema `
    -PartitionKey $partitionKeys `
    -ClusterKey $psClusterKeys `
    -Column $psColumns

Write-Host "Creating table $tableName"
$table = New-AzCosmosDBCassandraTable -ParentObject $keyspace `
    -Name $tableName -Schema $schema -AutoscaleMaxThroughput  $autoscaleMaxThroughput 

Az üzemelő példány eltávolítása

A példaszkript futtatása után a következő paranccsal távolítható el az erőforráscsoport és az összes ahhoz kapcsolódó erőforrás.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Szkript ismertetése

A szkript a következő parancsokat használja. A táblázatban lévő összes parancs a hozzá tartozó dokumentációra hivatkozik.

Parancs Jegyzetek
Azure Cosmos DB
New-AzCosmosDBAccount Létrehoz egy Azure Cosmos DB-fiókot.
New-AzCosmosDBCassandraKeyspace Létrehoz egy Azure Cosmos DB-t az Apache Cassandra Keyspace-hez.
New-AzCosmosDBCassandraClusterKey Létrehoz egy Azure Cosmos DB-t az Apache Cassandra fürtkulcsához.
New-AzCosmosDBCassandraColumn Létrehoz egy Azure Cosmos DB-t az Apache Cassandra-oszlophoz.
New-AzCosmosDBCassandraSchema Létrehoz egy Azure Cosmos DB-t az Apache Cassandra-sémához.
New-AzCosmosDBCassandraTable Létrehoz egy Azure Cosmos DB-t az Apache Cassandra-táblához.
Azure-erőforráscsoportok
Remove-AzResourceGroup Töröl egy erőforráscsoportot az összes beágyazott erőforrással együtt.

Következő lépések

Az Azure PowerShellről további információt az Azure PowerShell dokumentációjában talál .