Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Wednesday, July 22, 2015

Importing VMDK to AWS using EC2 CLI

Yesterday I showed how we can import OVA file to AWS as an AMI image, today I'm going to demonstrate how we can import actual VMDK file that is exported from any virtualize software as an instance in EC2.

Before we started, there are prerequisites to be done first.

1. Setting up EC2 CLI to work with your terminal. Test it with simple command:
> ec2-describe-regions
2. Create S3 bucket, name it anything you want. Mine is "instance-manifest". This bucket will save our VMDK's manifest and small VMDK parts then convert them to EC2 instance.


3. Now use this command to start importing VMDK:
> ec2-import-instance -o <Access Key> -w <Secret Key> -t <Instance Type> -a x86_64 -f <File Type> -p <Platform> -b <Bucket name> -s <EBS disk size> -z <Availability Zone> "\path\to\file.vmdk"
Change to red highlight to appropriated value to suit your environment.

Example Command:
> ec2-import-instance -o Your_Access_Key -w Your_Secret_Key -t t2.micro -a x86_64 -f VMDK -p Linux -b instance-manifest -s 10 -z ap-southeast-1a "D:\Downloads\ubuntu-disk1-streamed.vmdk"
4. Let's check to status of importing with the following command:
> ec2-describe-conversion-tasks --region <region_name>
or
> ec2-describe-conversion-tasks <task_id>
5. When the importing is done. Go to AWS console, EC2 then you'll see new instance from conversion.

Tuesday, July 21, 2015

Setup SSH Public Key Credentials for imported instances

In fact, there are many prerequisites to be done before exporting VMDK file and import it into AWS. One of them is to configure a non-root user to use public key-based SSH to access your instance after it is imported. 

I haven't done it yet, so here's the thing I did after I imported my VM.

1. Login to instance using password method.
2. Create public key for my root account using the following script:

if [ ! -d /root/.ssh ] ; then
        mkdir -p /root/.ssh
        chmod 700 /root/.ssh
fi
# Fetch public key using HTTP
curl http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/my-key
if [ $? -eq 0 ] ; then
        cat /tmp/my-key >> /root/.ssh/authorized_keys
        chmod 700 /root/.ssh/authorized_keys
        rm /tmp/my-key
fi
***This script can be applied to any user account.

3. Create private key from given public key pair you downloaded when you create an instance using putty gen.
4. Login with that private key and edit "/etc/ssh/sshd_config" file with these following conditions:

RSAAuthentication yes
PublicKeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys
PasswordAuthentication no
UsePAM no
PermitRootLogin without-password
5. Or you can create your own key for each account with the following command:
l2oxAz@localhost:~/$ ssh-keygen -t rsal2oxAz@localhost:~/$ ssh-copy-id l2oxAz@127.0.0.1


Importing OVA to AWS as AMI using AWS CLI (Part 2 of 2)

Okay, Now we are going to import our OVA files using AWS CLI tool. I've already created S3 bucket in my AWS account and uploaded OVA files also, put it in bucket named "exported-vmdk"

Let's open our terminal/cmd console or whatever console you're using with AWS CLI and type the following command to import OVA file and convert it into AMI image.

Here's my example of the command:

>aws ec2 import-image --cli-input-json "{  \"Description\": \"Ubuntu OVA\", \"DiskContainers\": [ { \"Description\": \"First CLI task\", \"UserBucket\": { \"S3Bucket\": \"exported-vmdk\", \"S3Key\" : \"ubuntu.ova\" } } ]}"

****S3Bucket is the bucket name on S3, S3Key is the name of the OVA file you're going to import
****Don't forget to change the command to suit with your environment.


Now If it successes, you can track the importing status by using the given image ID with this command:

>aws ec2 describe-import-image-tasks –import-task-ids <image-ID>

Once everything is done, login to AWS console, go to EC2 and look for AMI section. There will be an AMI image wait for you to create a new instance.

Sunday, January 9, 2011

How to monitor your apache status.

I'll using mod_status which apache2 has provided for.
It's easy to use and you can also use perl script to grab some information you'd like to.

Let's see if you've already got mod_status
browse to your /etc/apache2/mods-available/ 
just list the items and have a look. I think for apache2 they've just put it in already.

So now let's have a test.
$apache2ctl full status
If  it said that you need to add some kind of extended status,
Let's head to the /etc/apache2/apache2.conf and added this code at the end of file.
ExtendedStatus On
Now, your apache status will come up with full information.

If you need more configuration, please have it configured in /etc/apache2/mods-available/status.conf
<IfModule mod_status.c>

# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Uncomment and change the ".example.com" to allow
# access from other hosts.
<Location /server-status>
     SetHandler server-status
     Order allow,deny
     Order deny,allow
     Deny from all
     Allow from localhost ip6-localhost
     Allow from .example.com
</Location>
 </IfModule>


Tuesday, December 21, 2010

Doing some works on Load Balancer with Crossroads.

Well, it's finally about time to begins my senior project stuffs.
Let's say I've been doing busy with some jobs earlier, So I didn't have a chance to look at it much.
But It is nearly new year, everybody's going back their home after midterm examinations.
For me, It's time to move on and working on stuffs.
The less people, The more I can concentrate on this work. (I don't like to be surrounded by people much.)

Talk to much, let's see how I install crossroads on ubuntu. It's easy and work fine.

First download the crossroads package from their website.
$cd /
$wget http://crossroads.e-tunity.com/downloads/crossroads-stable.tar.gz
Untar it.
$tar -xzvf crossroads-stable.tar.gz
Then before starting our installation. Make sure that you've already installed the build-essential package.
$sudo apt-get install build-essential
 Let's begin!
$cd crossroads-2.68
$sudo make install
Wait for a moment. Then we done!
Now it's time for configuration.
Crossroads provides two ways of configuration. Using command-line, or using xml.
Let's see the first one. If we need to use command-line, then we use "xr" command for all configuration.
$xr --verbose --server tcp0:80 / #this will tell xr that we use this server as load balancer
-W 10.10.10.1:8001 / #and this will create our web interface on port 8001
-backend 10.10.10.2:80 / #this will create backend according to the ip address and port
-backend 10.10.10.3:80
This will make your server to listen to port 80 and to dispatch traffic to servers 10.10.10.2 and 10.10.10.3
A web interface for the balancer is started on port 8001

Instead of starting XR by hand, we may use xrcrl as preferable. But first, you've to create a configuration.
To do so, put the following in the file /etc/xrctl.xml
<?xml version="1.0" encoding="UTF-8"?>
     <configuration>
        <system>
          <uselogger>true</uselogger>
          <logdir>/tmp</logdir>
        </system>
        <service>
          <name>web</name>
        <server>
          <address>0:80</address>
          <type>tcp</type>
          <webinterface>10.10.10.1:8001</webinterface>
          <verbose>yes</verbose>
        </server>
        <backend>
          <address>10.10.10.2:80</address>
        </backend>
        <backend>
          <address>10.10.10.3:80</address>
        </backend>
        </service>
     </configuration>
Then type these following commands to start the xr
$xrctl start
Or to stop.
$xrctl stop 
That's all for today. Late night again. OMG!!

Credits : Crossroads

Saturday, December 18, 2010

How to install FTP with vsftpd.

Very easy to configure. recommended!!


First install via apt-get
$sudo apt-get install vsftpd
Let's have it back up before doing anything is recommend!
$sudo cp /etc/vsftpd.conf /etc/vsftpd.conf.bak
Now begin to configure!
Disable anonymous login and enable local users login, give them write permission.
anonymous_enable=NO
# Let local users login
# If you connect from the internet with local users, you should enable TLS/SSL/FTPS
local_enable=YES

# Write permissions
write_enable=YES
To Deny some users to login
userlist_deny=YES
userlist_file=/etc/vsftpd.denied_users
In the file /etc/vsftpd.denied_users add the username of the users that can't login. One username per line.

To Allow some users to login
userlist_deny=NO
userlist_enable=YES
userlist_file=/etc/vsftpd.allowed_users
In the file /etc/vsftpd.allowed_users add the username of the users that can login. One username per line.

TLS/SSL/FTPS
Add these code at the end of file.
ssl_enable=YES
allow_anon_ssl=NO
force_local_data_ssl=YES
force_local_logins_ssl=YES
ssl_tlsv1=YES
ssl_sslv2=YES
ssl_sslv3=YES
Additional Options
# Show hidden files and the "." and ".." folders.
# Useful to not write over hidden files:
force_dot_files=YES

# Hide the info about the owner (user and group) of the files.
hide_ids=YES

# Connection limit for each IP:
max_per_ip=3

# Maximum number of clients:
max_clients=5
Then, have it applied new configuration.
$sudo /etc/init.d/vsftpd restart 
That's all the configurations I've applied to my ftp server.
If you need more option, please kindly visit this site which can provides you for further information.
Ubuntu Forum 


Credits : epimeteo from Ubuntu Forum. Thx :)

Sunday, September 26, 2010

Ubuntu-Server GUI

Don't forget to update&upgrade your ubuntu-server!
# apt-get update
# apt-get upgrade
# apt-get dist-upgrade
I only want GUI to run in my ubuntu-server coz I want to use firefox to browsing website.
# apt-get install update-manager gnome-core xorg firefox