使用 Azure 资源管理器模板管理 Azure Cosmos DB for Apache Cassandra 资源
适用对象: Cassandra
在本文中,你将了解如何使用 Azure 资源管理器模板来帮助部署和管理 Azure Cosmos DB 帐户、密钥空间和表。
本文仅提供 API for Cassandra 帐户示例,若要查找其他 API 类型帐户的示例,请参阅:将 Azure 资源管理器模板与 Azure Cosmos DB 的 API for NoSQL、Gremlin、MongoDB、Table 配合使用。
重要
- 帐户名称限制为 44 个字符,全部小写。
- 若要更改吞吐量值,请用更新的 RU/s 重新部署模板。
- 当你在 Azure Cosmos DB 帐户中添加或删除位置时,无法同时修改其他属性。 必须单独执行这些操作。
若要创建以下任何 Azure Cosmos DB 资源,请将下列示例模板复制到新的 json 文件中。 在部署具有不同名称和值的同一资源的多个实例时,可以选择创建要使用的参数 json 文件。 可以通过多种方式部署 Azure 资源管理器模板,包括 Azure 门户、Azure CLI、Azure PowerShell 和 GitHub。
预配了自动缩放吞吐量的 Cassandra 的 Azure Cosmos DB 帐户
此模板在两个区域创建一个 Azure Cosmos DB 帐户,其中包含用于一致性和故障转移的选项,以及为自动缩放吞吐量配置的密钥空间和表。 此模板还支持从 Azure 快速入门模板库进行一键部署。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.8.9.13224",
"templateHash": "9558567034094647188"
}
},
"parameters": {
"accountName": {
"type": "string",
"defaultValue": "[format('cassandra-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Cosmos DB account name, max length 44 characters"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the Cosmos DB account."
}
},
"primaryRegion": {
"type": "string",
"metadata": {
"description": "The primary replica region for the Cosmos DB account."
}
},
"secondaryRegion": {
"type": "string",
"metadata": {
"description": "The secondary replica region for the Cosmos DB account."
}
},
"defaultConsistencyLevel": {
"type": "string",
"defaultValue": "Eventual",
"metadata": {
"description": "The default consistency level of the Cosmos DB account."
},
"allowedValues": [
"Eventual",
"ConsistentPrefix",
"Session",
"BoundedStaleness",
"Strong"
]
},
"maxStalenessPrefix": {
"type": "int",
"defaultValue": 100000,
"metadata": {
"description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2,147,483,647. Multi Region: 100,000 to 2,147,483,647."
},
"maxValue": 1000000,
"minValue": 10
},
"maxIntervalInSeconds": {
"type": "int",
"defaultValue": 300,
"metadata": {
"description": "Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84,600. Multi Region: 300 to 86,400."
},
"maxValue": 86400,
"minValue": 5
},
"systemManagedFailover": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Enable system managed failover for regions"
},
"allowedValues": [
true,
false
]
},
"keyspaceName": {
"type": "string",
"metadata": {
"description": "The name for the Cassandra Keyspace"
}
},
"tableName": {
"type": "string",
"metadata": {
"description": "The name for the Cassandra table"
}
},
"autoscaleMaxThroughput": {
"type": "int",
"defaultValue": 1000,
"metadata": {
"description": "Maximum autoscale throughput for the Cassandra table"
},
"maxValue": 1000000,
"minValue": 1000
}
},
"variables": {
"consistencyPolicy": {
"Eventual": {
"defaultConsistencyLevel": "Eventual"
},
"ConsistentPrefix": {
"defaultConsistencyLevel": "ConsistentPrefix"
},
"Session": {
"defaultConsistencyLevel": "Session"
},
"BoundedStaleness": {
"defaultConsistencyLevel": "BoundedStaleness",
"maxStalenessPrefix": "[parameters('maxStalenessPrefix')]",
"maxIntervalInSeconds": "[parameters('maxIntervalInSeconds')]"
},
"Strong": {
"defaultConsistencyLevel": "Strong"
}
},
"locations": [
{
"locationName": "[parameters('primaryRegion')]",
"failoverPriority": 0,
"isZoneRedundant": false
},
{
"locationName": "[parameters('secondaryRegion')]",
"failoverPriority": 1,
"isZoneRedundant": false
}
]
},
"resources": [
{
"type": "Microsoft.DocumentDB/databaseAccounts",
"apiVersion": "2022-05-15",
"name": "[toLower(parameters('accountName'))]",
"location": "[parameters('location')]",
"kind": "GlobalDocumentDB",
"properties": {
"capabilities": [
{
"name": "EnableCassandra"
}
],
"consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]",
"locations": "[variables('locations')]",
"databaseAccountOfferType": "Standard",
"enableAutomaticFailover": "[parameters('systemManagedFailover')]"
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces",
"apiVersion": "2022-05-15",
"name": "[format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName'))]",
"properties": {
"resource": {
"id": "[parameters('keyspaceName')]"
}
},
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts', toLower(parameters('accountName')))]"
]
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces/tables",
"apiVersion": "2022-05-15",
"name": "[format('{0}/{1}', format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName')), parameters('tableName'))]",
"properties": {
"resource": {
"id": "[parameters('tableName')]",
"schema": {
"columns": [
{
"name": "loadid",
"type": "uuid"
},
{
"name": "machine",
"type": "uuid"
},
{
"name": "cpu",
"type": "int"
},
{
"name": "mtime",
"type": "int"
},
{
"name": "load",
"type": "float"
}
],
"partitionKeys": [
{
"name": "machine"
},
{
"name": "cpu"
},
{
"name": "mtime"
}
],
"clusterKeys": [
{
"name": "loadid",
"orderBy": "asc"
}
]
}
},
"options": {
"autoscaleSettings": {
"maxThroughput": "[parameters('autoscaleMaxThroughput')]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces', split(format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName')), '/')[0], split(format('{0}/{1}', toLower(parameters('accountName')), parameters('keyspaceName')), '/')[1])]"
]
}
]
}
预配了标准吞吐量的 Cassandra 的 Azure Cosmos DB 帐户
此模板在两个区域创建一个 Azure Cosmos DB 帐户,其中包含用于一致性和故障转移的选项,以及为标准吞吐量配置的密钥空间和表。 此模板还支持从 Azure 快速入门模板库进行一键部署。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.3.255.40792",
"templateHash": "12484788747974976983"
}
},
"parameters": {
"accountName": {
"type": "string",
"defaultValue": "[format('cassandra-{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Cosmos DB account name, max length 44 characters"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for the Cosmos DB account."
}
},
"primaryRegion": {
"type": "string",
"metadata": {
"description": "The primary region for the Cosmos DB account."
}
},
"secondaryRegion": {
"type": "string",
"metadata": {
"description": "The secondary region for the Cosmos DB account."
}
},
"defaultConsistencyLevel": {
"type": "string",
"defaultValue": "Session",
"metadata": {
"description": "The default consistency level of the Cosmos DB account."
},
"allowedValues": [
"Eventual",
"ConsistentPrefix",
"Session",
"BoundedStaleness",
"Strong"
]
},
"maxStalenessPrefix": {
"type": "int",
"defaultValue": 100000,
"metadata": {
"description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 1000000. Multi Region: 100000 to 1000000."
},
"maxValue": 2147483647,
"minValue": 10
},
"maxIntervalInSeconds": {
"type": "int",
"defaultValue": 300,
"metadata": {
"description": "Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400."
},
"maxValue": 86400,
"minValue": 5
},
"automaticFailover": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Enable automatic failover for regions"
}
},
"keyspaceName": {
"type": "string",
"metadata": {
"description": "The name for the Cassandra Keyspace"
}
},
"tableName": {
"type": "string",
"metadata": {
"description": "The name for the Cassandra table"
}
},
"throughput": {
"type": "int",
"defaultValue": 400,
"metadata": {
"description": "The throughput for Cassandra table"
},
"maxValue": 1000000,
"minValue": 400
}
},
"functions": [],
"variables": {
"accountName_var": "[toLower(parameters('accountName'))]",
"consistencyPolicy": {
"Eventual": {
"defaultConsistencyLevel": "Eventual"
},
"ConsistentPrefix": {
"defaultConsistencyLevel": "ConsistentPrefix"
},
"Session": {
"defaultConsistencyLevel": "Session"
},
"BoundedStaleness": {
"defaultConsistencyLevel": "BoundedStaleness",
"maxStalenessPrefix": "[parameters('maxStalenessPrefix')]",
"maxIntervalInSeconds": "[parameters('maxIntervalInSeconds')]"
},
"Strong": {
"defaultConsistencyLevel": "Strong"
}
},
"locations": [
{
"locationName": "[parameters('primaryRegion')]",
"failoverPriority": 0,
"isZoneRedundant": false
},
{
"locationName": "[parameters('secondaryRegion')]",
"failoverPriority": 1,
"isZoneRedundant": false
}
]
},
"resources": [
{
"type": "Microsoft.DocumentDB/databaseAccounts",
"apiVersion": "2021-04-15",
"name": "[variables('accountName_var')]",
"location": "[parameters('location')]",
"kind": "GlobalDocumentDB",
"properties": {
"capabilities": [
{
"name": "EnableCassandra"
}
],
"consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]",
"locations": "[variables('locations')]",
"databaseAccountOfferType": "Standard",
"enableAutomaticFailover": "[parameters('automaticFailover')]"
}
},
{
"type": "Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces",
"apiVersion": "2021-04-15",
"name": "[format('{0}/{1}', variables('accountName_var'), parameters('keyspaceName'))]",
"properties": {
"resource": {
"id": "[parameters('keyspaceName')]"
}
},
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('accountName_var'))]"
]
},
{
"type": "Microsoft.DocumentDb/databaseAccounts/cassandraKeyspaces/tables",
"apiVersion": "2021-04-15",
"name": "[format('{0}/{1}', format('{0}/{1}', variables('accountName_var'), parameters('keyspaceName')), parameters('tableName'))]",
"properties": {
"resource": {
"id": "[parameters('tableName')]",
"schema": {
"columns": [
{
"name": "loadid",
"type": "uuid"
},
{
"name": "machine",
"type": "uuid"
},
{
"name": "cpu",
"type": "int"
},
{
"name": "mtime",
"type": "int"
},
{
"name": "load",
"type": "float"
}
],
"partitionKeys": [
{
"name": "machine"
},
{
"name": "cpu"
},
{
"name": "mtime"
}
],
"clusterKeys": [
{
"name": "loadid",
"orderBy": "asc"
}
]
},
"options": {
"throughput": "[parameters('throughput')]"
}
}
},
"dependsOn": [
"[resourceId('Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces', split(format('{0}/{1}', variables('accountName_var'), parameters('keyspaceName')), '/')[0], split(format('{0}/{1}', variables('accountName_var'), parameters('keyspaceName')), '/')[1])]"
]
}
]
}
后续步骤
下面是一些其他资源: