Saturday, May 23, 2009

Configure SSH to connect without entering password

This blog post is not about hacking into another's machine without the proper authorization of the owner. If you are looking for that, this is not the right place.

This is about configuring the SSH without entering the password, but, with the proper authorisation of the machine owner :). In cluster computing quite often, it is required to do this. This article describes how to do it by using "DSA" encryption algorithm. It is quite possible to use "RSA" encryption too.

Say there are two machines called A and B. Now we are going to configure machine A to connect to machine B without entering the password of machine B.

Generate private and public keys for the machine A.
ssh-keygen -t dsa

The ssh-keygen command will ask you to enter a passphrase. In this case it should be empty in order to connect without entering a password to the machine B.

The above command will place the private key file (id_dsa) and the public key file (id_dsa.pub) in the ".ssh" directory in the home directory of your user account.
Then copy the public key of machine A to the ".ssh/authorized_keys" file resides in the home directory of the machine B.

Now, you can connect to the ssh server of machine B from machine A without entering a password/passphrase.
In a cluster environment, you have to configure ssh in such a way that it enables to connect each others' ssh servers.

NOTE: It is not recommended to leave a passphrase empty when creating the keys. But, for the situations like clusters who comunicates via ssh, passphrase should be kept empty.

Get MySQL Cluster data nodes started after an unexpected shutdown

This article relates to MySQL version 5.1 and NDB Cluster version 6.x

When you are new to the MySQL Cluster, quite frequently, you face to the the problem of getting the data nodes attached to the cluster. Although some data nodes are started using the ndbd command, the management console shows it as disconnected. You know that there cannot be any configuration problms/errors, because you have started the cluster successfully few hours ago or the previous attempt.
In this kind of situation, most of the time, the root cause of the problem is that the cluster was ended in a improper way, in the previous time. The simple solution is starting the data nodes with the --initial option.

ndbd --initial

Reference: MySQL documentation

Add multiple jars to classpath

In java (in UNIX like platform), it is not enough just to include the directory, in which the jar dependencies of your application reside, to the classpath. It is required to include path of each and every dependant jars to the classpath. If your application only depends on few jars this is not a problem. But, what if your application depends on several jars say 20, it will be an annoying task to add all the paths of jars to the classpath manually.
It is possible to use a simple shell script to accomplish the above mentioned task. The script can be customized to suit your application very easily.


export JAR_HOME=path to directory which includes jars

for f in $JAR_HOME/*.jar

do

JAR_CLASSPATH=$JAR_
CLASSPATH:$f
done

export JAR_CLASSPATH


#the next line will print the JAR_CLASSPATH to the shell.
echo the classpath $JAR_CLASSPATH


java -classpath $JAR_CLASSPATH Name of the programme

Say your jars are in several diferent folders, then you will have to use a for loop per each directory and finally concaternate to a single variable.