| 1 | [[PageOutline]] |
| 2 | |
| 3 | ◢ <[wiki:III140614/Lab7 實作七]> | <[wiki:III140614 回課程大綱]> ▲ | <[wiki:III140614/Lab9 實作九]> ◣ |
| 4 | |
| 5 | = 實作八 Lab 8 = |
| 6 | |
| 7 | {{{ |
| 8 | #!html |
| 9 | <div style="text-align: center;"><big style="font-weight: bold;"><big>在完全分散模式下編譯 MapReduce 程式<br/>Compiling Hadoop MapReduce Java Program in Hadoop Cluster</big></big></div> |
| 10 | }}} |
| 11 | |
| 12 | {{{ |
| 13 | #!text |
| 14 | 以下練習,請連線至 hadoop.3du.me 操作。底下的 userXX 等於您的用戶名稱。 |
| 15 | }}} |
| 16 | |
| 17 | = Practice 1 : Word Count (Basic) = |
| 18 | |
| 19 | * 上傳內容到 HDFS 內[[BR]]upload data to HDFS |
| 20 | {{{ |
| 21 | $ mkdir lab8_input |
| 22 | $ echo "I like NCTU Cloud Course." > lab8_input/input1 |
| 23 | $ echo "I like nctu Cloud Course, and we enjoy this course." > lab8_input/input2 |
| 24 | $ hadoop fs -put lab8_input lab8_input |
| 25 | $ hadoop fs -ls lab8_input |
| 26 | Found 2 items |
| 27 | -rw-r--r-- 2 hXXXX supergroup 26 2011-04-19 10:07 /user/hXXXX/lab8_input/input1 |
| 28 | -rw-r--r-- 2 hXXXX supergroup 52 2011-04-19 10:07 /user/hXXXX/lab8_input/input2 |
| 29 | }}} |
| 30 | |
| 31 | * 下載 [http://www.classcloud.org/hadoop4win/WordCount.java WordCount.java] 並存到家目錄;[[BR]]Download [http://www.classcloud.org/hadoop4win/WordCount.java WordCount.java] and save to your home directory |
| 32 | {{{ |
| 33 | ~$ wget http://www.classcloud.org/hadoop4win/WordCount.java |
| 34 | }}} |
| 35 | |
| 36 | * 運作程式[[BR]]Compile WordCount.java and run it by '''hadoop jar''' command |
| 37 | |
| 38 | {{{ |
| 39 | $ mkdir MyJava |
| 40 | $ ln -s /opt/hadoop/hadoop-*-core.jar hadoop-core.jar |
| 41 | $ javac -classpath hadoop-core.jar -d MyJava WordCount.java |
| 42 | $ jar -cvf wordcount.jar -C MyJava . |
| 43 | $ hadoop jar wordcount.jar WordCount lab8_input/ lab8_out1/ |
| 44 | $ hadoop fs -cat lab8_out1/part-00000 |
| 45 | }}} |
| 46 | |
| 47 | * lab8_out1 執行結果 [[BR]]You should see results like this : |
| 48 | {{{ |
| 49 | #!text |
| 50 | Cloud 2 |
| 51 | Course, 1 |
| 52 | Course. 1 |
| 53 | I 2 |
| 54 | NCTU 1 |
| 55 | and 1 |
| 56 | course. 1 |
| 57 | enjoy 1 |
| 58 | like 2 |
| 59 | nctu 1 |
| 60 | this 1 |
| 61 | we 1 |
| 62 | }}} |
| 63 | ----- |