使用 Azure 资源管理器模板管理 Azure Cosmos DB Gremlin API 资源

适用于: Gremlin API

在本文中,你将了解如何使用 Azure 资源管理器模板来帮助部署和管理 Azure Cosmos DB 帐户、数据库和图。

本文仅提供 Gremlin API 帐户的示例。若要查找其他 API 类型帐户的示例,请参阅以下文章:将 Azure 资源管理器模板与适用于 CassandraSQLMongoDB的 Azure Cosmos DB API 配合使用。

重要

  • 帐户名称限制为 44 个字符,全部小写。
  • 若要更改吞吐量值,请用更新的 RU/s 重新部署模板。
  • 当你在 Azure Cosmos 帐户中添加或删除位置时,无法同时修改其他属性。 必须单独执行这些操作。

若要创建以下任何 Azure Cosmos DB 资源,请将下列示例模板复制到新的 json 文件中。 在部署具有不同名称和值的同一资源的多个实例时,可以选择创建要使用的参数 json 文件。 可以通过多种方式部署 Azure 资源管理器模板,包括 Azure 门户Azure CLIAzure PowerShellGitHub

预配了自动缩放吞吐量的 Gremlin 的 Azure Cosmos DB 帐户

此模板将为 Gremlin API(具有自动缩放吞吐量的数据库和图)创建一个 Azure Cosmos 帐户。 此模板还支持从 Azure 快速入门模板库进行一键部署。

备注

在我们从 https://raw.githubusercontent.com/ 网站下载特定模板并尝试使用自定义模板进行部署时,有时会遇到特定的问题。

githubusercontent 前缀模板部署问题

我们可以按照以下指导在 Azure 中国世纪互联部署模板:

  1. 复制模板 URI,通过更改前缀、中缀和模板文件名来转换 URI。 例如,源 URI 是 https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.network/vnet-two-subnets/azuredeploy.json

    类别 原始值 转换后的值 操作
    前缀 https://raw.githubusercontent.com https://github.com 更新
    中辍 blob mastermain(Git 存储库的默认分支名称)之前添加
    模板文件名 azuredeploy.json 保留默认值,或替换为新模板文件名。 update

    修改后,转换后的 URI 看起来将类似于 https://github.com/Azure/azure-quickstart-templates/blob/master/quickstarts/microsoft.network/vnet-two-subnets/azuredeploy.json

    请注意,很多模板已移至 https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/{Microsoft_Resource_Provider_Name}/ 之类的路径,你可以遵循相应的路径规定来更新原始 URI。

  2. 复制转换后的 URI,并在 Internet 浏览器中手动下载特定的模板内容。

  3. 在门户的“自定义部署”页中,选择“在编辑器中生成自己的模板”。

  4. 将下载的模板内容复制到“编辑模板”页中,并按照 Azure 中国云的要求更新参数,例如 Azure 中国云环境不支持的终结点、位置、VM 映像、VM 大小、SKU 和资源提供程序的 API 版本。

  5. 选择“保存”以返回“自定义部署”页。

  6. 选择“查看 + 创建”。

部署到 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.539.46024",
      "templateHash": "152416433425177287"
    }
  },
  "parameters": {
    "accountName": {
      "type": "string",
      "defaultValue": "[format('gremlin-{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Cosmos DB account name"
      }
    },
    "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": "Session",
      "allowedValues": [
        "Eventual",
        "ConsistentPrefix",
        "Session",
        "BoundedStaleness",
        "Strong"
      ],
      "metadata": {
        "description": "The default consistency level of the Cosmos DB account."
      }
    },
    "maxStalenessPrefix": {
      "type": "int",
      "defaultValue": 100000,
      "maxValue": 2147483647,
      "minValue": 10,
      "metadata": {
        "description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 1000000. Multi Region: 100000 to 1000000."
      }
    },
    "maxIntervalInSeconds": {
      "type": "int",
      "defaultValue": 300,
      "maxValue": 86400,
      "minValue": 5,
      "metadata": {
        "description": "Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400."
      }
    },
    "automaticFailover": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
        "description": "Enable automatic failover for regions"
      }
    },
    "databaseName": {
      "type": "string",
      "metadata": {
        "description": "The name for the Gremlin database"
      }
    },
    "graphName": {
      "type": "string",
      "metadata": {
        "description": "The name for the Gremlin graph"
      }
    },
    "autoscaleMaxThroughput": {
      "type": "int",
      "defaultValue": 4000,
      "maxValue": 1000000,
      "minValue": 4000,
      "metadata": {
        "description": "Maximum autoscale throughput for the graph"
      }
    }
  },
  "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": "EnableGremlin"
          }
        ],
        "consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]",
        "locations": "[variables('locations')]",
        "databaseAccountOfferType": "Standard",
        "enableAutomaticFailover": "[parameters('automaticFailover')]"
      }
    },
    {
      "type": "Microsoft.DocumentDB/databaseAccounts/gremlinDatabases",
      "apiVersion": "2021-04-15",
      "name": "[format('{0}/{1}', variables('accountName_var'), parameters('databaseName'))]",
      "properties": {
        "resource": {
          "id": "[parameters('databaseName')]"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('accountName_var'))]"
      ]
    },
    {
      "type": "Microsoft.DocumentDb/databaseAccounts/gremlinDatabases/graphs",
      "apiVersion": "2021-04-15",
      "name": "[format('{0}/{1}', format('{0}/{1}', variables('accountName_var'), parameters('databaseName')), parameters('graphName'))]",
      "properties": {
        "resource": {
          "id": "[parameters('graphName')]",
          "indexingPolicy": {
            "indexingMode": "consistent",
            "includedPaths": [
              {
                "path": "/*"
              }
            ],
            "excludedPaths": [
              {
                "path": "/myPathToNotIndex/*"
              }
            ]
          },
          "partitionKey": {
            "paths": [
              "/myPartitionKey"
            ],
            "kind": "Hash"
          }
        },
        "options": {
          "autoscaleSettings": {
            "maxThroughput": "[parameters('autoscaleMaxThroughput')]"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.DocumentDB/databaseAccounts/gremlinDatabases', split(format('{0}/{1}', variables('accountName_var'), parameters('databaseName')), '/')[0], split(format('{0}/{1}', variables('accountName_var'), parameters('databaseName')), '/')[1])]"
      ]
    }
  ]
}

预配了标准吞吐量的 Gremlin 的 Azure Cosmos DB 帐户

此模板将为 Gremlin API(具有标准手动吞吐量的数据库和图)创建一个 Azure Cosmos 帐户。 此模板还支持从 Azure 快速入门模板库进行一键部署。

部署到 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.539.46024",
      "templateHash": "8610816505295226999"
    }
  },
  "parameters": {
    "accountName": {
      "type": "string",
      "defaultValue": "[uniqueString(resourceGroup().id)]",
      "metadata": {
        "description": "Cosmos DB account name"
      }
    },
    "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": "Session",
      "allowedValues": [
        "Eventual",
        "ConsistentPrefix",
        "Session",
        "BoundedStaleness",
        "Strong"
      ],
      "metadata": {
        "description": "The default consistency level of the Cosmos DB account."
      }
    },
    "maxStalenessPrefix": {
      "type": "int",
      "defaultValue": 100000,
      "maxValue": 2147483647,
      "minValue": 10,
      "metadata": {
        "description": "Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 1000000. Multi Region: 100000 to 1000000."
      }
    },
    "maxIntervalInSeconds": {
      "type": "int",
      "defaultValue": 300,
      "maxValue": 86400,
      "minValue": 5,
      "metadata": {
        "description": "Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400."
      }
    },
    "automaticFailover": {
      "type": "bool",
      "defaultValue": true,
      "metadata": {
        "description": "Enable automatic failover for regions"
      }
    },
    "databaseName": {
      "type": "string",
      "defaultValue": "database1",
      "metadata": {
        "description": "The name for the Gremlin database"
      }
    },
    "graphName": {
      "type": "string",
      "defaultValue": "graph1",
      "metadata": {
        "description": "The name for the Gremlin graph"
      }
    },
    "throughput": {
      "type": "int",
      "defaultValue": 400,
      "maxValue": 1000000,
      "minValue": 400,
      "metadata": {
        "description": "Throughput for the Gremlin graph"
      }
    }
  },
  "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": "EnableGremlin"
          }
        ],
        "consistencyPolicy": "[variables('consistencyPolicy')[parameters('defaultConsistencyLevel')]]",
        "locations": "[variables('locations')]",
        "databaseAccountOfferType": "Standard",
        "enableAutomaticFailover": "[parameters('automaticFailover')]"
      }
    },
    {
      "type": "Microsoft.DocumentDB/databaseAccounts/gremlinDatabases",
      "apiVersion": "2021-04-15",
      "name": "[format('{0}/{1}', variables('accountName_var'), parameters('databaseName'))]",
      "properties": {
        "resource": {
          "id": "[parameters('databaseName')]"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('accountName_var'))]"
      ]
    },
    {
      "type": "Microsoft.DocumentDb/databaseAccounts/gremlinDatabases/graphs",
      "apiVersion": "2021-04-15",
      "name": "[format('{0}/{1}', format('{0}/{1}', variables('accountName_var'), parameters('databaseName')), parameters('graphName'))]",
      "properties": {
        "resource": {
          "id": "[parameters('graphName')]",
          "indexingPolicy": {
            "indexingMode": "consistent",
            "includedPaths": [
              {
                "path": "/*"
              }
            ],
            "excludedPaths": [
              {
                "path": "/myPathToNotIndex/*"
              }
            ]
          },
          "partitionKey": {
            "paths": [
              "/myPartitionKey"
            ],
            "kind": "Hash"
          },
          "options": {
            "throughput": "[parameters('throughput')]"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.DocumentDB/databaseAccounts/gremlinDatabases', split(format('{0}/{1}', variables('accountName_var'), parameters('databaseName')), '/')[0], split(format('{0}/{1}', variables('accountName_var'), parameters('databaseName')), '/')[1])]"
      ]
    }
  ]
}

后续步骤

下面是一些其他资源: