Share via


Api létrehozása Cassandra-fiókhoz, kulcstérhez és táblához az Azure CLI használatával automatikus skálázással

A KÖVETKEZŐKRE VONATKOZIK: Cassandra

A cikkben szereplő szkript létrehoz egy Azure Cosmos DB-t az Apache Cassandra-fiókhoz, a kulcstérhez és a táblához automatikus skálázással.

Előfeltételek

  • Ha nem rendelkezik Azure-előfizetéssel, első lépésként hozzon létre egy ingyenes Azure-fiókot.

  • Ehhez a szkripthez az Azure CLI 2.12.1-es vagy újabb verziója szükséges.

    • A szkriptet a Bash-környezetben futtathatja az Azure Cloud Shellben. Amikor megnyílik a Cloud Shell, mindenképpen válassza a Basht a rendszerhéj ablakának bal felső sarkában lévő környezeti mezőben. A Cloud Shell az Azure CLI legújabb verzióját használja.

    • Ha szeretné, telepítheti az Azure CLI-t a szkript helyi futtatásához. Futtassa az az verziót az Azure CLI-verzió megkereséséhez, és ha frissítenie kell, futtassa az az upgrade-t . Jelentkezzen be az Azure-ba az login futtatásával.

Példaszkript

Ez a szkript a következő parancsokat használja:

# Create a Cassandra keyspace and table with autoscale

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="autoscale-casandra-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
keySpace="keyspace1-$randomIdentifier"
table="table1-$randomIdentifier"
maxThroughput=1000 #minimum = 1000

# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag

# Create a Cosmos account for Cassandra API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableCassandra --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False 

# Create a Cassandra Keyspace
echo "Create $keySpace"
az cosmosdb cassandra keyspace create --account-name $account --resource-group $resourceGroup --name $keySpace

# Define the schema for the table
schema=$(cat << EOF 
{
    "columns": [
        {"name": "columna","type": "uuid"},
        {"name": "columnb","type": "int"},
        {"name": "columnc","type": "text"}
    ],
    "partitionKeys": [
        {"name": "columna"}
    ],
    "clusterKeys": [
        { "name": "columnb", "orderBy": "asc" }
    ]
}
EOF
)
# Persist schema to json file
echo "$schema" > "schema-$randomIdentifier.json"

# Create the Cassandra table
echo "Creating $table"
az cosmosdb cassandra table create --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --max-throughput $maxThroughput --schema @schema-$randomIdentifier.json

# Clean up temporary schema file
rm -f "schema-$randomIdentifier.json"

Erőforrások törlése

Ha nincs szüksége a létrehozott erőforrásokra, az az group delete paranccsal törölje az erőforráscsoportot és az összes benne lévő erőforrást, beleértve az Azure Cosmos DB-fiókot és a kulcsteret.

az group delete --name $resourceGroup

Következő lépések

Az Azure Cosmos DB CLI dokumentációja