你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure Cosmos DB for MongoDB vCore 中启用专用访问

适用对象: MongoDB vCore

Azure 专用链接是一项功能强大的服务,允许用户通过指定的专用终结点连接到 Azure Cosmos DB for MongoDB vCore。 此专用终结点包含多个专用 IP 地址,这些地址位于你自己的虚拟网络中的子网中。 通过这些终结点,您能够限制对 Azure Cosmos DB for MongoDB vCore 产品的访问途径,即只能通过专用 IP。 通过将专用链接与严格的 NSG 策略集成,数据泄漏的风险会大大降低。 若要更深入地了解专用终结点,请考虑浏览什么是 Azure 专用链接?

注意

但是,专用链接保护连接,但不会阻止 Azure Cosmos DB 终结点通过公共 DNS 解析。 将在应用程序级别处理对传入请求的筛选,而不是在传输或网络级别处理。

专用链接提供一种灵活性,让用户在访问 Azure Cosmos DB for MongoDB vCore 时,既可以通过你的虚拟网络,也可以通过任何连接的对等虚拟网络。 此外,链接到专用链接的资源可通过 VPN 或 Azure ExpressRoute 通过专用对等访问进行内部部署。

为了建立连接,采用专用链接的 Azure Cosmos DB for MongoDB vCore 支持自动和手动批准方法。 有关详细信息,请参阅 Azure Cosmos DB 中的专用终结点

先决条件

在 Azure 门户中使用专用终结点创建群集

按照以下步骤,在 Azure 门户中使用专用终结点创建新的 Azure Cosmos DB for MongoDB vCore 群集:

  1. 登录到 Azure 门户,然后选择 Azure 门户左上角的“创建资源”。

  2. 在“创建资源”页上选择“数据库”,然后选择“Azure Cosmos DB”。

  3. 在“选择 API 选项”页上,选择“MongoDB”磁贴上的“创建”。

  4. 选择“vCore 群集”资源类型。

  5. 在“Azure Cosmos DB for MongoDB vCore 群集”页上,选择或创建一个资源组,输入群集名称和位置,然后输入管理员密码并进行确认。

  6. 选择下一页:网络

  7. 选择“网络”选项卡,然后选择“专用访问”作为连接方法。

  8. 在“创建专用终结点”屏幕上,输入或选择适当的值:

    设置
    资源组 选择资源组。
    名称 为专用终结点输入任意名称。 如果此名称已被使用,请创建唯一的名称。
    网络接口名称 为网络接口输入任意名称。 如果此名称已被使用,请创建唯一的名称。
    位置 选择要在其中部署专用链接的区域。 在虚拟网络所在的位置创建专用终结点。
    目标子资源 选择之前选定的且你的专用终结点可访问的资源的子资源类型。
    虚拟网络 选择你的虚拟网络。
    子网 选择子网。
    与专用 DNS 区域集成 请选择“是”。 若要以私密方式连接到专用终结点,需有一条 DNS 记录。 建议将专用终结点与专用 DNS 区域集成。 你也可以使用自己的 DNS 服务器,或者使用虚拟机上的主机文件创建 DNS 记录。 为此选项选择“是”时,还将创建一个专用 DNS 区域组。 DNS 区域组是专用 DNS 区域和专用终结点之间的链接。 当专用终结点进行更新时,此链接可帮助你自动更新专用 DNS 区域。 例如,添加或删除区域后,会自动更新专用 DNS 区域。
    配置名称 选择订阅和资源组。 系统会自动确定专用 DNS 区域。 无法使用 Azure 门户更改此区域。
  9. 选择“确定”。

  10. 选择“下一步:标记”>“审阅 + 创建”。 在“查看 + 创建”页上,选择“创建”。

在现有群集上启用专用访问

若要为现有群集中的节点创建专用终结点,请打开该群集的“网络”页。

  1. 选择“添加专用终结点”。

    在“网络”屏幕上选择“添加专用终结点”的屏幕截图。

  2. 在“创建专用终结点”屏幕的“基本信息”选项卡上,确认订阅、资源组和区域。 输入终结点的名称(例如 my-cluster-1),并输入网络接口名(例如 my-cluster-1-nic)。

    注意

    除非你有合理的原因需要选择其他设置,否则我们建议选择与你的群集相匹配的订阅和区域。 表单域的默认值可能不正确。 进行检查,必要时更新。

  3. 在完成时选择“下一步:资源”。 对于“目标子资源”,选择群集的目标节点。 “协调器”通常是所需的节点。

  4. 选择“下一步: 虚拟网络”。 选择所需的“虚拟网络”和“子网” 。 在“专用 IP 配置”下选择“静态分配 IP 地址”,或者保留默认选项(即“动态分配 IP 地址”)。

  5. 选择“下一步: DNS”。

  6. 在“专用 DNS 集成”下,对于“与专用 DNS 区域集成”,保留默认选项“是”或选择“否”。

  7. 选择“下一步: 标记”,并添加任何所需标记。

  8. 选择“查看 + 创建” 。 查看设置,如果对设置感到满意,请选择“创建”。

使用 Azure CLI 创建专用终结点

运行以下 Azure CLI 脚本,为现有 Azure Cosmos DB 帐户创建名为 myPrivateEndpoint 的专用终结点。 请将变量值替换为你的环境的详细信息。

# Resource group where the Azure Cosmos DB account and virtual network resources are located  
ResourceGroupName="myResourceGroup" 

# Name of the existing Azure Cosmos DB account  
MongovCoreClusterName="myMongoCluster" 

# Subscription ID where the Azure Cosmos DB account and virtual network resources are located  
SubscriptionId="<your Azure subscription ID>"  

# API type of your Azure Cosmos DB account: Sql, SqlDedicated, MongoCluster, Cassandra, Gremlin, or Table 
CosmosDbSubResourceType="MongoCluster"  

# Name of the virtual network to create  
VNetName="myVnet"  

# Name of the subnet to create  
SubnetName="mySubnet"  

# Name of the private endpoint to create  
PrivateEndpointName="myPrivateEndpoint"  

# Name of the private endpoint connection to create 
PrivateConnectionName="myConnection" 

az network vnet create \
  --name $VNetName \
  --resource-group $ResourceGroupName \
  --subnet-name $SubnetName 

az network vnet subnet update \
  --name <name> \
  --resource-group $ResourceGroupName \
  --vnet-name $VNetName \
  --disable-private-endpoint-network-policies true 

az network private-endpoint create \
  --name $PrivateEndpointName \
  --resource-group $ResourceGroupName \
  --vnet-name $VNetName \
  --subnet $SubnetName \
  --private-connection-resource-id "/subscriptions/$SubscriptionId/resourceGroups/$ResourceGroupName/providers/Microsoft.DocumentDB/mongoClusters/$MongovCoreClusterName" \
  --group-ids MongoCluster --connection-name $PrivateConnectionName 

将专用终结点与专用 DNS 区域集成

创建专用终结点后,可以使用以下 Azure CLI 脚本将其与专用 DNS 区域集成:

#Zone name differs based on the API type and group ID you are using. 
zoneName="privatelink.mongocluster.cosmos.azure.com" 

az network private-dns zone create \
  --resource-group $ResourceGroupName \
  --name $zoneName 

az network private-dns link vnet create --resource-group $ResourceGroupName \
  --zone-name $zoneName \
  --name <dns-link-name> \
  --virtual-network $VNetName \
  --registration-enabled false 

#Create a DNS zone group
az network private-endpoint dns-zone-group create \
  --resource-group $ResourceGroupName \
  --endpoint-name <pe-name> \
  --name <zone-group-name> \
  --private-dns-zone $zoneName \
  --zone-name mongocluster 
az network private-link-resource list \
  -g <rg-name> \
  -n <resource-name> \
  --type Microsoft.DocumentDB/mongoClusters 

下一步