多数用户上云是按惯例给EC2配较大磁盘,实际使用率较低。考虑到EBS价格不低、又没有包年优惠,造成的浪费有时比虚机成本还高。AWS支持EBS盘动态扩容,但不支持缩容;上线后的系统重装迁移代价太高。下面给出EBS盘缩容和自动扩容的原理和步骤供您参考。如需进一步协助或服务,请留言,泰岳云业务会提供自动化工具及专业服务。
一、数据盘缩容:
难度系数***
风险等级*
RTO<1分钟
1、检查数据源盘使用率和分区和文件系统情况
2、新建合适大小EBS盘挂上虚机
3、新盘分区、创建并mount文件系统
4、源盘rsync步到新盘
5、停应用
6、增量同步
7、umont源盘和新盘
8、源盘分区label和UUID克隆到新盘
9、源盘从虚机拆离
10、新盘mount到源盘的挂载点
11、起应用
12、确认应用正常,删除源EBS盘
二、系统盘缩容
难度系数*****
风险等级**
RTO<3分钟
1、检查系统源盘使用率、分区和文件系统情况
1-1、检查系统盘bootloader版本、/etc/fstab配置
2、新建合适大小EBS盘挂上虚机
3、新盘分区、创建并mount文件系统
4、源盘rsync步到新盘
4-1、新盘grub-install做成启动盘
5、停应用
6、源盘增量同步到新盘
7、umont新盘
8、源盘分区label和UUID克隆到新盘
9、ec2停机
10、从ec2拆离源盘,挂载新盘为/dev/xvda
11、ec2开机
12、确认应用正常,删除源EBS盘
三、EBS自动扩容
磁盘缩容后,用户很容易担心万一磁盘满了、出事故咋办?这里提供自动扩容实现步骤:
难度系数***
风险等级*
RTO 0分钟(不停机)
1、ec2安装cloudwatch agent监控磁盘利用率
2、cloudwatch设置门限告警触发lambda函数
3、lambda调用api,为ec2磁盘扩容
Most users configure EC2 with larger disks by convention when moving to the cloud, but actual utilization is often low. Considering that EBS prices are not cheap and there are no annual package discounts, the waste can sometimes be higher than the virtual machine cost. AWS supports dynamic EBS volume expansion, but not reduction; reinstalling and migrating production systems is too costly. Below are the principles and steps for EBS volume reduction and automatic expansion for your reference. If you need further assistance or services, please leave a message, and Ultrapower Cloud Business will provide automation tools and professional services.
1. Data Volume Reduction:
Difficulty Level: ***
Risk Level: *
RTO < 1 minute
1. Check data source volume usage, partitions, and file system status
2. Create a new EBS volume of appropriate size and attach to the instance
3. Partition the new volume, create and mount the file system
4. Rsync data from source volume to new volume
5. Stop the application
6. Incremental sync
7. Unmount source volume and new volume
8. Clone source volume partition label and UUID to new volume
9. Detach source volume from the instance
10. Mount new volume to the source volume's mount point
11. Start the application
12. Confirm application is working properly, delete source EBS volume
2. System Volume Reduction
Difficulty Level: *****
Risk Level: **
RTO < 3 minutes
1. Check system source volume usage, partitions, and file system status
1-1. Check system volume bootloader version and /etc/fstab configuration
2. Create a new EBS volume of appropriate size and attach to the instance
3. Partition the new volume, create and mount the file system
4. Rsync data from source volume to new volume
4-1. Run grub-install on the new volume to make it bootable
5. Stop the application
6. Incremental sync from source volume to new volume
7. Unmount the new volume
8. Clone source volume partition label and UUID to new volume
9. Stop the EC2 instance
10. Detach source volume from EC2, mount new volume as /dev/xvda
11. Start the EC2 instance
12. Confirm application is working properly, delete source EBS volume
3. EBS Automatic Expansion
After reducing disk size, users often worry about what happens if the disk becomes full and causes an accident. Here are the steps for implementing automatic expansion:
Difficulty Level: ***
Risk Level: *
RTO: 0 minutes (no downtime)
1. Install CloudWatch agent on EC2 to monitor disk utilization
2. Set up CloudWatch threshold alarm to trigger Lambda function
3. Lambda calls API to expand EC2 disk