NoSQL için Azure Cosmos DB için veritabanı veya kapsayıcı için Azure CLI ile aktarım hızı (RU/sn) işlemleri

UYGULANANLAR: NoSQL

Bu makaledeki betik, paylaşılan aktarım hızına sahip NoSQL veritabanı için bir API ve ayrılmış aktarım hızına sahip bir NoSQL kapsayıcısı API'si oluşturur, ardından hem veritabanı hem de kapsayıcı için aktarım hızını güncelleştirir. Betik daha sonra standarttan otomatik ölçeklendirme aktarım hızına geçirildikten sonra otomatik ölçeklendirme aktarım hızının değerini okur.

Azure aboneliğiniz yoksa başlamadan önce birücretsiz Azure hesabı oluşturun.

Ön koşullar

  • Azure Cloud Shell'de Bash ortamını kullanın. Daha fazla bilgi için bkz . Azure Cloud Shell'de Bash için hızlı başlangıç.

  • CLI başvuru komutlarını yerel olarak çalıştırmayı tercih ediyorsanız Azure CLI'yı yükleyin . Windows veya macOS üzerinde çalışıyorsanız Azure CLI’yi bir Docker kapsayıcısında çalıştırmayı değerlendirin. Daha fazla bilgi için bkz . Docker kapsayıcısında Azure CLI'yi çalıştırma.

    • Yerel yükleme kullanıyorsanız az login komutunu kullanarak Azure CLI ile oturum açın. Kimlik doğrulama işlemini tamamlamak için terminalinizde görüntülenen adımları izleyin. Diğer oturum açma seçenekleri için bkz . Azure CLI ile oturum açma.

    • İstendiğinde, ilk kullanımda Azure CLI uzantısını yükleyin. Uzantılar hakkında daha fazla bilgi için bkz. Azure CLI ile uzantıları kullanma.

    • Yüklü sürümü ve bağımlı kitaplıkları bulmak için az version komutunu çalıştırın. En son sürüme yükseltmek için az upgrade komutunu çalıştırın.

  • Bu makale, Azure CLI'nın 2.12.1 veya sonraki bir sürümünü gerektirir. Azure Cloud Shell kullanılıyorsa en son sürüm zaten yüklüdür.

Örnek betik

Azure Cloud Shell'i başlatma

Azure Cloud Shell, bu makaledeki adımları çalıştırmak için kullanabileceğiniz ücretsiz bir etkileşimli kabuktur. Yaygın Azure araçları, kabuğa önceden yüklenmiştir ve kabuk, hesabınızla birlikte kullanılacak şekilde yapılandırılmıştır.

Cloud Shell'i açmak için kod bloğunun sağ üst köşesinden Deneyin'i seçmeniz yeterlidir. İsterseniz https://shell.azure.com adresine giderek Cloud Shell'i ayrı bir tarayıcı sekmesinde de başlatabilirsiniz.

Cloud Shell açıldığında ortamınız için Bash'in seçili olduğunu doğrulayın. Sonraki oturumlarda Bash ortamında Azure CLI kullanılır, kod bloklarını kopyalamak için Kopyala'yı seçin, Cloud Shell'e yapıştırın ve çalıştırmak için Enter tuşuna basın.

Azure'da oturum açma

Cloud Shell'de oturum açılan ilk hesapta otomatik olarak kimlik doğrulaması yapılır. Farklı bir abonelik kullanarak oturum açmak için aşağıdaki betiği kullanın ve yerine <Subscription ID> Azure Abonelik Kimliğiniz yazın. Azure aboneliğiniz yoksa başlamadan önce birücretsiz Azure hesabı oluşturun.

subscription="<subscriptionId>" # add subscription here

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

Daha fazla bilgi için bkz . Etkin aboneliği ayarlama veya etkileşimli olarak oturum açma

Betiği çalıştırın

# 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

Kaynakları temizleme

Bu kaynaklara sürekli ihtiyaç duymadığınız sürece az group delete komutunu kullanarak kaynak grubunu ve onunla ilişkili tüm kaynakları kaldırmak için aşağıdaki komutu kullanın. Bu kaynaklardan bazılarının oluşturulması ve silinmesi biraz zaman alabilir.

az group delete --name $resourceGroup

Örnek başvuru

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

Command Notlar
az group create Tüm kaynakların depolandığı bir kaynak grubu oluşturur.
az cosmosdb create Azure Cosmos DB hesabı oluşturur.
az cosmosdb sql database create NoSQL için Azure Cosmos DB veritabanı oluşturur.
az cosmosdb sql container create NoSQL için Azure Cosmos DB kapsayıcısı oluşturur.
az cosmosdb sql database aktarım hızı güncelleştirmesi NoSQL için Azure Cosmos DB veritabanı için aktarım hızını güncelleştirin.
az cosmosdb sql container throughput update NoSQL için Azure Cosmos DB kapsayıcısı için aktarım hızını güncelleştirme.
az cosmosdb sql veritabanı aktarım hızı geçişi NoSQL için Azure Cosmos DB veritabanı için aktarım hızını geçirme.
az cosmosdb sql container throughput migrate NoSQL için Azure Cosmos DB kapsayıcısı için aktarım hızını geçirme.
az group delete Bir kaynak grubunu tüm iç içe geçmiş kaynaklar dahil siler.

Sonraki adımlar

Azure Cosmos DB CLI hakkında daha fazla bilgi için bkz . Azure Cosmos DB CLI belgeleri.