区分EBS gp2和gp3卷类型
难度级别: 初级
预计耗时: 15分钟
任务目标: 理解gp2和gp3的核心差异,掌握选型和迁移方法
使用环境: AWS Console / AWS CLI
适用区域: 所有AWS商业区域
- 拥有AWS账号并能访问EC2控制台
- 具备基本的EBS卷概念(如不了解,请先阅读AWS EBS用户指南)
核心差异对比
Section titled “核心差异对比”| 特性 | gp2 | gp3 |
|---|---|---|
| 基准性能 | 3 IOPS/GB(最小100 IOPS) | 3000 IOPS(独立于容量) |
| 最大IOPS | 16000 IOPS | 16000 IOPS |
| 基准吞吐量 | 与IOPS关联 | 125 MB/s(独立于容量) |
| 最大吞吐量 | 250 MB/s | 1000 MB/s |
| 价格(/GB/月) | $0.10 | $0.08 |
| 额外IOPS定价 | 不支持 | $0.005/IOPS/月(超过3000 IOPS) |
| 额外吞吐量定价 | 不支持 | $0.04/MB/s/月(超过125 MB/s) |
最佳实践: 新建卷优先选择gp3,可节省20%成本且性能更灵活。
性能架构对比
Section titled “性能架构对比”graph LR
A[EBS卷容量] --> B{卷类型}
B -->|gp2| C[IOPS = 容量 × 3<br/>最小100, 最大16000]
B -->|gp3| D[基准: 3000 IOPS<br/>可独立调整至16000]
C --> E[吞吐量自动关联]
D --> F[基准: 125 MB/s<br/>可独立调整至1000 MB/s]
gp2适用场景:
- 已有系统且性能满足需求(无需迁移成本)
- 容量大于1000GB且需要高IOPS(此时gp2自动获得3000+ IOPS)
gp3适用场景(推荐):
- 所有新建工作负载
- 小容量但需要高性能(如100GB但需要3000 IOPS)
- 需要独立调整IOPS和吞吐量的场景
步骤1: 验证现有EBS卷类型
Section titled “步骤1: 验证现有EBS卷类型”通过AWS Console:
- 登录AWS Console,进入EC2服务
- 左侧菜单选择”Elastic Block Store” > “Volumes”
- 选择目标卷,查看”Volume type”列
通过AWS CLI:
aws ec2 describe-volumes \ --volume-ids vol-xxxxxxxxx \ --query 'Volumes[0].[VolumeType,Size,Iops,Throughput]' \ --output table步骤2: 创建gp3卷(推荐)
Section titled “步骤2: 创建gp3卷(推荐)”通过AWS Console:
- EC2控制台 > “Volumes” > “Create volume”
- “Volume type”选择”General Purpose SSD (gp3)”
- 设置容量(Size)
- 根据需求调整IOPS(默认3000)和吞吐量(默认125 MB/s)
- 点击”Create volume”
通过AWS CLI:
# 创建基础gp3卷(使用默认性能)aws ec2 create-volume \ --volume-type gp3 \ --size 100 \ --availability-zone us-east-1a
# 创建高性能gp3卷aws ec2 create-volume \ --volume-type gp3 \ --size 100 \ --iops 10000 \ --throughput 500 \ --availability-zone us-east-1a步骤3: 从gp2迁移到gp3
Section titled “步骤3: 从gp2迁移到gp3”迁移特性:
- 在线迁移,无需停机
- 迁移期间可能有性能波动
- 支持随时回滚
通过AWS Console:
- 选择gp2卷 > “Actions” > “Modify volume”
- “Volume type”改为”gp3”
- (可选)调整IOPS和吞吐量
- 点击”Modify”
- 在弹出的确认框中点击”Yes”
通过AWS CLI:
# 基础迁移(保持默认性能)aws ec2 modify-volume \ --volume-id vol-xxxxxxxxx \ --volume-type gp3
# 迁移并提升性能aws ec2 modify-volume \ --volume-id vol-xxxxxxxxx \ --volume-type gp3 \ --iops 5000 \ --throughput 250步骤4: 监控迁移进度
Section titled “步骤4: 监控迁移进度”# 检查修改状态aws ec2 describe-volumes-modifications \ --volume-ids vol-xxxxxxxxx \ --query 'VolumesModifications[0].[ModificationState,Progress]' \ --output table状态说明:
modifying: 迁移中optimizing: 优化中(可正常使用)completed: 完成
stateDiagram-v2
[*] --> modifying: 发起修改
modifying --> optimizing: 类型已变更
optimizing --> completed: 优化完成
completed --> [*]
note right of optimizing: 此阶段卷已可用<br/>性能逐步达到目标
步骤5: 验证迁移结果
Section titled “步骤5: 验证迁移结果”验证卷类型和性能:
aws ec2 describe-volumes \ --volume-ids vol-xxxxxxxxx \ --query 'Volumes[0].[VolumeType,Iops,Throughput]' \ --output table通过CloudWatch监控性能:
- CloudWatch控制台 > “Metrics” > “EBS”
- 选择卷ID
- 查看指标:
VolumeReadOps,VolumeWriteOps,VolumeThroughputPercentage
成本计算示例
Section titled “成本计算示例”场景: 100GB卷,需要5000 IOPS
gp2成本:
- 需要容量: 5000 IOPS ÷ 3 = 1667 GB
- 月成本: 1667 GB × $0.10 = $166.70
gp3成本:
- 容量成本: 100 GB × $0.08 = $8.00
- 额外IOPS成本: (5000 - 3000) × $0.005 = $10.00
- 月成本总计: $18.00
节省: $166.70 - $18.00 = $148.70 (89%节省)
如需回滚到gp2:
aws ec2 modify-volume \ --volume-id vol-xxxxxxxxx \ --volume-type gp2注意: gp2不支持独立设置IOPS,回滚后IOPS将由容量决定。
Q1: 迁移过程中会影响业务吗?
A: 不会停机,但可能有短暂性能波动,建议在业务低峰期执行。
Q2: 多久可以再次修改卷类型?
A: 上次修改完成后需等待6小时才能再次修改。
Q3: gp3的3000 IOPS是否足够?
A: 对于大多数应用场景足够。如需更高性能,建议通过CloudWatch监控实际使用情况后再调整。
Q4: 所有区域都支持gp3吗?
A: 所有AWS商业区域均支持,部分GovCloud区域可能延迟支持,请查看AWS区域表。
Q5: 迁移后如何验证性能是否达标?
A: 使用fio工具进行压测,或通过CloudWatch查看VolumeReadOps和VolumeWriteOps指标。