Auto scaling and Load Balancing using AWS
Step 2: Start the service by logging into the EC2 Machine
Install the web service with the following commands
yum install httpd -y
Start and enable the web service with the following commands
service httpd start
chkconfig httpd on
logout
Step 3: Create AMI
Right click the existing the running instance
Image Name: redhatweb
Image Description: webserver
Create image.
Go to Images -> AMIs-> you will see AMI creating is in Progress
Step 4: Create Classic Load Balancer
- Load Balance name: Webserverelb
-Select existing security groups which is associated with the instance ( here Security group : Auto scaling)
-Configure Security Settings: None
-Configure Health Check: Ping Protocol: HTTP , Ping Port: 80, Ping Path: /index.html
Advanced Details: Response Timeout: 5sec, Interval: 30sec, Unhealthy Threshold: 2sec, Healthy Threshold: 5sec
Notes:Healthy theshold 5 sec mean if index.html is reachable then the server is healthy threshold and hit 5 times
if index.html is not reachable it shows unhealthy and hit only 2 times.
Suppose index.html is not reachable, first it will hit index.html and timeout. Pack will be dropped in 5 sec. Again it will hit index.html
and packet will drop out.
After that it will take 30 sec to re-hit
- For classical load balancer, target group is not required. For application load balancer target group is required
- Add EC2 Instances: DONOT run any running instances. It will be blank
- Tag is optional, you can ignore.
- Review and Create, and click create.
Now Load balancer is created successfully and click close button
- Now you see there is no instance attached to this load balancer
- Now terminate the running instances as shown below
Step 5: Launch Configuration (Auto Scaling)
Lets create launch configuration in which Image has to be used for webserver
- Create Launch Configuration, Name: webservice
- Select My AMIs: Select Redhat (Name: webserver) instance (AMI) we created initially
- Instance Type, Select t2.micro
- Configuration Details, Name:webserver
- Add storage: Defaults
- Configure security group: select existing security groups : Auto scaling (ASG)
- Review and select existing key pair
- create Launch Configuration
Launch configuration is created successfully
Note: Next we need to create auto scaling group using the launch configuration template
Step 6: Create Auto scaling groups
Create Auto scaling group details
· Group Name: web
· Launch Configuration: webservice
· Group Size: start with 2 instances
· Network: Default VPC
· Subnets: Select 3 subnets
· Advanced details
· -Check Recover traffic from one or more load balancers
· Classic Load balancers: select webservers in the list
· Target group: none
· Health check type: ELB or EC2. Here we select EC2
· Health check grace period: 300 secs
Configure scaling policies
· Select — Use scaling policies to adjust the capacity of this group
· scale between 2 and 2 instances. (It should not be less than 2)
· Metric Type: Average CPU utilization
· Target value: 70
· Note: here if CPU utilization is more than 70% two more instances will be launched.
· Instance need: 300 sec
· Note: For launching 2 instances, the CPU utilization should be 70% minimum for 300 sec
Configuration Notifications
· None
Configure tags
· None
Note: before creating auto scaling group, check that you don’t have any running instances.
As soon as you click the auto scaling group you will see two instance will be launched immediately
Review
· Create auto scaling Group
Note: The instance that created now will be added under classic load balancer as shown below
Step 7: Create index.html on both servers
· Open the first instance in the terminal windows and in the root directory create index.html using the following command
vi index.html
Enter the following text as insert mode and exit the windows (:wq!)
This is my Primary server
Open the second instance in the terminal windows and repeat the same process but the text will be as shown below
This is my secondary server
Now you will see the servers will be up and it takes some time for the server up
Copy the DNS link in the web browser as soon as you see both servers active status is UP
Then you will see in the browser window the following messages and changes as you keep refreshing the browser
This is primary server
This is secondary server