Sunday, August 24, 2008

linux p2v: Migrating from one hardware to other

No matter how good the hardware is, eventually it dies. All my servers are dying one by one. Initially they have kernel panic sometimes then the frequency of kernel panics increase.
The challenge that I have always faced is how do I take all the applications running on server to another one? Reinstalling everything on a new machine is obviously not an option as I don't know what all is running and who is the current owner of which application.
So now I have started making VM of a server when it shows signs of old age. The usual p2v stuff did not help me much. Eventually I am able to do create the VM. Here is how to do it, for an experienced admin.
1) Install bare minimum OS on the new server. Preferably same version (major/minor etc). If you can not get the same version then get next up version from the same distribution (debian,fedora etc).
2) Boot the machine with a live cd (knoppix is my favorite) and delete everything except /boot and /lib/modules/ directory from the hard disk of the new machine.
3) Now tar these two directories and put st some secure place.
4) Boot the original machine also using a live cd and copy all the files using tar command itself. Execute the command like this:
tar -C -czvf - ./ | ssh root@new_mcahine tar -C -xzvf -
5) Now restore the the previously stores /boot and /lib/modules form secure place to new machine (using the live cd booted environment itself)
6) Edit the /etc/fstab to have correct entries.
7) Boot with a grub floppy and use setup command to setup grub.
8) Now reboot and if needed do the repair.

These instructions are useful to someone who knows what they are doing so may not be useful to linux novices. let me know if you have questions thru the comments here and my be I can help.

if you have lvm on the original machine, it becomes very difficult and you may have to edit the initrd image to make sure that lvm and hdd drivers are part of the initrd image.

Copying huge files to/from remote servers.

If you want to copy huge file (in Gigabytes) to remote servers you can not afford to let the connection break. But it happens all the time specially when you are using vpn.

If you have ssh access to the remote machine then you can use rsync over ssh channel to copy files. This approach is better than using scp because rsync has "resume" feature that restarts the copying from where is was aborted.
The syntax is like this:
If you want to copy from local machine to remote machine:
rsync -av -e ssh source_path username@remotemachine:/destination_path

If you want to copy from remote machine to local machine:
rsync -av -e ssh username@remotemachine:/source_path destination_path
(Please note that the above written commands are all on one line)

Tuesday, August 19, 2008

Weird glassfish error

I was experimenting with Glassfish today and encountered this error:
[#|2008-08-20T01:59:37.128+0000|SEVERE|sun-appserver9.1|javax.enterprise.system.core|_ThreadID=11;_ThreadName=main;_RequestID=8db54f8d-759a-446b-96d2-1c8856d01776;|CORE5071: An error occured during initialization
com.sun.appserv.server.ServerLifecycleException: Cannot bind to URL [rmi://0.0.232.95:5586/management/rmi-jmx-connector]: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: Exception creating connection to: 0.0.232.95; nested exception is:
java.net.SocketException: Invalid argument or cannot assign requested address]|#]

Look at the server name: 0.0.232.95
That was strange. Upon investigation it turned out that my server name is 59487. This kind of numerical host names are typically assigned to the servers in hosted environments. If you write this number in hex then it becomes: E85F
Now somehow it gets converted in a 4 byte number and then that number is treated as an IP address. So here is what happens:
E85F--> 0000E85F---> 00.00.E8.5F --> 00.00.232.95

Mystery solved.