Átviteli sebesség (RU/s) műveletek az Azure CLI-vel egy adatbázishoz vagy tárolóhoz az Azure Cosmos DB for NoSQL-hez

A KÖVETKEZŐRE VONATKOZIK: NoSQL

A cikkben szereplő szkript létrehoz egy API-t a NoSQL-adatbázishoz megosztott átviteli sebességgel, valamint egy dedikált átviteli sebességgel rendelkező API-t a NoSQL-tárolóhoz, majd frissíti az adatbázis és a tároló átviteli sebességét. A szkript ezután a standardról az automatikus skálázási átviteli sebességre migrál, majd beolvassa az automatikus skálázási átviteli sebesség értékét a migrálás után.

If you don't have an Azure subscription, create an Azure free account before you begin.

Előfeltételek

  • Ez a cikk az Azure CLI 2.12.1-es vagy újabb verzióját igényli. Az Azure Cloud Shell használata esetén a legújabb verzió már telepítve van.

Példaszkript

Az Azure Cloud Shell elindítása

Az Azure Cloud Shell egy olyan ingyenes interaktív kezelőfelület, amelyet a jelen cikkben található lépések futtatására használhat. A fiókjával való használat érdekében a gyakran használt Azure-eszközök már előre telepítve és konfigurálva vannak rajta.

A Cloud Shell megnyitásához válassza a Kipróbálás lehetőséget egy kódblokk jobb felső sarkában. A Cloud Shellt egy külön böngészőlapon is elindíthatja a https://shell.azure.com cím megnyitásával.

Amikor megnyílik a Cloud Shell, ellenőrizze, hogy a Bash ki van-e jelölve a környezetében. A következő munkamenetek az Azure CLI-t használják Bash-környezetben, a Másolás lehetőséget választva másolja ki a kódblokkokat, illessze be a Cloud Shellbe, és nyomja le az Enter billentyűt a futtatáshoz.

Bejelentkezés az Azure-ba

A Cloud Shell automatikusan hitelesítve lesz a kezdeti fiókkal, amellyel bejelentkezett. A következő szkripttel egy másik előfizetéssel jelentkezhet be, lecserélve <Subscription ID> az Azure-előfizetés azonosítóját. If you don't have an Azure subscription, create an Azure free account before you begin.

subscription="<subscriptionId>" # add subscription here

az account set -s $subscription # ...or use 'az login'

További információ: Aktív előfizetés beállítása vagy interaktív bejelentkezés

A szkript futtatása

# Throughput operations for a SQL API database and container

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="throughput-sql-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-sql-cosmos"
container="container1"
partitionKey="/partitionKey"
originalThroughput=400
updateThroughput=500

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

# Create a Cosmos account for SQL API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup

# Create a SQL API database
echo "Creating $database with $originalThroughput"
az cosmosdb sql database create --account-name $account --resource-group $resourceGroup --name $database --throughput $originalThroughput

# Create a SQL API container
echo "Creating $container with $maxThroughput"
az cosmosdb sql container create --account-name $account --resource-group $resourceGroup --database-name $database --name $container --partition-key-path $partitionKey --throughput $originalThroughput

# Throughput operations for SQL API database
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned database throughput
az cosmosdb sql database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.throughput -o tsv

# Retrieve the minimum allowable database throughput
minimumThroughput=$(az cosmosdb sql database throughput show --resource-group $resourceGroup --account-name $account --name $database --query resource.minimumThroughput -o tsv)

echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update database throughput
echo "Updating $database throughput to $updateThroughput"
az cosmosdb sql database throughput update --account-name $account --resource-group $resourceGroup --name $database --throughput $updateThroughput

# Migrate the database from standard (manual) throughput to autoscale throughput
az cosmosdb sql database throughput migrate --account-name $account --resource-group $resourceGroup --name $database --throughput-type "autoscale"

# Retrieve current autoscale provisioned max database throughput
az cosmosdb sql database throughput show --account-name $account --resource-group $resourceGroup --name $database --query resource.autoscaleSettings.maxThroughput -o tsv

# Throughput operations for SQL API container
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned container throughput
az cosmosdb sql container throughput show --account-name $account --resource-group $resourceGroup --database-name $database --name $container --query resource.throughput -o tsv

# Retrieve the minimum allowable container throughput
minimumThroughput=$(az cosmosdb sql container throughput show --account-name $account --resource-group $resourceGroup --database-name $database --name $container --query resource.minimumThroughput -o tsv)
echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update container throughput
echo "Updating $container throughput to $updateThroughput"
az cosmosdb sql container throughput update --account-name $account --resource-group $resourceGroup --database-name $database --name $container --throughput $updateThroughput

# Migrate the container from standard (manual) throughput to autoscale throughput
az cosmosdb sql container throughput migrate --account-name $account --resource-group $resourceGroup --database-name $database --name $container --throughput "autoscale"

# Retrieve the current autoscale provisioned max container throughput
az cosmosdb sql container throughput show --account-name $account --resource-group $resourceGroup --database-name $database --name $container --query resource.autoscaleSettings.maxThroughput -o tsv

Clean up resources

Az alábbi paranccsal eltávolíthatja az erőforráscsoportot és a hozzá társított összes erőforrást az az csoporttörlés paranccsal – kivéve, ha folyamatosan szüksége van ezekre az erőforrásokra. Ezen erőforrások némelyikének létrehozása és törlése eltarthat egy ideig.

az group delete --name $resourceGroup

Mintahivatkozás

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
az group create Létrehoz egy erőforráscsoportot, amely az összes erőforrást tárolja.
az cosmosdb create Létrehoz egy Azure Cosmos DB-fiókot.
az cosmosdb sql database create Létrehoz egy Azure Cosmos DB for NoSQL-adatbázist.
az cosmosdb sql container create Létrehoz egy Azure Cosmos DB for NoSQL-tárolót.
az cosmosdb sql database átviteli sebességének frissítése Az Azure Cosmos DB for NoSQL-adatbázisok átviteli sebességének frissítése.
az cosmosdb sql container throughput update Az Azure Cosmos DB for NoSQL-tároló átviteli sebességének frissítése.
az cosmosdb sql database átviteli sebesség migrálása Egy Azure Cosmos DB for NoSQL-adatbázis átviteli sebességének migrálása.
az cosmosdb sql container throughput migrate Az Azure Cosmos DB for NoSQL-tároló átviteli sebességének migrálása.
az group delete Töröl egy erőforráscsoportot az összes beágyazott erőforrással együtt.

Következő lépések

Az Azure Cosmos DB CLI-vel kapcsolatos további információkért tekintse meg az Azure Cosmos DB CLI dokumentációját.