| 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 | = 練習 1 : Word Count 初級版 = |
| 9 | |
| 10 | * 上傳內容到hdfs內 |
| 11 | |
| 12 | {{{ |
| 13 | $ cd /opt/hadoop |
| 14 | $ mkdir lab4_input |
| 15 | $ echo "I like NCHC Cloud Course." > lab4_input/input1 |
| 16 | $ echo "I like nchc Cloud Course, and we enjoy this course." > lab4_input/input2 |
| 17 | $ bin/hadoop fs -put lab4_input lab4_input |
| 18 | $ bin/hadoop fs -ls lab4_input |
| 19 | }}} |
| 20 | |
| 21 | * 編輯 [wiki:waue/2010/0115-WordCountV1 wordcount.java] 並存到/opt/hadoop; |
| 22 | |
| 23 | |
| 24 | * 運作程式 |
| 25 | |
| 26 | {{{ |
| 27 | $ mkdir MyJava |
| 28 | $ javac -classpath hadoop-*-core.jar -d MyJava WordCount.java |
| 29 | $ jar -cvf wordcount.jar -C MyJava . |
| 30 | $ bin/hadoop jar wordcount.jar WordCount lab4_input/ lab4_out1/ |
| 31 | $ bin/hadoop fs -cat lab4_out1/part-00000 |
| 32 | }}} |
| 33 | |
| 34 | * lab4_out1 執行結果 |
| 35 | {{{ |
| 36 | #!text |
| 37 | Cloud 2 |
| 38 | Course, 1 |
| 39 | Course. 1 |
| 40 | I 2 |
| 41 | NCHC 1 |
| 42 | and 1 |
| 43 | course. 1 |
| 44 | enjoy 1 |
| 45 | like 2 |
| 46 | nchc 1 |
| 47 | this 1 |
| 48 | we 1 |
| 49 | }}} |
| 50 | ----- |