editing etc hosts files of a cluster

View: New views
2 Messages — Rating Filter:   Alert me  

editing etc hosts files of a cluster

by Ramesh.Ramasamy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have a cluster setup with 3 nodes, and I'm adding hostname details (in /etc/hosts) manually in each node. Seems it is not an effective approach. How this scenario is handled in big clusters?

Is there any simple of way to add the hostname details in all the nodes by editing a single entry/file/script?

Thanks and Regards,
Ramesh


Re: editing etc hosts files of a cluster

by Ramesh.Ramasamy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This following script does the work, but testing against /etc/hosts file instead of /home/hadoop/hosts/hosts fails, I'm getting permission denied error..

hadoop@master:sed$ cat applyhadoopcluster.sh
#!/bin/bash
for i in `cat clusternodes`
do
        # Remove the exiting entiries of Hadoop cluster, if any
        ssh hadoop@$i "sed '/#HADOOP_HOST_ENTRIES_STARTING/,/#HADOOP_HOST_ENTRIES_ENDING/d' /home/hadoop/hosts/hosts -i"

        # Insert the Hadoop cluster entries
        ssh hadoop@$i "sed '1i\#HADOOP_HOST_ENTRIES_STARTING' /home/hadoop/hosts/hosts -i"
        count=2
        while read j
        do
                #echo $j
                ssh -n hadoop@$i "sed '2i$j' /home/hadoop/hosts/hosts -i"
                count=`expr $count + 1`
                #echo $count
        done < clusterhostnames
        ssh hadoop@$i "sed ${count}i\#HADOOP_HOST_ENTRIES_ENDING /home/hadoop/hosts/hosts -i"
done

hadoop@master:sed$ cat clusterhostnames
172.25.149.37  master
172.25.149.38  slave2
172.25.149.66   slave1

hadoop@master:sed$ cat clusternodes
master
slave2
slave1