EC2_Notes
EC2_Notes
wide,
these locations are composed of regions and Availability Zones.
Each region is a separate geographic area. Each region has multiple,
isolated locations known as Availability Zones.
Security Group:
==============
a) SG is a virtual firewall. It can be attached to the Ec2 instance.
b) SG configration is having two parts
i) Inbound rules
ii)outbound Rules
b) What type of requests server allows, will be configured in Inboud Rules.
c) What type of requests server can send, will be configured in Outbound Rules.
d) In SG we can Configure only allow rules.
e) One security Group can be attached to Multiple Ec2 instances.
f) One Ec2 instance can have upto max of "5" Security Groups.
Keypair:
=======
a) To log in to your instance, you must create a key pair, specify the name of the
key pair when you launch the instance, and provide the private key when you connect
to the instance.
Type of Instance :
==================
Amazon EC2 provides a wide selection of instance types optimized to fit different
use
cases. Instance types comprise varying combinations of CPU, memory, storage,
and networking capacity and give you the flexibility to choose the appropriate mix
of resources for your applications.
Ex :
t2.nano,t2.micro,t2.small,t2.medium,t2.large,t2.xlarge,t2.2xlarge
Creating Keypair:
================
a) Goto EC2 DashBoard
b) On the navigation bar select region for the key pair
c) Click Key Pairs in the navigation pane
d) Click Create Key Pair
e) Enter a name for the key pair in the Key Pair Name field of the dialog box and
click Create
f) The private key file, with .pem extension, will automatically be downloaded by
the browser.
Note :
a) You can also attach existing SecurutyGrouop to ec2 instance.
b) you can connect to linux ec2 instance by ssh protocal.
Note : You will find "User data" feild ,In instance creation Process,
"Configure Instance Details" step is having
section called "AdvancedDetailed".
Stop Ec2 instance: If instance is in running state we can stop the instance
==================
1) Goto EC2 DashBoard
2) Select The ec2 instance
3) Action --> Instance State --> "Stop"
Note: When we stop the instance public will be removed from the instance.
when we start the instance new public ip will be assigned to ec2 instance.
Reboot Ec2 instance: If instance is in running state we can "Reboot" the instance
====================
1) Goto EC2 DashBoard
2) Select The ec2 instance
3) Action --> Instance State --> "Reboot"
Practice:
=========
1) Launch an ec2 instance in Mumbai region
2) Launch an ec2 instance in Mumbai region "ap-south-1a" AZ.
3) Create a security group and configure inbound "ssh" & "http" rules
4) Attach "step3" security group to "step2" ec2 instance.
5) Stop the "step2" ec2 instance and check the public ip address.
6) start the Ec2 instance after step5 execution,check the public ip address.
7) Create new keypair
8) Launch an ec2 instance using step3 "SecurityGroup" & step7 keypair
9) Install apache2 in Ubuntu Ec2 instance at the time of Launch.
Elastic IP(EIP):
================
It is a dedicated public IP address which
is reserved for your account, It can be assigned any ec2 instance in you account.
After attaching it to ec2 instance,Even if we stop the ec2 instance this public
will
not be released from instance , It remain attached with EC2 instance.
Practice:
=========
1) Create EIP and attach it to any existind Ec2 instance.
2) Stop the EC2 instance and check public is released or not from the Instance.
3) Realese the EIP from EC2 instance
4) Realese the EIP from your account.
1) EBS is primary storge unit for EC2 instance, Only in EBS we can install OS and
softwares.
2) Its block based storge, Other two storges (EFS,S3) are object based storges.
3) One EBS volume we can be attach to one ec2 instance at a time
4) We can attach EBS volume to ec2 instance, only if Instance & volume in same AZ .
5) EBS,S3 service is availble in all regions, EFS is not availble in all regions.
6) EBS Volumes (Disk) performance is measured by using IOPS(Input Output per
second).
7) There are Five types of EBS volumes
a) GP2
b) IO1
c) SC1
d) ST1
e) Magantic
Note : Above Five EBS volumes supports various rate of IOPS, And high IOPS have,
high pricing.
8) Outof five EBS volume only below types can be root volumes
a) GP2
b) IO1
c) Magantic
9) Root Volume: Root volume means where we install the OS. At the time of ec2
instance
launch this volume is created.
Note :
a) If volume state is "inuse" means it is attached to EC2 instance.
b) If volume state is "availble" means it is not attached to EC2 instance.
Practice:
=========
1)
a) Create an ubuntu EC2 Instance in mumbai region "ap-south-1a" AZ.
b) Create "gp2" volume in mumbai region "ap-south-1a" AZ.
c) Attach it to the step1 ec2 instance.
d) Mount it to Ubuntu instance and create some files in newly added volume.
e) Unmount & detach it from the instance
2)
a) Create new ubuntu ec2 instance in mumbai region "ap-south-1a" AZ.
b) attach & mount "Practice 1" volume to it.
c) check the files which you have created in "Practice 1 (step 4)" .
Steps:
1) Launch new "T2 Large" Instance
2) Stop existing "T2 Micro" Instance
3) Detach "root" volume from "T2 micro" Instance
4) Stop "T2 Large" Instance (Step1)
5) Detach "root" volume from "T2 Large" Instance
6) Attach t2micro instance root volume (step3) to
t2 Large instance (Root volume device type value must be "/dev/sda1" )
2nd Method:
==========
1) Goto Ec2 dashboard
2) Select the EC2 instance
3) Goto "Actions" --> "Instance settings" -->"Change Instance Type.
Snapshot:
========
1) Snapshot is a point in time backup of EBS volume.
2) Snapshot is at region level.
3) Based on snapshot we can create new EBS volumes
4) Snapshot is stored in S3 bucket.
5) snapshot size must be >= volume size.
6) We can copy snapshot to other regions also
7) we cannot attach snapshot to EC2 instance, To access
snapshot data ,we need to create volume.
Creating Snapshot:
==================
a) Goto EC2 dash board
b) Goto "Elastic Block Storge"
c) Click on Volume
d) select the Volume which you want to take the backup.
e) Click on "Actions" --> "Create Snapshot"
f) Created snapshot will be in Snapshot section.
i) Goto EC2 dash board
ii) Goto "Elastic Block Storge"
iii) Click on Snapshots
Steps:
i) Goto EC2 dash board
ii) Goto "Elastic Block Storge"
iii) Click on Snapshots
iv) Select the snapshot
v) Click on "Action" --> Create Volume
vi) Created volume will be in Volume section
vii) Attach the created volume to any ec2 instance.
Practice:
=========
1)
a) Take the backup of any existing EBS volume
b) Create a new volume from snapshot
c) attach & mount it to any ec2 instance.
d) Check the data is exists or not.
ELB Listener:
--------------
Front End Listener:
==================
An ELB Listener, is the process that checks for connection
request Listeners check for traffic from "clients to the ELB"
Backend Listener:
=================
Listeners are configured with ports to check for traffic from ELB to EC2
ELB Features:
=============
a) It may take sometime for the registration of ec2 instance under ELB to complete
b) Elb also monitor the health of its registered instances and ensures that it
routes traffic only to healthy instances
-> A health instance shows as "In-service " Under ELB
c) When ELB detects instance is unhealty it stop routing traffic to the instance
-> A unhealth instance shows as "outof-service " Under ELB
d) When ELB service detects ec2 instance is back to healthy it resumes traffic
routing to
that instance
e) By default elb uses ping HTTP (port 80) for health checks
b)Sticky Sessions:With the stickiness feature, you can configure the load balancer
to bind usersessions to specific application instances. All requests coming from
the user during
the session will be sent to the same application instance.
d) ELB Idle Timeout : it is the number of seconds a connection can be idle before
the load balancer closes the connection.
Practice:
========
1) Create two ec2 instances in different AZs ( allow ssh & Http requests in SG )
2) Install Apache2 webserver on above two instances
3) Apache run on port number 80.
4) Successful apache2 installation will open default apache2 webpage
(copy paste the "public ip " in the browser.)
5) Default apache2 page location
/var/www/html/index.html
6) Create a clasic loadbalncer:
a) Goto Ec2 Dash Board
b)on the navigation pane, under LOAD BALANCING, choose Load Balancers.
c)Choose Create Load Balancer.
d)Select "Classic Load Balancer", choose Create.
i)Provide Required details like "Load Balancer name"
ii) Click on "Next: Assign Security group"
iii) Choose "create new security group:
and add http port requests
iv) Click on "Configrue Security Settings"
v) Click on "Next : Configrue Health Checks"
vi) Click on " Nex: Add Ec2 Instances
v) Select the instances which you want to add.
vi) click on Next
vii) click on " Review and create".
Application ELB:
================
Based on application context we can distribute the
load between the application related servers
Target Groups: Group the servers based on Application context.This process we call
it as a Target
groups.
AutoScalling:
=============
1) Allows your AWS ec2 to grow or shrink depending on your workload
2) AS Ensures that you have the right number of AWS ec2 instances
4) AS always try to even distribution of the ec2 instances between the AZs
5)AS can span Multiple AZs within the Same region.Hence it can be used to create
Fault Tolerant design.
6) No additional cost for launching AS group,you pay for what you use of EC2
instances.
10) You can determine which subnets will AS group use to launch new instances
in each AZ.
2)Auto Scalling Group (ASG): Here we define Scalling activity process related
parameters like.
a) What type of scalling Activity Manual/Event based
b) Scalling Activity parameters like "max","min","desire"
c) AutoScalling helth check types
Note :
a) ASG manage's ec2 instances based on defined AutoScalling policy parameters.
b) ASG have 3 imp parameters
i) Min : The Min size of the ASgroup
ii) Max : The maximum size of the ASgroup
iii)Desire:The number of EC2 instances that should be running in the group.
This number must be greater than or equal to the minimum size of the group
and
less than or equal to the maximum size of the group. If you do not specify a
desired capacity, the default is the minimum size of the group
AS Rebalancing:
==================
a) If AS finds the the number EC2 instances are not evenly distrubuted across AZ,
It will initiate Rebalancing Activity.
c) AS does this by launching new Ec2 instances in the AZs that have less
Ec2 instances first,then terminating EC2 instances from the AZs that
have more number of EC2 instances.
d) In rebalncing activity AS temprarily launch instances more then what you have
define in ASG "Max" value .
e) The extra number of instances is less then or equal to 10% of max capacity
value.
Q) What will happen if the AS group was at or near max capacity when AZ
rebalncing kincks in?
Type of AutoScalling:
=====================
a) Manual Scaling :
i) Maintains a current number of instance all the time
ii) Manually changes ASG's min/desired/max, attch/detach instances
Practice:
=========
Q3) Delete Q2 ASG & and check ASG instances are deleted or not
Q5) Edit Q4 ASG and add "ap-southeast-2a" AZ and check how rebalncing is performed
by ASG
Q7) Manualy Stop any EC2 instance in Q4 ASG group and check the result.
============================================================================
AS-ELB Practice:
Q8) Create Launch configration in "Tokyo Region" with below parameters
a) t2 micro instace type
b) ubuntu 16 ami
c) use any existing keypair
d) use any exsting SecurityGroup (add Http inbound rule)
e) Install apache2 using user data.
Q9)
a) Create an Autoscalling group (ASG) with 2 ec2 instance using Q8
Launch configration.
b) Create New clasic ELB .
c) EDIT Q9(a) ASG to attach ELB.
d) check ASG instances were automatically registered with Elb
e) Stop the apache2 service in one ec2 instance &
and check instance health status
in ELB & ASG
f) Start Apache2 service again in step(e) ec2 instance
and check instance health status in ELB & ASG
g) EDIT step(a) ASG and "Health check" type to ELB
i) Stop the apache2 service in one ec2 instance & and check instance health status
in ELB & ASG, This time ASG will replace the instance.
Imp Que:
========
ELB is attached to the ASG, Instance state is showing "Outof service" In ELB
health checks, But in ASG Health checks it is showing "Inservice".
What might be the problem, Why there is a mismatch?
ASG Health Checks:
=================
a) AS clasifies its EC2 instances status as either Healty or Unhealty
b) By default ,AS uses EC2 status Checks only to determinethe health
status os an instance
c) When you have one or more ELBs defined with the AS group,
you can configure AS to use "both" the Health checks and the ELB
Health checks to determine the instances helath status.
c) Until the Grace Period timer expires, any unhealty reported by EC2 status
checkes,
or ELB attached to ASG,will not be acted upon.
ii)If ELB health check are configured to be used by ASG, If ELB reports the
instance
status "Out-of-service"
iii) One source reports the instance as unhealty is enough for AS to mark it for
replacement.
c) Elastic IP and EBS volumes ges detached from the terminated instances,
you need to manually attach them to new instances.
Practice:
========
Q10) Attach any existing ec2 instance to ASG.
Q11) Detach any existing ASgroup ec2 instance.
Q12) What happend if detach ec2 instance from ASG without changing "desire"
parameter
value.