#!/bin/bash
sudo rm /opt/hadoop -rf
sudo rm /opt/hadoop*.tar.gz
sudo rm -rf /var/hadoop
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""
cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
sudo apt-get purge java-gcj-compat
sudo apt-get install sun-java6-bin  sun-java6-jdk sun-java6-jre
cd /opt
sudo wget http://ftp.twaren.net/Unix/Web/apache/hadoop/core/hadoop-0.20.2/hadoop-0.20.2.tar.gz
sudo tar zxvf hadoop-0.20.2.tar.gz
sudo mv hadoop-0.20.2/ hadoop
sudo chown -R hadooper:hadooper /opt/hadoop
sudo mkdir -p /var/hadoop
sudo chown -R hadooper:hadooper /var/hadoop
cd hadoop
cat >> conf/hadoop-env.sh << EOF
export JAVA_HOME=/usr/lib/jvm/java-6-sun
export HADOOP_HOME=/opt/hadoop
export HADOOP_CONF_DIR=/opt/hadoop/conf
EOF
cat > conf/core-site.xml << EOF
<configuration>
  <property>
    <name>fs.default.name</name>
    <value>hdfs://localhost:9000</value>
  </property>
  <property>
    <name>hadoop.tmp.dir</name>
    <value>/var/hadoop/hadoop-\${user.name}</value>
  </property>
</configuration>
EOF
cat > conf/hdfs-site.xml  << EOF
<configuration>
  <property>
    <name>dfs.replication</name>
    <value>1</value>
  </property>
</configuration>
EOF
cat > conf/mapred-site.xml  << EOF
<configuration>
  <property>
    <name>mapred.job.tracker</name>
    <value>localhost:9001</value>
  </property>
</configuration>
EOF
bin/hadoop namenode -format
bin/start-all.sh
