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

Sunday, January 19, 2014

How to Resize the Root Partition in Linux on Amazon EC2

Check the Root Partition size before resize:
df -h

1The current root partition size is ~8 GB.

After that, stop your instance:
sudo poweroff

2

Go to Volumes on the left-hand EC2 navigation control panel.Right-click on the volume you want to resize and select Create Snapshot.

3Note: Make sure you also check the availability zone.

Fill out the details of the snapshot you are creating.

4

Go to Snapshots on the left-hand EC2 navigation control panel.Right-click on the snapshot you created and select Create Volume from Snapshot.

5

Enter the new size of the partition that you would like to be, select the same availability zone in which your instance is running and click Yes,Create.

6

Go back to the Volumes in the EC2 control panel. Select the old root volume, right click on it and select Detach Volume.

7

Now right click on the new volume that we have just created and select Attach Volume.

8

Please make sure that the volume should be attached as /dev/sda1:

9

Now turn on your instance. Make a note of your partition name, in my case it is /dev/xvda1. Type the resize2fs /dev/xvda1 command.
sudo resize2fs /dev/xvda1

10

After that view the new root partition size.
df -h

11

Yes, it’s work

Hope this will help you!

Please Remember me in your prayers!

{Workaround}how to get access to the server, when Amazon EC2 private key lost

1. Login to your AWS Management Console.

2. Select  EC2 from the Services | set your Region in the drop-down list | Click the Instances link in left side bar.

3. Right click on the instance name. The Instance Management context menu will appear. Select Create Image.

1

4. Enter the name and description. This is for your use, not Amazon’s.Click the Create Image button. A confirmation message appears. Behind the scene, EBS volume is copied to a snapshot.

2

5. Find your new AMI. AMI link is in the left navigation bar. Right Click on it and select the Launch (Follow the wizard).

3

6. In the last step, select the “Create a new key pair” instead of using the existing key pair,provide the name to your key pair and then click Download Key Pair Button.

4

7. Convert the downloaded key (for Putty use)  by using the following Tutorial.

8. Connect to the instance with the converted key and verify your data/setting.

5

Hope this will help you!

Please Remember me in your prayers!

Monday, June 17, 2013

How to connect to an EC2 instance using Putty

You created an EC2 instance and got private key (with PEM extension)from Amazon. Now, how you can login to your instance with PuTTY? For this, you need to convert the .PEM to .PPK format using Puttygen.

Run Puttygen:



Click on the Load button:



Locate your PEM file that you want to convert:



Putty will convert the .PEM to .PPK format:



Select “Save Private Key” (passphrase is not required):



Launch Putty and enter the Instance IP address:



Navigate to Connection -> SSH -> Auth, Click “Browse” and select the .PPK file and Click “Open“:



When connection comes up enter username (default is ubuntu for Ubuntu and root for CentOS):



Hope this will help you!

How to Mount EC2 EBS Storage To EC2 Linux Instance

Login to your AWS management console,click on EC2 in the list of AWS products and from there, identify the correct region of EC2 instance because EC2 EBS volume must be in the same location as the EC2 instance:



Click Volumes located under Elastic Block Store then click on Create Volume button, which will launch the EBS volume creation wizard, Simply fill in the details and click Yes,Create:



Note: EBS volume that is created in us-east-1a, will only be mounted to a EC2 instance located in us-east-1a.

Right clicking on the EBS volume that we have just created and select Attach Volume from the menu:



Select the Instance that you want to attach with EC2 EBS volume:



Then click the Yes, Attach button to attach the EBS volume:



Next login to the AWS instance where you attached the EBS volume and type:
sudo fdisk -l



Where xvdf is our newly added EBS!

To create the partition on the second EBS, use the following command and follow the “on screen” instructions:
sudo fdisk /dev/xvdf



Use the partprobe command to update the kernel with the changes:
sudo partprobe /dev/xvdf

Note: Where /dev/xvdf is my device name, you can use your’s!

Now we need to format our newly created parition using the following command:
sudo mkfs /dev/xvdf1 -t ext4



Verify the newly created partition:
sudo fdisk -l



Next you need to create a directory for a mount point:
cd /mnt/
sudo mkdir 2ndEBS



Next, mount the newly created xvdf1 parition into 2ndEBS directory:
sudo mount /dev/xvdf1 /mnt/2ndEBS -t ext4



Configure the permission on 2ndEBS directory:
sudo chmod 0777 /mnt/2ndEBS/



Now, we make a test that we can write a file on to the new drive:
touch /mnt/2ndEBS/test.txt
ls /mnt/2ndEBS/*



Next time, when we will reboot the computer, it will be gone. If we want to mount new EBS permanently then we need to edit the fstab file:
sudo nano /etc/fstab



Add this line at the end of the fstab file(you can adjust it according to your requirement):
/dev/xvdf1 /mnt/2ndEBS ext4 defaults 0 0



Use this command or else reboot your computer:
sudo mount –a



Hope this will help you!

Apache Virtual Hosts in Ubuntu

In this tutorial, I’ll show you the steps to configure 3 Apache virutal hosts running on a single EC2 Ubuntu Instance. The three domains, that I’ll use in this tutorial are:
1) linuxsoft.tk
2) rbgeek.tk
3) tendo.tk

DNS setting for these 3 domains are as follows:







Create three folders inside the /var/www folder, they will host these new sites:
sudo mkdir /var/www/tendo
sudo mkdir /var/www/rbgeek
sudo mkdir /var/www/linuxsoft



Copy the /etc/apache2/sites-available/default file with the name same as the new sites:
cd /etc/apache2/sites-available/
sudo cp default tendo
sudo cp default rbgeek
sudo cp default linuxsoft



Edit the new config files for each site:
sudo nano linuxsoft



Add the line ServerName with the name of your domain/site and change both DocumentRoot and Directory that point to your new site:



Repeat these steps for other new sites same as above:
rbgeek.tk




tendo.tk





To enable the each virtual host, simply type:
sudo a2ensite tendo
sudo a2ensite rbgeek
sudo a2ensite linuxsoft
sudo a2dissite default



Finally, restart the Apache service:
sudo service apache2 restart



Test all the sites:

http://www.tendo.tk



http://www.rbgeek.tk



http://www.tendo.tk



Troubleshooting:





Hope this will help you!