Showing posts with label EC2. Show all posts
Showing posts with label EC2. Show all posts

Solved: Restore root disk of EC2 without changing IP or Hostname

If the root volume of your EC2 instance got corrupt, instance won’t come up. Since you don’t have access to console of EC2 instance so you can’t do much.
In this post we will discuss options to restore an EC2 instance from snapshot backup. Prerequisite for the below guide is that you already have snapshot of the volume which you want to restore.
Option 1 – Different IP and Hostname 
Easiest option to restore an EC2 instance is to launch a new instance with the available snapshot. Refer this AWS doc to launch an instance from backup.
But, an instance launched this way will have both hostname and private IP different from original instance. If this is a problem for you go to option 2.
Option 2 – Same IP different Hostname
So, as per option 1 you have created and instance with an AMI but now you need the IP to be same as old one. To go around this you can detach the network interface of old instance and attach it to new instance.
This option will give you same private IP as old one but you will still have new hostname.
If you need both hostname and IP to be same go to option 3.
Option 3 – Same IP and Hostname
In this option we will discuss how you can restore an EC2 instance and keep both hostname and IP same. This can very important if your EC2 instance is in Active Directory(AD) domain, as change in IP and hostname mapping will cause conflict in domain. Because of this conflict the domain server can block login to the EC2 instance.
Let’s see how we can get around this.
Prerequisites:-
  • You already have snapshot of the root and other volumes of instance.
  • Keep a screenshot of your Instance description from your AWS console, this can be used to refer instance configuration later.
Plan
For the eager one’s, plan is to follow the below steps.
  • Stop the instance
  • Detach the current root EBS
  • Create a new volume from the old snapshot
  • Attach the new volume to instance
  • Boot the instance
Now let’s see the steps in detail.
Stop Instance
Stop the instance if it’s up.
Detach the current root EBS 
  • Select the root volume(/dev/sda1) mentioned as “Root device” from instance description and click on EBS id of the volume.
  • You will now come in “Volumes” window.
  • From the “Actions” drop down select “Detach Volume”
Create a new volume from the old snapshot
  • Create a volume from the snapshot you have taken earlier.
  • Select the snapshot of the volume and from “Actions” drop down select “Create Volume”.
  • In the “Create Volume” window ensure that you select the Availability Zone to be same as the AZ in which your instance is located.
  • Leave the other options as default. 
  • Finally hit “Create Volume”.
Attach the new volume
  • Once your volume is created select it.
  • From the “Actions” drop down select “Attach”.
  • While attaching the volume in the device field mention volume name as /dev/sda1 since we are attaching it as root volume. This is same as your old root volume name.
  • Hit “Attach” .
Boot instance
  • Once the volume is attached start the instance normally. You should now see that the instance has the data from your old backup. Also, it’s hostname and private IP will remain same as before.
Note:- If you want to keep the public IP to be fixed, you need to assign an Elastic IP to the instance. Public IP assigned by default, by AWS keeps on changing with every reboot.
That’s all folks!

Solve: How to add an EBS volume to a Windows EC2 instance and configure it

This post is divided in two sections. In the first section you will see how to create an EBS volume and in the next section we will show you how to configure the EBS volume in windows instance.
Create EBS Volume
  • Go to AWS Console > EC2
  • In the left panel select “Volumes” .
  • Once in the “Volume” screen select “Create Volume”
  • In the “Create Volume” window specify the size of disk and the Availability Zone  in which you want the disk to be created.
Tip:- The disk should be in same AZ as your EC2 instance.
  • Now in the left pane again select the “Volume” to see all your volumes.
  • Select the volume you just created and after that in the upper menu click on “Actions” and select “Attach volume”
  • In “Attach volume” window select the instance to which you want to attach the volume and click on “Attach”.

Configure EBS volume in Windows
  • Login to your windows EC2 instance using RDP. Once inside the instance, from the Start menu go to  “Computer Management” as mentioned below.
Start > Control Panel > System and Security > Administrative Tools > Computer Management
  • Click on Disk Management on the left pane.
  • Here we can see the new disk but it’s still offline. Right click on the new disk and select “Online”.
  • Once the disk is online right click again on the disk and select “Initialize Disk”.

  • If disk is below 2TB, select MBR and click OK
  • Finally right click on the pane where size is shown(refer image below). Select “New Simple Volume”
  • Leave other options as default and click “Next” till you come to “Assign Drive Letter or Path”.  Here we have assigned the drive letter E .
  • Leave everything else as default in next windows and click on finish.
  • Now if we go to “This PC/ My computer” we should see the new disk.


So here we have attached an EBS volume to the Windows EC2 instance. Do let us know in comments section if you have any query.





Solved: How to change hostname in AWS EC2 instance of RHEL 7

In our last post we have seen how to change hostname of an RHEL server.
But if you are using the RHEL 7 AMI provided on AWS marketplace the steps will be slightly different.
First login to your EC2 instance. (Check this post to know How to login to AWS EC2 Linux instance.)
Once you login to your EC2 instance execute below command.
 sudo hostnamectl set-hostname --static cloudvedas
(Here “cloudvedas” is the new hostname.)
If you want to make it persistent across reboot follow further.
Now using vi or vim editor edit the file /etc/cloud/cloud.cfg
sudo vi /etc/cloud/cloud.cfg
At the end of file add the following line and save the file
preserve_hostname: true
Finally reboot the server
sudo reboot
Once the server is up, check the hostname.
ec2-user# hostname
cloudvedas
ec2-user#
It should now show you the new hostname.

Solved: How to login to AWS EC2 Linux Instance

In this post we will discuss how you can login to your AWS EC2 linux instance using Putty.
Pre-requisites :-
Once you are done with the pre-requisites let’s move ahead.
Convert .pem key to .ppk
  • First we will convert the .pem key to .ppk key.
  • Click on PuttyGen you downloaded.
  • Click on “Load”. Browse and select your private key with .pem extension.
Now click on “Save private key” .
It will ask if you want to add passphrase. It’s like additional password when you login. If you want you can enter passphrase in “Key passphrase”.
For this exercise i just clicked on “Yes” .

  • Save key with the name you like. Check that the new key file now have .ppk extension.
Using the  Key for Login
Now we will use the .ppk key we just created to login to our ec2 instance.
  • Open Putty that we downloaded earlier.
  • In the left Pane click on Session.
In hostname enter you server details like user name and IP.
If you are using Amazon Linux Image the default user is ec2-user.  So entry will be like ec2-user@33.44.55.66  and Port 22.

  • In the left navigation pane  click on “Connection” and expand it.
Next expand “SSH” and click on “Auth” (refer image below).

In the right pane click on Browse and select the .ppk key we created earlier.
  • Now in the left navigation pane click on “Session” again. In the right pane in the “Saved sessions”, name the session as “test” or whatever you like and click save. This will save your session so that you don’t have to do this activity again.
  • Finally select the session you created and click “Open”. If all is configured correctly you will now be logged in to you EC2 instance.
Note:- If your ssh session gets timed out after being idle for few minutes check this post on how to set putty keep alive time.

Solved: "Network error: Software caused connection abort"

Some time you may have noticed that your putty session is getting disconnected with error “Network error: Software caused connection abort”
This can happen because of time out setting on server or sometime due to firewall. To resolve this issue you will have to set a keep alive time for the session.
After you set a keep alive time putty will send a packet after the specified seconds to keep the session live.
Generally you can set it to 240 seconds i.e. 4 minutes. But at times you may have to keep it low. Like when I connect from my home laptop to my AWS EC2 instance I’ve to keep it at 2 secs.
To set it:
  • Open Putty.
  • Load the session for which you are facing timeout issue.
  • Click on Connection in the left pane .
Here we have set Seconds between keepalives to 2 . (refer image below)



  • Finally click on “Session” in left pane and save the session.
If you already have other saved sessions in putty you will have to repeat above steps for each of the saved session if needed.

AWS Crash Course – VPC

In the last section we discussed about EC2.  In case you missed it you can check it here AWS Crash Course – EC2 .
In this section we will discuss about VPC.
What is VPC?
  • VPC is Virtual Private Cloud.
  • VPC is like your own private cloud inside the AWS public cloud.
  • You can decide the network range.
  • Your VPC is not shared with others.
  • You can launch instances in VPC and restrict inbound/outbound access to them.
  • You can leverage multiple layers of security, including security groups and network access control lists.
  • You can create a Virtual Private Network (VPN) connection between your corporate datacenter and your VPC.
Components of Amazon VPC:-
  • Subnet: A segment of a VPC’s IP address range this is basically the network range of IPs which you assign to your resource e.g. EC2.
  • Internet Gateway: If you want your instance in VPC to be able to access Public Internet, you create an internet gateway.
  • NAT Gateway: You can use a network address translation (NAT) gateway to enable instances in a private subnet to connect to the Internet or other AWS services, but prevent the Internet from initiating a connection with those instances.
  • Hardware VPN Connection: A hardware-based VPN connection between your Amazon VPC and your datacenter, home network, or co-location facility.
  • Virtual Private Gateway: A virtual private gateway is the VPN concentrator on the Amazon side of the VPN connection..
  • Customer Gateway: A customer gateway is a physical device or software application on your side of the VPN connection.
  • Router: Routers acts like a mediator for your sunets in VPC. It interconnect subnets and direct traffic between Internet gateways, virtual private gateways, NAT gateways, and subnets.
  • Peering Connection: A peering connection enables you to route traffic via private IP addresses between two peered VPCs. Peering connection is used to do VPC Peering by which you can establish connections/tunnel between two different VPCs.
VPC has few more components but to avoid confusion we will discuss about them in later sections.
This series is created to give you a quick snapshot of AWS technologies.  You can check about other AWS services in this series over here .

AWS Crash Course - EC2

We are starting this series on AWS to give you a decent understanding of different AWS services. These will be short articles which you can go through in 15-20 mins everyday.
You can check the complete series here of AWS Crash Course .
Introduction:-
  • AWS compute is part of it’s IaaS offerings.
  • With compute, you can deploy virtual servers to run your applications.
  • Don’t have to wait for days or weeks to get your desired server capacity.
  • You can manage the OS or let AWS manage it for you.
  • It can be used to build mobile apps or running massive clusters.
  • You can even deploy application serverless.
  • It provides high fault tolerance.
  • Easy scalability and load balancing.
  • You are billed as per your usage.
What is EC2?
  • EC2 is Elastic Compute Cloud
  • It’s VM (virtual machine) in cloud.
  • You can commission one or thousands of instances simultaneously, and pay only for what you use, making web-scale cloud computing easy.
  • Amazon EC2 reduces the time required to obtain and boot new server instances to minutes, allowing you to quickly scale capacity, both up and down, as your computing requirements change.
  • Amazon EC2 provides developers the tools to build failure resilient applications and isolate them from common failure scenarios.
What are EC2 pricing models?
  • On Demand – Pay by hour no long term commitment.
  • Reserved – Yearly reservations up to 75% cheaper compared to On Demand.
  • Dedicated – A dedicated Physical server is provided to you. Up to 70% cheaper compared to On Demand.
  • Spot – Bid on spare Amazon computing capacity. Up to 90% cheaper compared to On Demand.
EC2 Instance Types:-
  • General Purpose (T2, M4 and M3) – Small and mid-size databases
  • Compute Optimized (C4 and C3) – High performance front-end fleets, web-servers, batch processing etc.
  • Memory Optimized (X1, R4 and R3) – High performance databases, data mining & analysis, in-memory databases
  • Accelerated Computing Instances(P2, G2 and F1) – Used for graphic workloads
  • Storage Optimized I3 – High I/O Instances – NoSQL databases like Cassandra, MongoDB
  • D2 – Dense-storage Instances – Massively Parallel Processing (MPP) data warehousing, MapReduce and Hadoop distributed computing
Check out more details in next section .  AWS Crash Course – VPC
If you want to try some hands on, you can follow this guide to launch Amazon Linux Instance or this for Windows instance.