将两个 VPC 网络对等互连
了解如何使用 Google Cloud 控制台将两个虚拟私有云 (VPC) 网络进行对等互连。
请考虑以下情况:组织 organization-a 需要在 project-a 的 network-a 与 project-b 的 network-b 之间建立 VPC 网络对等互连。为了成功建立 VPC 网络对等互连,network-a 和 network-b 的管理员必须分别配置对等互连关联。
通过完成本文档中的步骤,您将创建以下配置:
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Compute Engine API. Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
- 
    
        Make sure that you have the following role or roles on the project: Compute Network Admin or Project Editor Check for the roles- 
              In the Google Cloud console, go to the IAM page. Go to IAM
- Select the project.
- 
              In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator. 
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
 Grant the roles- 
              In the Google Cloud console, go to the IAM page. 前往 IAM
- 选择项目。
- 点击 授予访问权限。
- 
              在新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。 
- 在选择角色列表中,选择一个角色。
- 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
- 点击 Save(保存)。
 
- 
              
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Compute Engine API. Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
- 
    
        Make sure that you have the following role or roles on the project: Compute Network Admin or Project Editor Check for the roles- 
              In the Google Cloud console, go to the IAM page. Go to IAM
- Select the project.
- 
              In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator. 
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
 Grant the roles- 
              In the Google Cloud console, go to the IAM page. 前往 IAM
- 选择项目。
- 点击 授予访问权限。
- 
              在新的主账号字段中,输入您的用户标识符。 这通常是 Google 账号的电子邮件地址。 
- 在选择角色列表中,选择一个角色。
- 如需授予其他角色,请点击 添加其他角色,然后添加其他各个角色。
- 点击 Save(保存)。
 
- 
              
- 对第二个项目重复上述步骤。本快速入门介绍如何将不同项目中的 VPC 网络对等互连。
- 在 Google Cloud 控制台中,前往 VPC 网络页面。 
- 点击创建 VPC 网络。 
- 在名称字段中,输入 - network-a。
- 在新子网部分中,指定以下内容: - 在名称字段中,输入 subnet-a。
- 选择任何区域。
- 在 IPv4 范围字段中,输入 10.0.1.0/24。
- 点击完成。
 
- 在名称字段中,输入 
- 在 IPv4 防火墙规则标签页上包含名为 - NETWORK-allow-custom的预定义入站流量防火墙规则的行的右侧,点击修改。- 取消选择使用子网的 IPv4 范围。
- 在其他 IPv4 范围中,输入 10.0.0.0/20。进入此范围可确保对等互连网络中的资源可以相互通信,让您可以日后添加更多子网,而无需更新防火墙规则。
- 点击确认。
 
- 点击创建。 
- 在 Google Cloud 控制台中,前往 VPC 网络页面。 
- 点击创建 VPC 网络。 
- 在名称字段中,输入 - network-b。
- 在新子网部分中,指定以下内容: - 在名称字段中,输入 subnet-b。
- 选择任何区域。
- 在 IPv4 范围字段中,输入 10.0.8.0/24。
- 点击完成。
 
- 在名称字段中,输入 
- 在 IPv4 防火墙规则标签页上包含名为 - NETWORK-allow-custom的预定义入站流量防火墙规则的行的右侧,点击修改。- 取消选择使用子网的 IPv4 范围。
- 在其他 IPv4 范围中,输入 10.0.0.0/20。进入此范围可确保对等互连网络中的资源可以相互通信,让您可以日后添加更多子网,而无需更新防火墙规则。
- 点击确认。
 
- 点击创建。 
- 在 Google Cloud 控制台中,前往 VPC 网络对等互连页面。 
- 点击创建连接。 
- 点击继续。 
- 输入 - peer-ab作为连接这一端的名称。
- 在您的 VPC 网络下,选择 - network-a。
- 将 Peering VPC network(对等互连 VPC 网络)单选按钮设置为 - In another project。
- 指定另一个项目的项目 ID。 
- 指定另一个网络的 VPC 网络名称,即 - network-b。
- 选择导入自定义路由和导出自定义路由 
- 点击创建。 
- 在 Google Cloud 控制台中,前往 VPC 网络对等互连页面。 
- 选择 - peer-ab。在对等连接详情页面上,状态显示为- Inactive. Waiting for the connection to be created by network-b。
- 在 Google Cloud 控制台中,前往 VPC 网络对等互连页面。 
- 点击创建连接。 
- 点击继续。 
- 输入 - peer-ba作为连接这一端的名称。
- 在您的 VPC 网络下,选择 - network-b。
- 将 Peering VPC network(对等互连 VPC 网络)单选按钮设置为 - In another project。
- 指定另一个项目的项目 ID。 
- 指定另一个网络的 VPC 网络名称,即 - network-b。
- 选择导入自定义路由和导出自定义路由 
- 点击创建。 
- 在 Google Cloud 控制台中,前往 VPC 网络对等互连页面。 
- 在“VPC 网络对等互连”页面上,您创建的连接的状态显示为 - ACTIVE。
- 前往另一个项目中的“VPC 网络对等互连”页面,确定它同样显示为 - ACTIVE。
- 在 Google Cloud 控制台中,转到路由页面。 
- 对于网络和区域,选择 - network-a以及您在其中创建- subnet-a的区域,然后点击查看。
- 在路由列表中,存在 - subnet-b的- Peering subnet路由。
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
- 在 Google Cloud 控制台中,前往 VPC 网络对等互连页面。 
- 选中要移除的对等互连旁边的复选框。 
- 点击删除。 
- 在 Google Cloud 控制台中,前往 VPC 网络页面。 
- 点击某个 VPC 网络的名称以显示其 VPC 网络详情页面。 
- 点击删除 VPC 网络。 
- 在显示的消息中,点击删除进行确认。 
创建两个 VPC 网络
在本部分,您将创建各自位于不同项目中的两个 VPC 网络。
在第一个项目中创建 network-a 和 subnet-a
控制台
在第二个项目中创建 network-b 和 subnet-b
控制台
将 network-a 与 network-b 对等互连
在本部分中,您将配置 network-a 以与 network-b 建立对等互连。
控制台
此时,对等互连状态保持为 INACTIVE,因为 project-b 的 network-b 中缺少匹配的配置。
当对等互连状态变为 ACTIVE 时,VPC 网络对等互连会自动交换子网路由。 Google Cloud 还会通过对等互连连接导入或导出自定义路由(静态路由和动态路由),从而交换这些路由。必须将这两个网络配置为在共享自定义路由之前交换这些路由。如需了解详情,请参阅导入和导出自定义路由。
如需查看当前对等互连状态,请查看对等互连连接:
控制台
将 network-b 与 network-a 对等互连
在本部分中,您将创建从 network-b 到 network-a 的匹配对等互连配置,以使对等互连在两端都变为 ACTIVE。
控制台
VPC 网络对等互连变为 ACTIVE
一旦对等互连变为 ACTIVE 状态,子网路由和自定义路由便会进行交换,从而使流量能够在网络中的资源之间流动。
控制台
到对等互连网络 CIDR 前缀的路由现可在 VPC 网络对等互连之间可见。这些路由是为活跃对等互连连接生成的隐式路由。它们没有对应的路由资源。以下过程显示了 project-a 所有 VPC 网络的路由。
控制台
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
删除项目
如需删除您创建的项目,请执行以下操作:
删除各个资源
如果您不想删除整个项目,请删除 VPC 网络对等互连连接和您创建的 VPC 网络。
在删除网络之前,您必须先删除其 VPC 网络对等互连连接。
删除 VPC 网络对等互连连接
如需删除 VPC 网络对等互连连接,请执行以下操作:
控制台
删除 VPC 网络
如需删除 VPC 网络,请执行以下操作:
控制台
后续步骤
如需详细了解 VPC 网络对等互连,请参阅: