混合云网络
使用 VPN、Direct Connect 与 ExpressRoute 配置本地与云环境之间安全、高性能的连接。
不适用场景
- 任务与混合云网络无关
- 需要使用本范围之外的其他领域或工具
使用说明
- 明确目标、约束条件与所需输入。
- 应用相关最佳实践并验证结果。
- 提供可执行的步骤与验证方法。
- 如需详细示例,请打开
resources/implementation-playbook.md。
目标定位
在本地数据中心与云服务商(AWS、Azure、GCP)之间建立安全、可靠的网络连接。
适用场景
- 将本地连接到云
- 将数据中心扩展到云
- 实现混合主主(active-active)部署
- 满足合规要求
- 逐步迁移到云
连接选项
AWS 连接
1. 站点到站点 VPN
- 基于互联网的 IPSec VPN
- 每条隧道最高 1.25 Gbps
- 中等带宽下性价比高
- 延迟较高,依赖互联网
resource "aws_vpn_gateway" "main" {
vpc_id = aws_vpc.main.id
tags = {
Name = "main-vpn-gateway"
}
}
resource "aws_customer_gateway" "main" {
bgp_asn = 65000
ip_address = "203.0.113.1"
type = "ipsec.1"
}
resource "aws_vpn_connection" "main" {
vpn_gateway_id = aws_vpn_gateway.main.id
customer_gateway_id = aws_customer_gateway.main.id
type = "ipsec.1"
static_routes_only = false
}
2. AWS Direct Connect
- 专用网络连接
- 1 Gbps 至 100 Gbps
- 延迟更低,带宽稳定
- 更昂贵,需要部署时间
参考: 见 references/direct-connect.md
Azure 连接
1. 站点到站点 VPN
resource "azurerm_virtual_network_gateway" "vpn" {
name = "vpn-gateway"
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
type = "Vpn"
vpn_type = "RouteBased"
sku = "VpnGw1"
ip_configuration {
name = "vnetGatewayConfig"
public_ip_address_id = azurerm_public_ip.vpn.id
private_ip_address_allocation = "Dynamic"
subnet_id = azurerm_subnet.gateway.id
}
}
2. Azure ExpressRoute
- 经由连接服务商的私有连接
- 最高 100 Gbps
- 低延迟、高可靠性
- 全球连接需高级版
GCP 连接
1. Cloud VPN
- IPSec VPN(经典或 HA VPN)
- HA VPN:99.99% SLA
- 每条隧道最高 3 Gbps
2. Cloud Interconnect
- 专用(10 Gbps、100 Gbps)
- 合作伙伴(50 Mbps 至 50 Gbps)
- 延迟低于 VPN
混合网络模式
模式 1:Hub-and-Spoke(中心辐射)
On-Premises Datacenter
↓
VPN/Direct Connect
↓
Transit Gateway (AWS) / vWAN (Azure)
↓
├─ Production VPC/VNet
├─ Staging VPC/VNet
└─ Development VPC/VNet
模式 2:多区域混合
On-Premises
├─ Direct Connect → us-east-1
└─ Direct Connect → us-west-2
↓
Cross-Region Peering
模式 3:多云混合
On-Premises Datacenter
├─ Direct Connect → AWS
├─ ExpressRoute → Azure
└─ Interconnect → GCP
路由配置
BGP 配置
本地路由器:
- AS 号:65000
- 通告:10.0.0.0/8
云路由器:
- AS 号:64512 (AWS)、65515 (Azure)
- 通告:云 VPC/VNet CIDR
路由传播
- 在路由表上启用路由传播
- 使用 BGP 进行动态路由
- 实施路由过滤
- 监控路由通告
安全最佳实践
- 使用私有连接(Direct Connect/ExpressRoute)
- 为 VPN 隧道实施加密
- 使用 VPC 端点避免互联网路由
- 配置网络 ACL与安全组
- 启用 VPC Flow Logs用于监控
- 实施 DDoS 防护
- 使用 PrivateLink/Private Endpoints
- 用 CloudWatch/Monitor 监控连接
- 实施冗余(双隧道)
- 定期进行安全审计
高可用
双 VPN 隧道
resource "aws_vpn_connection" "primary" {
vpn_gateway_id = aws_vpn_gateway.main.id
customer_gateway_id = aws_customer_gateway.primary.id
type = "ipsec.1"
}
resource "aws_vpn_connection" "secondary" {
vpn_gateway_id = aws_vpn_gateway.main.id
customer_gateway_id = aws_customer_gateway.secondary.id
type = "ipsec.1"
}
主主(Active-Active)配置
- 来自不同位置的多个连接
- 使用 BGP 实现自动故障转移
- 等价多路径(ECMP)路由
- 监控所有连接的健康状态
监控与排障
关键指标
- 隧道状态(up/down)
- 入/出字节数
- 丢包率
- 延迟
- BGP 会话状态
排障
# AWS VPN
aws ec2 describe-vpn-connections
aws ec2 get-vpn-connection-telemetry
# Azure VPN
az network vpn-connection show
az network vpn-connection show-device-config-script
成本优化
- 根据流量合理调整连接规模
- 低带宽工作负载使用 VPN
- 通过更少的连接整合流量
- 最小化数据传输成本
- 高带宽使用 Direct Connect
- 实施缓存以减少流量
参考文件
references/vpn-setup.md- VPN 配置指南references/direct-connect.md- Direct Connect 设置
相关技能
multi-cloud-architecture- 用于架构决策terraform-module-library- 用于 IaC 实现




