NCHCCloudCourse100928: install-hadoop

File install-hadoop, 4.1 KB (added by jazz, 14 years ago)
Line 
1#!/bin/bash
2[ "`id -u`" != "0" ] && exec sudo su -c "$0" "$@"
3echo "---- [1] Installing Sun Java JDK 6 ........ ----"
4if [ ! -x /usr/bin/java ]; then
5  add-apt-repository "deb http://archive.canonical.com/ lucid partner"
6  apt-get update
7  cat << EOF | /usr/bin/debconf-set-selections
8sun-java6-bin   shared/accepted-sun-dlj-v1-1    select true
9sun-java6-jdk   shared/accepted-sun-dlj-v1-1    select true
10sun-java6-jre   shared/accepted-sun-dlj-v1-1    select true
11EOF
12  apt-get -y install sun-java6-jdk sun-java6-plugin
13fi
14
15echo "---- [2] Installing Hadoop 0.20.2 ........ ----"
16cd /opt
17{
18  if [ ! -x /opt/hadoop ]; then
19    wget http://ftp.twaren.net/Unix/Web/apache/hadoop/core/hadoop-0.20.2/hadoop-0.20.2.tar.gz
20    tar zxvf hadoop-0.20.2.tar.gz
21    rm -f hadoop-0.20.2.tar.gz
22    mv hadoop-0.20.2/ hadoop
23    chown -R hadoop:hadoop /opt/hadoop
24    if [ ! -x /var/hadoop ]; then
25      mkdir -p /var/hadoop
26      chown -R hadoop:hadoop /var/hadoop
27    fi
28  fi
29}
30
31if [ ! -x /opt/hadoop ]; then
32  echo "---- [ERROR] /opt/hadoop is not exist!! ----"; exit;
33else
34  echo "---- [3] Configure Hadoop NameNode and JobTracker .... ----"
35  cd /opt/hadoop
36  {
37    if [ ! -f /opt/hadoop/conf/hadoop-env.sh ]; then
38      echo "---- [ERROR] /opt/hadoop/conf/hadoop-env.sh is not exist!!  ----"; exit
39    else
40      if [ ! -f /opt/hadoop/conf/hadoop-env.sh.org ]; then
41        echo "---- [3.1] Updating /opt/hadoop/conf/hadoop-env.sh ....  ----"
42        cp /opt/hadoop/conf/hadoop-env.sh /opt/hadoop/conf/hadoop-env.sh.org
43        cat >> conf/hadoop-env.sh << EOF
44export JAVA_HOME=/usr/lib/jvm/java-6-sun
45export HADOOP_HOME=/opt/hadoop
46export HADOOP_CONF_DIR=/opt/hadoop/conf
47EOF
48      fi
49    fi
50
51    if [ ! -f /opt/hadoop/conf/core-site.xml ]; then
52      echo "---- [ERROR] /opt/hadoop/conf/core-site.xml is not exist!!  ----"; exit
53    else
54      if [ ! -f /opt/hadoop/conf/core-site.xml.org ]; then
55        echo "---- [3.2] Updating /opt/hadoop/conf/core-site.xml ....  ----"
56        cp /opt/hadoop/conf/core-site.xml /opt/hadoop/conf/core-site.xml.org
57        cat > conf/core-site.xml << EOF
58<?xml version="1.0"?>
59<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
60<configuration>
61  <property>
62    <name>fs.default.name</name>
63    <value>hdfs://localhost:9000</value>
64  </property>
65  <property>
66    <name>hadoop.tmp.dir</name>
67    <value>/var/hadoop/hadoop-\${user.name}</value>
68  </property>
69</configuration>
70EOF
71      fi
72    fi
73
74    if [ ! -f /opt/hadoop/conf/hdfs-site.xml ]; then
75      echo "---- [ERROR] /opt/hadoop/conf/hdfs-site.xml is not exist!!  ----"; exit
76    else
77      if [ ! -f /opt/hadoop/conf/hdfs-site.xml.org ]; then
78        echo "---- [3.3] Updating /opt/hadoop/conf/hdfs-site.xml ....  ----"
79        cp /opt/hadoop/conf/hdfs-site.xml /opt/hadoop/conf/hdfs-site.xml.org
80        cat > conf/hdfs-site.xml << EOF
81<?xml version="1.0"?>
82<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
83<configuration>
84  <property>
85    <name>dfs.replication</name>
86    <value>1</value>
87  </property>
88</configuration>
89EOF
90      fi
91    fi
92
93    if [ ! -f /opt/hadoop/conf/mapred-site.xml ]; then
94      echo "---- [ERROR] /opt/hadoop/conf/mapred-site.xml is not exist!!  ----"; exit
95    else
96      if [ ! -f /opt/hadoop/conf/mapred-site.xml.org ]; then
97        echo "---- [3.3] Updating /opt/hadoop/conf/mapred-site.xml ....  ----"
98        cp /opt/hadoop/conf/mapred-site.xml /opt/hadoop/conf/mapred-site.xml.org
99        cat > conf/mapred-site.xml << EOF
100<?xml version="1.0"?>
101<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
102<configuration>
103  <property>
104    <name>mapred.job.tracker</name>
105    <value>localhost:9001</value>
106  </property>
107</configuration>
108EOF
109      fi
110    fi
111
112    if [ ! -d /var/hadoop/hadoop-root/dfs/name ]; then
113      echo "---- [3.4] Formating NameNode ....  ----"
114      su - hadoop -c "/opt/hadoop/bin/hadoop namenode -format"
115      su - hadoop -c "/opt/hadoop/bin/hadoop-daemon.sh start namenode"
116      su - hadoop -c "/opt/hadoop/bin/hadoop-daemon.sh start datanode"
117      su - hadoop -c "/opt/hadoop/bin/hadoop-daemon.sh start jobtracker"
118      su - hadoop -c "/opt/hadoop/bin/hadoop-daemon.sh start tasktracker"
119    fi
120  }
121fi