使用 Azure CLI 创建具有自动缩放功能的 API for Gremlin 帐户、数据库和图形

适用对象: Gremlin

本文中的脚本创建具有自动缩放功能的 Azure Cosmos DB for Gremlin 帐户、数据库和图形。

先决条件

  • 如果没有 Azure 试用版订阅,请在开始前创建一个试用版订阅

  • 此脚本需要使用 Azure CLI 2.30 或更高版本。

  • 如果愿意,可以安装 Azure CLI 以在本地运行脚本。 运行 az version 以查找 Azure CLI 版本,如果需要升级,请运行 az upgrade。 通过运行 az login 登录到 Azure。

    注意

    在可以在由世纪互联运营的 Microsoft Azure 中使用 Azure CLI 之前,请先运行 az cloud set -n AzureChinaCloud 来更改云环境。 若要切换回 Azure 公有云,请再次运行 az cloud set -n AzureCloud

示例脚本

此脚本使用以下命令:

# Create a Gremlin API database and graph with autoscale

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="chinaeast2"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="autoscale-gremlin-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-gremlin-cosmos"
graph="msdocs-graph1-gremlin-cosmos"
partitionKey="/partitionKey"
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 Gremlin API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableGremlin --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False

# Create a Gremlin database
echo "Creating $database with $account"
az cosmosdb gremlin database create --account-name $account --resource-group $resourceGroup --name $database

# Create a Gremlin graph with autoscale
echo "Creating $graph"
az cosmosdb gremlin graph create --account-name $account --resource-group $resourceGroup --database-name $database --name $graph --partition-key-path $partitionKey --max-throughput $maxThroughput

删除资源

如果不需要脚本创建的资源,请使用 az group delete 命令删除资源组及其包含的所有资源,包括 Azure Cosmos DB 帐户和数据库。

az group delete --name $resourceGroup

后续步骤

Azure Cosmos DB CLI 文档