Azure Cosmos DB for MongoDB vCore 提供无缝可伸缩性和区域内高可用性(HA)。 本文档为想要了解如何缩放和配置群集的开发人员提供了快速指南。
先决条件
- 现有的 Azure Cosmos DB for MongoDB (vCore) 群集。
扩展集群计算
              群集层 允许在群集 的物理分片上配置 vCore 数和 RAM 量。 可以随时更改群集层以满足需求,而不会中断。 例如,可以将 M50 增加到 M60 或将 M50 减少到 M40。
- 在群集边栏的 “设置”下,选择“ 缩放”。 
- 若要更改群集层,请从下拉菜单中选择新层。 - 
              
              
                
 
- 选择“保存”以保存更改。 
- 若要纵向扩展或缩减群集计算层,请通过更改- update属性中的- MXXX值来更新现有群集- compute.tier。
 - az resource update \
  --resource-type "Microsoft.DocumentDB/mongoClusters" \
  --name "<cluster-name>" \
  --resource-group "<resource-group>" \
  --set properties.compute.tier="<compute-tier>"
 
可以直接使用 Azure REST API,或者在 Azure CLI 环境中结合 az rest 一起使用。
- 使用此命令更改群集计算层: - az rest \
   --method "PATCH" \
   --url "https://management.chinacloudapi.cn/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/mongoClusters/<cluster-name>?api-version=2025-07-01-preview" \
   --body "{\"location\":\"<cluster-region>\",\"properties\":{\"compute\":{\"tier\":\"<compute-tier>\"}}}"
 
 
增加存储大小
可以增加 存储大小 ,以增加数据库增长空间。 例如,可以将存储从 128 GiB 增加到 256 GiB。
- 若要增加存储大小,请从下拉菜单中选择新大小。 - 
              
              
                
 
- 选择“保存”以保存更改。 
- 若要增加群集存储大小,请使用作更新现有群集 - update,方法是增加属性中的- storage.sizeGb值。 支持的存储大小在 支持的存储页上列出。
 - az resource update \
  --resource-type "Microsoft.DocumentDB/mongoClusters" \
  --name "<cluster-name>" \
  --resource-group "<resource-group>" \
  --set properties.storage.sizeGb="<new-size-in-GiB>"
 
可以直接使用 Azure REST API,或者在 Azure CLI 环境中结合 az rest 一起使用。
- 使用此命令更改群集计算层: - az rest \
   --method "PATCH" \
   --url "https://management.chinacloudapi.cn/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/mongoClusters/<cluster-name>?api-version=2025-07-01-preview" \
   --body "{\"location\":\"<cluster-region>\",\"properties\":{\"storage\":{\"sizeGb\":\"<new-size-in-GiB>\"}}}"
 
 
启用或禁用高可用性
可以根据需要启用或禁用 区域内高可用性(HA )。 区域内 HA 通过维护群集中每个主分片的副本分片来避免数据库停机。 如果主分片出现故障,则传入连接会自动重定向到其副本分片,以确保故障时间最短。
- 若要启用或禁用区域内 HA,请切换复选框选项。 - 
              
              
                
 
- 选择“保存”以保存更改。 
- 若要在群集上启用区域内高可用性,请将属性中的值设置为 />,使用作更新现有群集。 - az resource update \
  --resource-type "Microsoft.DocumentDB/mongoClusters" \
  --name "<cluster-name>" \
  --resource-group "<resource-group>" \
  --set properties.highAvailability.targetMode="ZoneRedundantPreferred"
 
- 若要在群集上禁用区域内高可用性,请将属性中的值设置为 />,使用作更新现有群集。 - az resource update \
  --resource-type "Microsoft.DocumentDB/mongoClusters" \
  --name "<cluster-name>" \
  --resource-group "<resource-group>" \
  --set properties.highAvailability.targetMode="Disabled"
 
可以直接使用 Azure REST API,或者在 Azure CLI 环境中结合 az rest 一起使用。
- 使用此命令在群集上 启用 区域内高可用性: - az rest \
   --method "PATCH" \
   --url "https://management.chinacloudapi.cn/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/mongoClusters/<cluster-name>?api-version=2025-07-01-preview" \
   --body "{\"location\":\"<cluster-region>\",\"properties\":{\"highAvailability\":{\"targetMode\":\"ZoneRedundantPreferred\"}}}"
 
- 使用此命令在群集上 禁用 区域内高可用性: - az rest \
   --method "PATCH" \
   --url "https://management.chinacloudapi.cn/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/mongoClusters/<cluster-name>?api-version=2025-07-01-preview" \
   --body "{\"location\":\"<cluster-region>\",\"properties\":{\"highAvailability\":{\"targetMode\":\"Disabled\"}}}"
 
 
增加物理分片数
重要
Azure Cosmos DB for MongoDB vCore 中的物理分片和数据重新均衡目前为预览版。 此预览版在没有服务级别协议的情况下提供,不建议用于生产工作负荷。 某些功能不受支持或功能有限。
 
当数据库超出单个物理分片群集的容量时,可以增加 存储大小 或添加更多 物理分片。 将新的物理分片添加到群集后,必须执行群集重新均衡作,以便跨分片重新分发数据。 群集中的每个物理分片始终具有相同的 计算 和 存储 配置。
- 若要添加物理分片,请从列表中选择新的分片数量。 - 
              
              
                
 
- 选择“保存”以保存更改。 
- 在弹出窗口中选择 “继续 ”以保留更改。 
- 若要向群集添加物理分片,请使用作更新现有群集 - update,方法是将属性的值- sharding.shardCount增加一个。
 - az resource update \
  --resource-type "Microsoft.DocumentDB/mongoClusters" \
  --name "<cluster-name>" \
  --resource-group "<resource-group>" \
  --set properties.sharding.shardCount="<current-shard-count-plus-one>"
 - 
- 注意 - 一次只能添加一个物理分片。 如果需要将多个物理分片添加到群集,则需要按顺序执行此作。 
 
可以直接使用 Azure REST API,或者在 Azure CLI 环境中结合 az rest 一起使用。
- 使用此命令将物理分片添加到群集: - az rest \
   --method "PATCH" \
   --url "https://management.chinacloudapi.cn/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.DocumentDB/mongoClusters/<cluster-name>?api-version=2025-07-01-preview" \
   --body "{\"location\":\"<cluster-region>\",\"properties\":{\"sharding\":{\"shardCount\":\"<current-shard-count-plus-one>\"}}}"
 - 
- 注意 - 一次只能添加一个物理分片。 如果需要将多个物理分片添加到群集,则需要按顺序执行此作。 
 
 
如果在集群上需要超过 10 个物理分片,请联系我们的团队 寻求帮助。
重新平衡数据
              将物理分片添加到群集后,或者如果多分片群集在其物理分片中存储使用率不均衡,数据重新均衡会重新分发分片之间的数据,而不会造成任何停机。
在预览版中,需要在群集上启用数据重新均衡:
- 在 Azure 门户中,打开群集属性。
- 在“功能”页上的“设置”下,为多分片群集选择“重新平衡器”。
- 在 多分片群集面板的“重新平衡器 ”中,选择“ 启用”。
若要启动数据重新均衡,请使用管理工具(如 Mongo shell)连接到群集。
- 使用 - sh.startBalancer()命令启动重新平衡器。
 
- 使用 - sh.isBalancerRunning()检查重新平衡器状态。
 
- 使用 - sh.stopBalancer()命令停止重新平衡器。
 
注意
重新均衡过程的持续时间取决于在物理分片之间移动的数据量。 该作联机执行,不会影响群集可用性或功能。
 
后续步骤
本指南介绍了在 Azure 门户中缩放和配置 Cosmos DB for MongoDB vCore 群集的过程非常简单。 Azure 门户提供了调整群集层级、扩展存储空间、启用或禁用高可用性,以及在无需停机的情况下添加物理分片的功能。