Friday, July 31, 2009

Creating a Fedora machine with MYSQL on Amazon

  1. Login to AWS console
  2. Start a machine with AMI:- ami-2547a34c
  3. Make sure required ports are open in the security group that you used
    • MYSQL:-3306
    • SSH:- 22
  4. After the server is up, login to the server using ssh
  5. Install the mysql server :-
     yum -y install mysql mysql-devel mysql-server
  6. start the server:-
    /etc/init.d/mysqld start
  7. By default, mysql doesn;'t provide any password for root. This is dangerous, so first thing you do is set a password:-
    mysqladmin -u root password 
  8. By default root has permissions to only login from localhost. So, give permission to root to login from anywhere:-
    mysql -u root -p

    grant all on *.* to root@'%'
That's it.. now you can login to MYSQL from your local machine using Toad or any other client

Maven and selenium

Good article on how to setup maven with selenium here

Thursday, July 23, 2009

How to get syntax highlighting in your blogs

Here I have to use this

Creating a Paid LINUX AMI

The Amazon documentation is here, but all examples don't work well. This blog is better. Most of the information below is reproduced from the above Blog. Here I am listing out all the things you need to do assuming you are creating an image from scratch

First you need the following
  • User name/password of your Amazon acct
  • Your account number. This is of the form of XXXX-XXXX-XXX. You can get it from the mail that Amazon sent you when you created the account or from your access identifiers page
  • AWS access key: Looks like this AKIAIJAEHQEJP1PCA4IL. You can get it from the mail that Amazon sent you when you created the account or from your access identifiers page
  • Secret key : Looks like this 5dgaxfawHIkan63XHAKDFJ3Jsdmfg9HAS. You can get it from the mail that Amazon sent you when you created the account or from your access identifiers page
  • AMI Id of the starter image that you want to create your image from
  • Dev pay product code. If you don;t have this, sing up for devpay using your amazon account. You will get a product code at the end
  1. Login to your access identifiers page
  2. If you haven't already, generate a new private key and certificate. Download this private key and certificate to your local machine. The private key will be named pk-XXXXXX.pem, The certificate is named cert-XXXXXX.pem. Protect these 2 files and do not share them publicly. These 2 files have private keys to your account. Also, if you are managing multiple Amazon accounts, make sure you don't mix the keys together
  3. Login to AWS console
  4. Create a key pair. Download the private key for the key pair into your local machine
  5. Start an instance using the starter AMI using the key pair that you just created
  6. SSH into this instance. (If you are using PUTTY, follow these instructions to create a ppk file)
  7. Create a directory named /mnt/bundle. We will create the image here. Also we will store your private keys here. It is important that the image be created in /mnt since by default /mnt is excluded from bundling. You don;t want your private keys to be bundled into the image
  8. copy the private key and certificate file to /mnt/bundle (If you are on windows use WinSCP)
  9. Bundle your image
    cd /mnt/bundle\
    ec2-bundle-vol -k pk-AAA...ZZZ.pem -c cert-AAA...ZZZ.pem -u -d /mnt/bundle/ -p

  10. Wait. This will take some time. It will create a file named .manifest.xml, along with files named .part.nn
  11. Login to S3 organizer
  12. Create a bucket
  13. Upload the image to the bucket
    ec2-upload-bundle -b  -m .manifest.xml -a  -s 

  14. Wait. The image will be copied over to the bucket
  15. Register this image as an AMI using the AWS console. At this point your image is bundled. But no one else except you can use it. Now you have to turn this into a paid AMI
  16. go back to SSH console. You might need to setup the following envioroment variables in order to run the following commands
    EC2_HOME
    JAVA_HOME

  17. Run the following command to associate your AMI with your devpay product
    ec2-modify-image-attribute --product-code -K pk-XXXX.pem -C cert-XXX.pem


Connecting to an Amazon instance through PUTTY

Here

Attaching and detaching a MYISAM datbase

Let's say you have a huge MYSQL database in one MYSQL instance. You want to make a copy of this database in another MYSQL instance. There are several ways you can do a copy
1) Export the database:- Use Mysqldump. Basically, this creates a huge SQL file that contains all the SQL statements for creating and populating data into the database. This way is good for creating empty starter databases, because you can easily change the schema by changing the SQL. A good tutorial is here
2) Just copy the database:- This works only for ISAM tables.
First a short background on how MYSQL stores data:- If you look into your MYSQL data folder, you will see that there is a folder for every database in the MYSQL instance. This folder has 3 files for every table in the database
  • frm table - I think this file contains the schema of the table
  • myd table - for an ISAM table, this file holds the data. A InnodDB table doesn;t have any data in this file. The data is stored in a seperate file outside of the folder
  • myi table - this file holds the indexes
Since, a database is just a collection of tables, you see these files for every table in the database. As long as all your tables are ISAM, everything that MYSQL needs to retreive data from the database is in this folder

So, this is how you detach and attach the database from one instance to another:- You just copy the folder that holds the database to the data folder of the instance you are attaching the database to. That's it! You don't even have to restart MYSQL.