forked from dharmeshkakadia/Hadoop-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hadoop_install.sh
102 lines (89 loc) · 3.12 KB
/
hadoop_install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
!/bin/bash
# Downloads and configures hadoop on cluster.
# To Do
# Install Dependdencies like java, ssh etc
# takes two arguments
# $1 is URL to download the hadoop tar
# $2 is properties file which gives the cluster parameters (see the example Properties file)
# Download and move hadoop
wget $1
tar xzf hadoop-*
rm hadoop-*.tar.gz
sudo rm -rf /usr/local/hadoop
sudo mv hadoop-* /usr/local/hadoop
#sudo chown -R hduser:hadoop /usr/local/hadoop
# configure
echo "-----------starting configuration-------------"
sudo rm -rf /app/hadoop/tmp
sudo mkdir -p /app/hadoop/tmp
cd /usr/local/hadoop/conf/
# actually not needed, used by start-all.sh and stop-all.sh
# master and slave files
grep -i jobtracker $2 | cut -f 2 | cut -d ":" -f 1 > masters
grep -i slave $2 | cut -f 2 > slaves
# change JAVA_HOME according to your environment
JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-amd64
echo "export JAVA_HOME=$JAVA_HOME" >> hadoop-env.sh
#core-site.xml
echo -e "<?xml version=\"1.0\"?>
<?xml-stylesheet type=\"text/xsl\" href=\"configuration.xsl\"?>
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/app/hadoop/tmp</value>
<description>A base for other temporary directories.</description>
</property>
<property>
<name>fs.default.name</name>
<value>hdfs://`grep -i namenode $2 | cut -f 2`</value>
<description>The name of the default file system. A URI whose
scheme and authority determine the FileSystem implementation. The
uri's scheme determines the config property (fs.SCHEME.impl) naming
the FileSystem implementation class. The uri's authority is used to
determine the host, port, etc. for a filesystem.</description>
</property>
</configuration>" > core-site.xml
echo -e "<?xml version=\"1.0\"?>
<?xml-stylesheet type=\"text/xsl\" href=\"configuration.xsl\"?>
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>`grep -i jobtracker $2 | cut -f 2`</value>
<description>The host and port that the MapReduce job tracker runs </description>
</property>
</configuration>" > mapred-site.xml
# hdfs-site.xml
echo -e "<?xml version=\"1.0\"?>
<?xml-stylesheet type=\"text/xsl\" href=\"configuration.xsl\"?>
<configuration>
<property>
<name>dfs.replication</name>
<value>2</value>
<description>Default block replication.
The actual number of replications can be specified when the file is created.
The default is used if replication is not specified in create time.
</description>
</property>
</configuration>" > hdfs-site.xml
# rsync to slaves
for srv in $(cat /usr/local/hadoop/conf/slaves); do
echo "Sending command to $srv...";
rsync -vaz --exclude='logs/*' /usr/local/hadoop $srv:/usr/local/
#ssh $srv "rm -fR /usr/local/$2 ; ln -s /usr/local/hadoop /usr/local/$"
done
# All the nodes in the cluster
servers="$(cat masters slaves)"
echo "-----------starting hadoop cluster-------------"
# format namenode
cd /usr/local/hadoop/bin/
./hadoop namenode -format
./start-dfs.sh
./start-mapred.sh
echo "-----------Verfing hadoop daemons-------------"
# verify
for srv in $servers; do
echo "Running jps on $srv.........";
# ssh $srv "ps aux | grep -v grep | grep java"
ssh $srv "jps"
done
echo "done!!!!!!"