Amazon AutoScalling ubuntu


A. Setup Auto Scaling command line:
Download the tool from http://aws.amazon.com/developertools/2535
Unzip it and follow the process below
Set the following environment variables:
1. Open “/etc/bash.bashrc” file to set environment variables

$ sudo nano /etc/bash.bashrc

2. Add this line to “/etc/bash.bashrc”:

export AWS_AUTO_SCALING_HOME="AutoScaling directory path here"

3. Set $PATH of AWS_AUTO_SCALING_HOME directory by adding line in “/etc/bash.bashrc”:

export PATH="$PATH:$AWS_AUTO_SCALING_HOME/bin"

4. set JAVA_HOME variable by adding line in “/etc/bash.bashrc”:

export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")

5. This command also provide java path

$ sudo update-alternatives --config java

6. There is file “credential-file-path.template” at root of AWS_AUTO_SCALING_HOME directory copy file and change name to “credentials-yourname.template” provide credentials, which are required in that file. Now run chmod 600 credentials-yourname.template.

Now add this line in “/etc/bash.bashrc”

export AWS_CREDENTIAL_FILE="$AWS_AUTO_SCALING_HOME/credentials-yourname.template"

B. Setup Cloudwatch command line:
set these variables in “/etc/bash.bashrc”:


export AWS_CLOUDWATCH_HOME="Cloudwatch directory path here"
export PATH="$PATH:$AWS_CLOUDWATCH_HOME/bin"

Download the tool from http://aws.amazon.com/developertools/2534
Note:

Run these two command to get environment variable values in terminal:

source /etc/bash.bashrc 
ldconfig

To test whether environment variable is set:

echo $Variable_Name

C. Setup Autoscalling and Cloudwatch for Amazon:
1. Follow this link https://www.ezautoscaling.com/AutoScalingGuide.aspx
2. Don’t forget to add this “–region region_name” at the end of every command in every command in step 1.

Summary: (from reference link#1)

Let’s quickly summarize the steps and commands needed to auto scale:
Make sure you have pre-requisites ready
Install and setup Auto Scaling Command Line Tools (A step above)
Install and setup CloudWatch Command Line Tools (B step above)
All things below: (C step above)
Create new launch configuration:
as-create-launch-config Launch Config Name –image-id AMI ID –instance-type Instance Size –key Security Key
Create new auto scaling group:
as-create-auto-scaling-group Auto Scaling Group Name –launch-configuration Launch Configuration Name –availability-zones Availability Zones –min-size Minimum size of group –max-size Maximum size of group –desired-capacity Starting desired capacity –load-balancers Load Balancers to add each new instance to
Create new CloudWatch monitor to scale up:
as-put-scaling-policy –auto-scaling-group Auto Scaling Group Name –name Policy Name –adjustment Number of Servers –type ChangeInCapacity –cooldown 600
mon-put-metric-alarm “Policy Name” –comparison-operator “GreaterThanThreshold” –evaluation-periods 3 –metric-name CPUUtilization –namespace AWS/EC2 –period 60 –statistic Average –threshold 70 –alarm-actions Policy Result –dimensions “InstanceId=Instance ID to monitor”
Create new CloudWatch monitor to scale down:
as-put-scaling-policy –auto-scaling-group Auto Scaling Group Name –name Policy Name “–adjustment=-1” –type ChangeInCapacity –cooldown 600
mon-put-metric-alarm “Policy Name” –comparison-operator “LessThanThreshold” –evaluation-periods 3 –metric-name CPUUtilization –namespace AWS/EC2 –period 60 –statistic Average –threshold 20 –alarm-actions Policy Result –dimensions “InstanceId=Instance ID to monitor”
Change desired capacity:
as-set-desired-capacity Auto Scaling Group Name –desired-capacity Number of EC2 servers currently desired
Delete auto scaling group:
as-delete-auto-scaling-group Name of Auto Scaling Group –force-delete
as-delete-launch-config Launch Configuration Name –force

References:
1. https://www.ezautoscaling.com/AutoScalingGuide.aspx

2. http://blog.johnalvero.com/2012/03/aws-autoscaling-how-to.html

Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with:
Posted in amazon

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: