Changes between Initial Version and Version 1 of NTUT160625/Lab8


Ignore:
Timestamp:
Jun 25, 2016, 5:07:10 PM (8 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NTUT160625/Lab8

    v1 v1  
     1[[PageOutline]]
     2
     3◢ <[wiki:NTUT160625/Lab7 實作七]> | <[wiki:NTUT160625 回課程大綱]> ▲ | <[wiki:NTUT160625/Lab9 實作九]> ◣
     4
     5{{{
     6#!text
     7以下練習,請連線至 hdp01.3du.me 操作。底下的 userXX 等於您的用戶名稱。
     8以下練習,請連線至 hdp02.3du.me 操作。底下的 userXX 等於您的用戶名稱。
     9以下練習,請連線至 hdp03.3du.me 操作。底下的 userXX 等於您的用戶名稱。
     10以下練習,請連線至 hdp04.3du.me 操作。底下的 userXX 等於您的用戶名稱。
     11}}}
     12
     13= 實作八 Lab 8 =
     14
     15{{{
     16#!html
     17<div style="text-align: center;"><big style="font-weight: bold;"><big>HDFS、MapReduce 與 Hadoop Streaming 觀念驗證<br/>Running Hadoop Streaming with HDFS and MapReduce</big></big></div>
     18}}}
     19
     20== 準備輸入資料集 Input Dataset ==
     21
     22 * 首先準備輸入,包含兩部份:(1) 供 Velvet 計算的 *.fa 檔案,這裡為了方便示範起見,採用 test_long.fa 當範本,並複製 99 份不同檔名,當輸入 (2) 供 Mapper 運算的輸入檔案(內含 HDFS 的檔名路徑)
     23{{{
     24~$ echo "test" > test_long.fa
     25~$ for ((i=1;i<100;i++)); do hadoop fs -put test_long.fa input-$i.fa; done
     26~$ for ((i=1;i<20;i++)); do echo /user/$(whoami)/input-$i.fa; done > split-01.txt
     27~$ for ((i=20;i<40;i++)); do echo /user/$(whoami)/input-$i.fa; done > split-02.txt
     28~$ for ((i=40;i<60;i++)); do echo /user/$(whoami)/input-$i.fa; done > split-03.txt
     29~$ for ((i=60;i<80;i++)); do echo /user/$(whoami)/input-$i.fa; done > split-04.txt
     30~$ for ((i=80;i<100;i++)); do echo /user/$(whoami)/input-$i.fa; done > split-05.txt
     31~$ hadoop fs -mkdir lab10_input
     32~$ hadoop fs -put split-0* lab10_input
     33}}}
     34 * 檢查輸入檔案
     35{{{
     36~$ hadoop fs -ls
     37~$ hadoop fs -ls lab10_input
     38}}}
     39
     40== 觀察 Hadoop Streaming 執行身份與工作目錄 ==
     41
     42 * 撰寫 testmapper.sh
     43{{{
     44#!sh
     45#!/bin/bash
     46
     47id="h998"
     48mkdir -p /tmp/$id
     49host=`hostname`
     50pwd=`pwd`
     51uid=`whoami`
     52
     53while read line; do
     54  input=$line
     55  filename=`basename $input`
     56  echo "$uid@$host:$pwd> hadoop fs -get $input /tmp/$id/$filename"
     57  echo "$uid@$host:$pwd> velveth output-$filename 17 -fasta -short /tmp/$id/$filename"
     58  echo "$uid@$host:$pwd> hadoop fs -put output-$filename ."
     59done
     60rm -rf /tmp/$id
     61}}}
     62 * 接著,讓我們在本地端先驗證一下 testmapper.sh 的運作
     63{{{
     64~$ head -n 2 split-01.txt > split-00.txt
     65~$ cat > testmapper.sh << EOF
     66#!/bin/bash
     67
     68id="`whoami`"
     69mkdir -p /tmp/\$id
     70host=\`hostname\`
     71pwd=\`pwd\`
     72uid=\`whoami\`
     73
     74while read line; do
     75  input=\$line
     76  filename=\`basename \$input\`
     77  echo "\$uid@\$host:\$pwd> hadoop fs -get \$input /tmp/\$id/\$filename"
     78  echo "\$uid@\$host:\$pwd> velveth output-\$filename 17 -fasta -short /tmp/\$id/\$filename"
     79  echo "\$uid@\$host:\$pwd> hadoop fs -put output-\$filename ."
     80done
     81rm -rf /tmp/\$id
     82EOF
     83~$ chmod a+x testmapper.sh
     84~$ cat split-00.txt | ./testmapper.sh
     85user00@hdp01.3du.me:/home/user00> hadoop fs -get /user/user00/input-1.fa /tmp/user00/input-1.fa
     86user00@hdp01.3du.me:/home/user00> velveth output-input-1.fa 17 -fasta -short /tmp/user00/input-1.fa
     87user00@hdp01.3du.me:/home/user00> hadoop fs -put output-input-1.fa .
     88user00@hdp01.3du.me:/home/user00> hadoop fs -get /user/user00/input-2.fa /tmp/user00/input-2.fa
     89user00@hdp01.3du.me:/home/user00> velveth output-input-2.fa 17 -fasta -short /tmp/user00/input-2.fa
     90user00@hdp01.3du.me:/home/user00> hadoop fs -put output-input-2.fa .
     91}}}
     92 * 讓我們用 Hadoop Streaming 的方式來執行 testmapper.sh
     93{{{
     94~$ hadoop jar hadoop-streaming.jar -input lab10_input -output lab10_out1 -mapper testmapper.sh -file testmapper.sh -numReduceTasks 0
     95}}}
     96 * 觀察 lab10_out1 的結果,看與本機執行有何不同呢?
     97{{{
     98~$ hadoop fs -cat /user/$(whoami)/lab10_out1/part-00000 | head
     99root@hdp05.3du.me:/opt/hadoop/var/hadoop-root/mapred/local/taskTracker/user00/jobcache/job_201411281523_0038/attempt_201411281523_0038_m_000000_0/work> hadoop fs -get /user/user00/input-20.fa /tmp/user00/input-20.fa
     100root@hdp05.3du.me:/opt/hadoop/var/hadoop-root/mapred/local/taskTracker/user00/jobcache/job_201411281523_0038/attempt_201411281523_0038_m_000000_0/work> velveth output-input-20.fa 17 -fasta -short /tmp/user00/input-20.fa
     101root@hdp05.3du.me:/opt/hadoop/var/hadoop-root/mapred/local/taskTracker/user00/jobcache/job_201411281523_0038/attempt_201411281523_0038_m_000000_0/work> hadoop fs -put output-input-20.fa .
     102root@hdp05.3du.me:/opt/hadoop/var/hadoop-root/mapred/local/taskTracker/user00/jobcache/job_201411281523_0038/attempt_201411281523_0038_m_000000_0/work> hadoop fs -get /user/user00/input-21.fa /tmp/user00/input-21.fa
     103root@hdp05.3du.me:/opt/hadoop/var/hadoop-root/mapred/local/taskTracker/user00/jobcache/job_201411281523_0038/attempt_201411281523_0038_m_000000_0/work> velveth output-input-21.fa 17 -fasta -short /tmp/user00/input-21.fa
     104root@hdp05.3du.me:/opt/hadoop/var/hadoop-root/mapred/local/taskTracker/user00/jobcache/job_201411281523_0038/attempt_201411281523_0038_m_000000_0/work> hadoop fs -put output-input-21.fa .
     105root@hdp05.3du.me:/opt/hadoop/var/hadoop-root/mapred/local/taskTracker/user00/jobcache/job_201411281523_0038/attempt_201411281523_0038_m_000000_0/work> hadoop fs -get /user/user00/input-22.fa /tmp/user00/input-22.fa
     106root@hdp05.3du.me:/opt/hadoop/var/hadoop-root/mapred/local/taskTracker/user00/jobcache/job_201411281523_0038/attempt_201411281523_0038_m_000000_0/work> velveth output-input-22.fa 17 -fasta -short /tmp/user00/input-22.fa
     107root@hdp05.3du.me:/opt/hadoop/var/hadoop-root/mapred/local/taskTracker/user00/jobcache/job_201411281523_0038/attempt_201411281523_0038_m_000000_0/work> hadoop fs -put output-input-22.fa .
     108}}}
     109
     110== 實作透過 Hadoop Streaming 執行 99 組 velvet 運算 ==
     111
     112 * 撰寫 mapper.sh
     113{{{
     114#!sh
     115#!/bin/bash
     116
     117id="h998"
     118mkdir -p /tmp/$id
     119host=`hostname`
     120pwd=`pwd`
     121uid=`whoami`
     122
     123while read line; do
     124  input=$line
     125  filename=`basename $input`
     126  echo "$uid@$host> hadoop fs -get $input /tmp/$id/$filename"
     127  hadoop fs -get $input /tmp/$id/$filename
     128  echo "$uid@$host> velveth output-$filename 17 -fasta -short /tmp/$id/$filename"
     129  velveth output-$filename 17 -fasta -short /tmp/$id/$filename
     130  echo "$uid@$host> hadoop fs -put output-$filename /user/$id/."
     131  hadoop fs -put output-$filename /user/$id/.
     132  hadoop fs -chown $id /user/$id/output-$filename
     133done
     134rm -rf /tmp/$id
     135}}}
     136 * 於本機測試 mapper.sh
     137{{{
     138~$ cat > mapper.sh << EOF
     139#!/bin/bash
     140
     141id="`whoami`"
     142mkdir -p /tmp/\$id
     143host=\`hostname\`
     144pwd=\`pwd\`
     145uid=\`whoami\`
     146
     147while read line; do
     148  input=\$line
     149  filename=\`basename \$input\`
     150  echo "\$uid@\$host> hadoop fs -get \$input /tmp/\$id/\$filename"
     151  hadoop fs -get \$input /tmp/\$id/\$filename
     152  echo "\$uid@\$host> velveth output-\$filename 17 -fasta -short /tmp/\$id/\$filename"
     153  velveth output-\$filename 17 -fasta -short /tmp/\$id/\$filename
     154  echo "\$uid@\$host> hadoop fs -put output-\$filename /user/\$id/."
     155  hadoop fs -put output-\$filename /user/\$id/.
     156  hadoop fs -chown \$id /user/\$id/output-\$filename
     157done
     158rm -rf /tmp/\$id
     159EOF
     160~$ chmod a+x mapper.sh
     161~$ cat split-00.txt | ./mapper.sh
     162~$ hadoop fs -rmr output-*
     163~$ rm -rf output-sample-*
     164}}}
     165 * 接著用 hadoop streaming 來執行
     166{{{
     167~$ hadoop jar hadoop-streaming.jar -input lab10_input -output lab10_out2 -mapper mapper.sh -file mapper.sh -numReduceTasks 0
     168}}}