Linux > Virtualization

Configuring and setting up auto scaling in AWS

(1/1)

aravindm:
What is Auto scaling?

In basic term auto scaling means that, adding compute instances EC2 when the load on the server reaches particular threshold on the higher side. Also removing the compute instance EC2 when the load on the server comes back to normal. This particularly helps to making sure that required amount of compute power is available whenever required.

This also helps to avoid over usage and under usage of resources.

What things required to configure-setup auto scaling in AWS

1. Launch Configuration (Template)

* AMI (Ex: Amazon Linux, Redhat Linux)–> Type of operating system
* Instance type (Ex: t2.micro, m4.large)–> Type of hardware required
* Storage
* Security Group
* SSH-Key pair
2. Auto scaling Group

* Launch Configuration
* Network/Subnet’s–> choosing appropriate AZ’s for instance
* Scaling policies for increase
* Scaling policies for decrease
* Monitoring & Alarm
Steps to configure-setup auto scaling in AWS for web server

As a demo we will be using auto scaling for our web server. However you need to use auto scaling as per your need.

Step 1: Building web server.

Firstly we need to configure web server

Step 2: Create AMI image.

In the next step we need to create AMI image of the web server created so that additional servers can be added when required.

Step 3: Create launch configuration using the web server AMI .

Now to create launch configuration go to Auto scaling –> Launch configurations option as below in the left pane of AWS console window.



   
* Click on Create Auto scaling group button.


   
* Click on Create launch configuration button on the right bottom.


   
* Select the Custom AMI created in the step 2.
For this select My AMIs and click on select button.




* In the next step select General purpose and t2.micro
* For the next step which is for Name of the launch configuration, give it name “Web-server_lauch_config” and click on “Next: Add storage button”


   
* Don’t change anything under storage details and click on Next:Configure Security group.
* In the security group configuration choose the security group configuration as per your configuration. In our demo we are selecting “launch-wizard-33” which opens the port 80 and 22.


   
* Click on Review and click on Create Launch configuration in the next step.
* For the next step, select an key pair new one or existing one based on your requirement and click on create launch configuration button.


Step 4: Create Auto Scaling Group:

In the next step you need to create Auto Scaling Group.  In the first step use below options.


* Group name: you need to give the name for your auto scaling group. I am giving name as “Auto scale group”
* Group size:Here you need to choose Group size as per your requirement. Here for demo purpose we are taking one. So that it will launch 1 instance at the beginning.
* Network: Here I am using default one. You can use your own VPC if have configured and
* Subnet: Select subnet as per required AZ’s. This ensures that service is available across multiple AZ’s. Click on “Next: Configure scaling Policies” button.



   
* Next step is very important which defines how do we need to scale the instances.
* Select “Use scaling policies to adjust the capacity of this group” option using radio button.
* For Scale between option select 1 and 4 which defines minimum and maximum instances to be launch.


      3. Now for “Take the action:” option under “Increase Group Size” select Add 1 instance. In case you wanted to have more you  can use accordingly.
      4. Click on “Add new alarm”  under “Increase Group Size” and select following options in next popup. This configuration we will add new EC2 instance once CPU utilization increased above 30% and wait time is 5 minutes.



      5. Now for Scaling down, for “Take the action:” option under “Decrease Group Size” select Remove 1 instance.
      6. Click on “Add new alarm”  under “Decrease Group Size” and select following options in next popup. This configuration we will remove EC2 instance once CPU utilization decreased below 20% and wait time is 5 minutes.



       7.Click on “Next:Configure Notifications” and select below options. You can also create new topics if you want. Next click on Next configure Tags button. This configuration item will send notification for triggered events.



       8. Select following options in the Tag options and click review button.
       9. If everything looks ok then click on “Create Auto Scaling group” button.
       10. At the end you will get  below successful message.



Now you can able to see that one instance is started running with tag “Auto Scaled Web servers” automatically.



Step for increasing CPU utilization:

In real scenario this step in not needed. However for demo we need to increase the CPU utilization so that EC2 will be scaled up automatically.

* Login to auto scaled web server as root.
* execute below commands
--- Code: ---vi /tmp/inc_cpu.sh
--- End code ---

and put below lines in the same file as many you can.


--- Code: ---dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
dd if=/dev/zero of=/dev/null bs=50000 count=100000
--- End code ---
Save and quit file using “:wq!” option. Make the script executable using below command.


--- Code: ---chmod u+x /tmp/inc_cpu.sh
--- End code ---

Now goto /tmp using “cd /tmp” command execute shell script multiple time created so that CPU utilization will increase.


--- Code: ---nohup ./inc_cpu.sh &
--- End code ---

You will notice that CPU utilization will start increasing as below since Idle Utilization is zero:


--- Code: ---top - 18:06:30 up 34 min,  2 users,  load average: 2.37, 0.70, 0.24
Tasks: 101 total,   5 running,  96 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.0%us, 98.0%sy,  0.0%ni,  0.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   1017372k total,   178292k used,   839080k free,     9016k buffers
Swap:        0k total,        0k used,        0k free,    98176k cached
--- End code ---

As a result of this auto scaling policy , one Ec2 instance will be get launched (initialized) automatically (after cooling period of 300 secs) since our threshold of above 30% CPU utilization has passed already .



After some time, once CPU utilization decreases below 20%. In our case idle becomes 100%.



This how we can configure-setup auto scaling in AWS.

 ;)

Navigation

[0] Message Index

Go to full version