Compute Engine 与最小安全组合
High Contrast
Dark Mode
Light Mode
Sepia
Forest
2 min read363 words

Compute Engine 与最小安全组合

GCP 上最接近 EC2 组合的,是 Compute Engine + VPC Firewall + Persistent Disk + Service Account。产品名字不同,运维逻辑与 AWS 一致。

GCP 最小组合图

graph LR A[Internet] --> B[VPC Firewall 规则] B --> C[Compute Engine Ubuntu] C --> D[Persistent Disk 数据盘] C --> E[Service Account] E --> F[GCS / Cloud Monitoring 等 GCP 服务]

GCP 与 AWS 对应关系

AWS 服务 GCP 对应 关键差异
EC2 Compute Engine 机器类型命名不同(e2-micro / t3.micro)
Security Group VPC Firewall 规则 GCP 防火墙规则在 VPC 层,通过标签匹配实例
EBS Persistent Disk GCP 支持在线扩容(无需停机)
IAM Role Service Account GCP 以 Service Account 邮件地址为身份标识

用 gcloud CLI 创建基础环境

# 创建一台 Ubuntu 22.04 Compute Engine 实例
gcloud compute instances create myapp-vm \
--zone=asia-east1-b \
--machine-type=e2-micro \
--image-family=ubuntu-2204-lts \
--image-project=ubuntu-os-cloud \
--boot-disk-size=20GB \
--service-account=myapp-sa@my-project.iam.gserviceaccount.com \
--scopes=https://www.googleapis.com/auth/cloud-platform \
--tags=myapp-server
# 创建 VPC 防火墙规则(SSH 限制来源 IP)
gcloud compute firewall-rules create allow-ssh-trusted \
--allow tcp:22 \
--source-ranges=203.0.113.0/32 \
--target-tags=myapp-server \
--description="SSH from trusted IP only"
# 允许 HTTP/HTTPS
gcloud compute firewall-rules create allow-http-https \
--allow tcp:80,tcp:443 \
--source-ranges=0.0.0.0/0 \
--target-tags=myapp-server
# 通过 IAP 无需公网 IP 安全 SSH
gcloud compute ssh myapp-vm --zone=asia-east1-b --tunnel-through-iap

常见误区

本节执行清单

下一节Cloud DNS、Storage、Monitoring 落地——继续补齐周边能力。