| 1 | {{{ |
| 2 | #!html |
| 3 | <div style="text-align: center;"><big |
| 4 | style="font-weight: bold;"><big><big>實做四: Hadoop 程式編譯</big></big></big></div> |
| 5 | }}} |
| 6 | [[PageOutline]] |
| 7 | |
| 8 | = 練習 0 : hello : 印出我們的 key value 為何 = |
| 9 | |
| 10 | |
| 11 | |
| 12 | * 下載 [http://trac.nchc.org.tw/cloud/raw-attachment/wiki/Hadoop_Lab4/nchc-example.jar nchc-example.jar] |
| 13 | {{{ |
| 14 | $ wget http://trac.nchc.org.tw/cloud/raw-attachment/wiki/Hadoop_Lab4/nchc-example.jar |
| 15 | }}} |
| 16 | |
| 17 | * 執行客製化的hadoop 程式 |
| 18 | |
| 19 | {{{ |
| 20 | $ bin/hadoop jar nchc-example.jar |
| 21 | }}} |
| 22 | * 輸出結果 |
| 23 | {{{ |
| 24 | ****************************************** |
| 25 | 歡迎使用 NCHC.Hadoop 的運算功能 |
| 26 | 指令: |
| 27 | Hadoop jar nchc-example-*.jar <功能> |
| 28 | 功能: |
| 29 | wordcount: 計算輸入資料夾內分別在每個檔案的字數統計 |
| 30 | mwc: 統合計算所有輸入檔的字數統計 |
| 31 | grep: 算出包指定字串的個數 |
| 32 | nchcgrep: 整合來源檔內的每個字與其所有出現的所在列 |
| 33 | hello: 印出內容並統計累進字數 |
| 34 | ****************************************** |
| 35 | |
| 36 | }}} |
| 37 | * 使用hello |
| 38 | {{{ |
| 39 | $ bin/hadoop jar nchc-example.jar hello |
| 40 | }}} |
| 41 | * 使用提示: |
| 42 | {{{ |
| 43 | hello <inDir> <outDir> <m> <r> |
| 44 | }}} |
| 45 | |
| 46 | * 範例: |
| 47 | |
| 48 | {{{ |
| 49 | $ bin/hadoop jar nchc-example.jar hello lab3_input lab4_out6 1 1 |
| 50 | }}} |
| 51 | |
| 52 | [wiki:Hadoop_Lab4_hello_018 hello 程式碼] |
| 53 | |
| 54 | = 練習 1 : Word Count 初級版 = |
| 55 | |
| 56 | * 上傳內容到hdfs內 |
| 57 | |
| 58 | {{{ |
| 59 | $ cd /opt/hadoop |
| 60 | $ mkdir lab4_input |
| 61 | $ echo "I like NCHC Cloud Course." > lab4_input/input1 |
| 62 | $ echo "I like nchc Cloud Course, and we enjoy this course." > lab4_input/input2 |
| 63 | $ bin/hadoop fs -put lab4_input lab4_input |
| 64 | $ bin/hadoop fs -ls lab4_input |
| 65 | }}} |
| 66 | |
| 67 | * 下載 [raw-attachment:wiki:jazz/Hadoop_Lab6:WordCount.java WordCount.java] 並存到/opt/hadoop; |
| 68 | {{{ |
| 69 | $ wget http://trac.nchc.org.tw/cloud/raw-attachment/wiki/jazz/Hadoop_Lab6/WordCount.java |
| 70 | }}} |
| 71 | |
| 72 | * 運作程式 |
| 73 | |
| 74 | {{{ |
| 75 | $ mkdir MyJava |
| 76 | $ javac -classpath hadoop-*-core.jar -d MyJava WordCount.java |
| 77 | $ jar -cvf wordcount.jar -C MyJava . |
| 78 | $ bin/hadoop jar wordcount.jar WordCount lab4_input/ lab4_out1/ |
| 79 | $ bin/hadoop fs -cat lab4_out1/part-00000 |
| 80 | }}} |
| 81 | |
| 82 | * lab4_out1 執行結果 |
| 83 | {{{ |
| 84 | #!text |
| 85 | Cloud 2 |
| 86 | Course, 1 |
| 87 | Course. 1 |
| 88 | I 2 |
| 89 | NCHC 1 |
| 90 | and 1 |
| 91 | course. 1 |
| 92 | enjoy 1 |
| 93 | like 2 |
| 94 | nchc 1 |
| 95 | this 1 |
| 96 | we 1 |
| 97 | }}} |
| 98 | ----- |
| 99 | |
| 100 | = 練習 2 : Word Count 進階版 = |
| 101 | |
| 102 | {{{ |
| 103 | $ echo "\." >pattern.txt && echo "\," >>pattern.txt |
| 104 | $ bin/hadoop fs -put pattern.txt ./ |
| 105 | $ mkdir MyJava2 |
| 106 | }}} |
| 107 | |
| 108 | |
| 109 | * 下載 [raw-attachment:wiki:jazz/Hadoop_Lab6:WordCount2.java WordCount2.java] 並存到/opt/hadoop; |
| 110 | {{{ |
| 111 | $ wget http://trac.nchc.org.tw/cloud/raw-attachment/wiki/jazz/Hadoop_Lab6/WordCount2.java |
| 112 | }}} |
| 113 | |
| 114 | {{{ |
| 115 | $ javac -classpath hadoop-*-core.jar -d MyJava2 WordCount2.java |
| 116 | $ jar -cvf wordcount2.jar -C MyJava2 . |
| 117 | $ bin/hadoop jar wordcount2.jar WordCount2 lab4_input lab4_out2 -skip pattern.txt |
| 118 | $ bin/hadoop fs -cat lab4_out2/part-00000 |
| 119 | }}} |
| 120 | |
| 121 | * lab4_out2 執行結果 |
| 122 | {{{ |
| 123 | #!text |
| 124 | Cloud 2 |
| 125 | Course 2 |
| 126 | I 2 |
| 127 | NCHC 1 |
| 128 | and 1 |
| 129 | course 1 |
| 130 | enjoy 1 |
| 131 | like 2 |
| 132 | nchc 1 |
| 133 | this 1 |
| 134 | we 1 |
| 135 | }}} |
| 136 | |
| 137 | {{{ |
| 138 | $ bin/hadoop jar wordcount2.jar WordCount2 -Dwordcount.case.sensitive=false lab4_input lab4_out3 -skip pattern.txt |
| 139 | $ bin/hadoop fs -cat lab4_out3/part-00000 |
| 140 | }}} |
| 141 | |
| 142 | * lab4_out3 執行結果 |
| 143 | {{{ |
| 144 | #!text |
| 145 | and 1 |
| 146 | cloud 2 |
| 147 | course 3 |
| 148 | enjoy 1 |
| 149 | i 2 |
| 150 | like 2 |
| 151 | nchc 2 |
| 152 | this 1 |
| 153 | we 1 |
| 154 | }}} |