How to Create a Cluster (LinuxOS) - Easy Steps to create Cluster

In my previous post of "How to Install CentOS in VMware Workstation", now I am going to write steps of "How to Create a Cluster in LinuxOS". The following are the easy steps to create a cluster but be-careful while typing commands because these are case-sensitive and also care about spaces between commands because they also matter.

Easy Steps to create Cluster


Now first make a check list of our steps as given below and we  start doing these steps...................

1: Linux Installation in Nodes
2: SSH equivalence establishment for user root
3: SSH hostkeys collection
4: Setup NTP service
5: Installation of PDSH
6: Setup NFS (Optional)
7: Creation of ordinary user, and also setup SSH equivalence for that
8: Installation of prerequisite packages (GCC, G77 etc)
9: Installation of MPI
10: Compiling Linpack (Optional)

You may also like ::: How to Install CentOS in VMware workstations



Step 1:            

Installation of Linux on all nodes

Step 2:            

Working on Master Node
Start with hosts file
Vi /etc/hosts

127.0.0.1                              localhost.localdomain localhost
10.0.0.20                              masternode
10.0.0.21                              node1
10.0.0.22                              node2

Copy Hosts file on node1 and node
For Node1
Scp /etc/hosts node1:/etc/
Are you sure you want to continue connecting (yes/no)? yes
Node1 Password will be required
For Node2
Scp /etc/hosts node2:/etc/
Are you sure you want to continue connecting (yes/no)? yes
Node2 Password will be required

Step 3:            

Key Generation Process
ssh-keygen –t dsa
Just press enter on all steps
ssh-keygen –t rsa
Just press enter on all steps
Go on the directory and verify the generated keys files
cd .ssh/
ls –l
Following files has been generated:
id_dsa
id_dsa.pub
id_rsa
id_rsa.pub
known_hosts

Generate authorized_keys in ssh directory
cat *.pub >> authorized_keys

Copy these files on Node1 and Node2
cd ..
For Node1
scp –r .ssh node1:/root/
Node1 Password will be required
For Node2
scp –r .ssh node2:/root/
Node2 Password will be required

Generate Nodes ssh finger prints (Not need for mpiuser)
ssh-keyscan –t dsa masternode node1 node2 > /etc/ssh/ssh_known_hosts
ssh-keyscan –t rsa masternode node1 node2 >> /etc/ssh/ssh_known_hosts
Now you can view the generated file using
less /etc/ssh/ssh_know_hosts

Copy this file on Node1 and Node2, Note that will not ask for the password this time because the public key has already attached or certify on the other side.
scp /etc/ssh/ssh_known_hosts node1:/etc/ssh/
scp /etc/ssh/ssh_known_hosts node2:/etc/ssh/

Now test with login on the other nodes
ssh node1
Run the command on other nodes
ssh node1 uptime 

Step 4:            

Setup NTP service
vi /etc/ntp.conf
disabled the following lines:
#server 0.fedora.pool.ntp.org dynamic
#server 1.fedora.pool.ntp.org dynamic
#server 2.fedora.pool.ntp.org dynamic
enabled the following lines:
server   127.127.1.0                         # local clock
fudge    127.127.1.0         stratum 10
service ntpd restart
shutting down ntpd:                                                       [FAILED]
starting ntpd:                                                                     [OK]

ntpq –p –n

Step 5:            

Installation of PDSH (pdsh-2.18-1.src.rpm)
Recompile it
rpmbuild --rebuild pdsh-2.18-1.src.rpm
change directory
cd /usr/src/redhat/RPMS/i286/
rpm –ivh pdsh-*

vi /etc/machines
masternode
node1
node2

pdsh –a date
pdsh –a ntpq –p –n

Step 6:            

Setup NFS
vi /etc/exports
/cluster ^(rw,no_root_squasn,sync)

service nfs restart
chkconfig --level 35 nfs on
pdsh –a mkdir /cluster
service nfs restart

mount –t nfs masternode:/cluster /cluster/
df –hT

vi /etc/fstab
At the end of this file, add following line:
Masternode:/cluster                      /cluster nfs          defaults               0 0
               

Step 7:            

Creation of ordinary user, and also setup SSH equivalence for that
[group: mpigroup-600, user: mpiuser-600, member of mpigroup, /cluster/mpiuser]
groupadd –g 600 mpigroup
useradd –u 600 –g 600 –d /cluster/mpiuser mpiuser
perform above commands on all nodes

Step 8:            

Installation of prerequisite packages (GCC, G77 etc)
rpm –q gcc
rpm –qa | grep g77
yum list | grep g77
yum –y install compat-gcc-34-g77
pdsh –w node1, node2 yum –y install compat-gcc-34-g77

Step 9:            

Installation of MPI
su – mpiuser
generate ssh keys repeat step-3

Download MPI from (http://www.mcs.anl.gov/research/projects/mpich2/downloads)
Mpich2-1.0.8.tar.gz and copy on cluster directory

Goto on root user and execute the following commands:
chown mpiuser:mpigroup /cluster –R

goto cluster directory using mpiuser
Unzip the following mpi file
tar xzf mpich2-1.0.8.tar.gz
cd mpich2-1.0.8
./configure --prefix=/cluster/mpich2
make
make install

setup some environment variables
Goto Home Directory
cd
vi .bash_profile

PATH=$PATH:$HOME/bin:/cluster/mpich2/bin
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/cluster/mpich2/lib
export PATH
export LD_LIBRARY_PATH

source .bash_profile
echo $PATH

which mpd
which mpiexec
which mpirun

cat >> /cluster/mpiuser/mpd.hosts << EOF
> masternode
> node1
> node2

vi /cluster/mpiuser/mpd.hosts
remove the masternode and save it

vi /cluster/mpiuser/.mpd.conf
secretword=redhat

mpd &

chmod 0600 /cluster/mpiuser/.mpd.conf

ps aux | grep mpd

mpd &

mpdtrace
mpdtrace –l
mpdallexit
mpdboot –n 2 –chkuponly

mpdboot –n 2
mpdtrace

For checking that your cluster is successfully created run the following example

cd /cluster/mpich2-1.0.8/examples

mpiexec –n 3 ./cpi

how to compile the program of MPI

mpicc –o icpi icpi.c

Now we have successfully created the cluster on CentOS which we have installed in VMware. Now you are able to perform your codes in virtual machines.
I hope you have gained much from this post. Give us feedback and keep visiting Cool Stack.

0 comments:

Post a Comment