AWS Setup For Launching Webserver Using AWSCLI
Task Description β AWS π¨π»βπ»
π Create a key pair
π Create a security group
π Launch an instance using the above created key pair and security group.
π Create an EBS volume of 1 GB.
π The final step is to attach the above created EBS volume to the instance you created in the previous steps.
βA key pair, consisting of a private key and a public key, is a set of security credentials that you use to prove your identity when connecting to an instance. Amazon EC2 stores the public key, and you store the private key. You use the private key, instead of a password, to securely access your instances.β
βA security group acts as a virtual firewall for your EC2 instances to control incoming and outgoing traffic. Inbound rules control the incoming traffic to your instance, and outbound rules control the outgoing traffic from your instance.β
βAn Amazon EBS volume is a durable, block-level storage device that you can attach to your instances. β¦ EBS volumes persist independently from the running life of an EC2 instance. You can attach multiple EBS volumes to a single instance. The volume and instance must be in the same Availability Zone.β
Create a Key Pair
aws ec2 create-key-pair β key-name MyKeyPair β query βKeyMaterialβ β output text > MyKeyPair.pem
Create Security Group & Allow 22 , 80 Ports -
aws ec2 create-security-group β group-name MySecurityGroup β description βMy security groupβ* Allow port 80
aws ec2 authorize-security-group-ingress β group-name MySecurityGroup β protocol tcp β port 80 β cidr 0.0.0.0/0* Allow port 22
aws ec2 authorize-security-group-ingress β group-name MySecurityGroup β protocol tcp β port 22 β cidr 0.0.0.0/0
Launch EC2 Instance -
aws ec2 run-instances β image-id ami-052c08d70def0ac62 β count 1 β instance-type t2.micro β key-name MyArthKey β security-group-ids sg-01b33e2b5c84ea0ce
Create EBS Volume of 1GiB
aws ec2 create-volume β volume-type gp2 β size 1 β availability-zone ap-south-1a
Attach volume with Ec2 insatnce
aws ec2 attach-volume β volume-id vol-0266248156cb351e5 β instance-id i-0214635e40b0a9f83 β device /dev/sdf
SetUp Apache WebServer
*Login into root user
$ sudo su β root1) yum install httpd
Attach EBS volume at β/var/www/htmlβ after create Partition , do format & Create a WebPage -
1) Create partition
# fdisk /dev/xvdb
2)Format it
# mkfs.ext4 /dev/xvdb1
3)Attach at /var/www/html
# mount /dev/xvdb1 /var/www/html
Check It is mounted or not -
# df -h
Stop SeLinux
#setenforce 0
Start the WebServer
#Systemctl start httpd
Check status of WebServer
#systemctl status httpd
Now Setup is ready for launching Webserver