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