This Howto Explain how to autoscale EC2 instance in case one instance goes down, the other will be on a point where last AMI is created. This HowTo does not show information about the monitoring alarms but just creating instance. To safe data, you can setup S3 data sync or NFS.
Download and unzip all the APIs from the amazon:
cd /root
apt-get install default-jdk
wget http://ec2-downloads.s3.amazonaws.com/AutoScaling-2011-01-01.zip
wget http://ec2-downloads.s3.amazonaws.com/CloudWatch-2010-08-01.zip
wget http://s3.amazonaws.com/ec2-downloads/ec2-api-tools.zip
unzip AutoScaling-2011-01-01.zip
unzip CloudWatch-2010-08-01.zip
unzip ec2-api-tools.zip
Create a credentials file for authentication with AWS.
vi /root/crefile
export AWSAccessKeyId=xxxxxxxxxxxxxxxxxxxxxx
export AWSSecretKey=xxxxxxxxxxxxxxx+xxxxxxxxxxxxxxxchmod 600 /root/crefile
Export all the PATHS
export AWS_AUTO_SCALING_HOME=/root/autoscale/AutoScaling-1.0.61.1
export JAVA_HOME=/usr/lib/jvm/default-java
export EC2_HOME=/root/autoscale/ec2-api-tools-1.6.4/
export AWS_ELB_HOME=/root/autoscale/ElasticLoadBalancing-1.0.17.0/
export AWS_CREDENTIAL_FILE=/root/crefile
export AWS_CLOUDWATCH_HOME=/root/autoscale/CloudWatch-1.0.13.4/
Get your keypairs to be used for the AutoScale launch config:
cd /root/autoscale/ec2-api-tools-1.6.4/bin
./ec2-describe-keypairs -O YOURACCESSID -W YORSECRETKEY
KEYPAIR my-keypari db:38:dd:94:4b:xx:1a:xx:f0:fc:3f:e7:ee:6c:16:3b:f7:a6:2a:9a
KEYPAIR windows db:38:dd:94:4b:xx:1a:xx:f0:fc:3f:e7:ee:6c:16:3b:f7:a6:2a:9a
KEYPAIR bit db:38:dd:94:4b:xx:1a:xx:f0:fc:3f:e7:ee:6c:16:3b:f7:a6:2a:9a
KEYPAIR Server db:38:dd:94:4b:xx:1a:xx:f0:fc:3f:e7:ee:6c:16:3b:f7:a6:2a:9a
Go to the EC2 APIs and Test if APIs are working fine
./ec2-describe-instances -K /root/key -O YOURACCESSKEY -W YOURSECRETKEY
Setup ELB
elb-create-lb ELBNAME –headers –listener “lb-port=80,instance-port=80,protocol=http” –availability-zones us-east-1a
elb-register-instances-with-lb ELBNAME –headers –instances INSTANCEID
elb-configure-healthcheck ELBNAME –headers –target “HTTP:80/HEALTHCHECK.php” –interval 10 –timeout 3 –unhealthy-threshold 2 –healthy-threshold 2
Setup AUTO SCALING:
./as-create-launch-config CONFIGNAME –image-id AMIID –instance-type INSTANCETYPE –group GROUPNAME
OK-Created launch config./as-create-auto-scaling-group ASGROUPNAME –availability-zones us-east-1a –launch-configuration CONFIGNAME –desired-capacity X –min-size X –max-size X –load-balancers ELBNAME –health-check-type ELB –grace-period 30
OK-Created AutoScalingGroup./as-put-scaling-policy ADDINSTANCEPOLICY –auto-scaling-group ASGROUPNAME –adjustment=X –type ChangeInCapacity
Above Command returns something like this
arn:aws:autoscaling:us-east-1:951138297389:scalingPolicy:a7e33e1f-d43c-422f-80ec-d97e2110cc61:autoScalingGroupName/ASGROUPNAME:policyName/ADDINSTANCEPOLICY
./as-put-scaling-policy TERMINATEINSTANCE –auto-scaling-group ASGROUPNAME –adjustment=-X –type ChangeInCapacityAbove Command returns something like this
arn:aws:autoscaling:us-east-1:951138297389:scalingPolicy:541bb726-be08-4c54-8484-e9bc3156716e:autoScalingGroupName/ASGROUPNAME:policyName/TERMINATEINSTANCE
