1. EC2页面,跳转到volume
选中一个ec2,description---点击root device的信息---点击EBS id的信息,跳转到volume页面
2. 对volume创建一个snapshot
选中volume---action---create snapshot
3. 创建一个EBS volume
根据左侧导航栏,来到snapshot页面,看到步骤2创建的snapshot为completed状态了,就选择actions--create volume,在下一页中,配置改为40G
4. attach EBS到volume
(1)stop EC2
因为要对一个EC2的root volume进行更改,需要把EC2停掉。所以来到EC2页面,停掉这个EC2
(2)detach 之前的volume
等EC2的状态是stopped了,在description选项卡---点击root device中的信息(/dev/xvda)---点击volume的信息
跳转后的页面选择action---detach volume
(3)再来到volume页面,选择步骤3创建的volume,选择action---attach volume
因为步骤3中(2)步骤 root device的路径为/dev/xvda,所以这里也填写为一样的
5. 创建一个自动扩容的配置
(1)根据现有的auto scaling configuration,保存user data代码
来到EC2页面的auto scaling选项--launch configuration,选中其中一个configuration,可以看到页面下方details里的user data,点击view user data可以看到这个configuration的bash script代码。可以拷贝这个bash代码,保存到自己随便建立的文本里,一会用。
#!/bin/bash -xe
yum update -y
yum install -y httpd24 php70 mysql56-server php70-mysqlnd git
cd /var/www/html
git clone https://github.com/linuxacademy/content-aws-soa-c01.git
cd content-aws-soa-c01/wp-site/
mv * /var/www/html
groupadd www
usermod -a -G www cloud_user
chown -R root:www /var/www
chmod -R 2775 /var/www
echo '<?php phpinfo(); ?>' > /var/www/html/phpinfo.php
service httpd start
chkconfig httpd on
service mysqld start
chkconfig mysqld on
(2)新建 自动扩容配置 create new configuration
选择amazon linux机器,不是amazon linux 2;
名字叫为web2;
user data写成步骤(1)中的代码
大小配置为40G;
security group改成existing的webservergroup(允许http 80端口和ssh 22端口);
(3)EC2页面的auto scaling groups选项卡,更改配置
由下图可以看出来,因为terminate了一个ec2,它会给你又启动一个ec2