| 1 | = 實做六: Hadoop 程式編譯 = |
| 2 | |
| 3 | == 啟動Hadoop環境 == |
| 4 | |
| 5 | * 重新啟動昨天的環境 |
| 6 | * 在 node1 上操作 |
| 7 | {{{ |
| 8 | $ cd /opt/hadoop |
| 9 | $ bin/hadoop start-dfs.sh |
| 10 | $ ssh node02 "bin/hadoop start-mapred.sh" |
| 11 | }}} |
| 12 | * 請檢查 hadoop 是否正確運作. |
| 13 | |
| 14 | == Example 1 : == |
| 15 | |
| 16 | * 上傳內容到hdfs內 |
| 17 | |
| 18 | {{{ |
| 19 | $ cd /opt/hadoop |
| 20 | $ bin/hadoop dfs -mkdir input |
| 21 | $ echo "I like NCHC Cloud Course." > input1 |
| 22 | $ echo "I like nchc Cloud Course, and we enjoy this course." > input2 |
| 23 | $ bin/hadoop dfs -put input1 input |
| 24 | $ bin/hadoop dfs -put input2 input |
| 25 | $ bin/hadoop dfs -ls input |
| 26 | }}} |
| 27 | |
| 28 | * 點此連結 [attachment:wiki:jazz/Hadoop_Lab6:WordCount.java?format=raw WordCount.java] 並將他存到 /opt/hadoop |
| 29 | |
| 30 | * 運作程式 |
| 31 | |
| 32 | {{{ |
| 33 | $ mkdir MyJava |
| 34 | $ javac -classpath hadoop-*-core.jar -d MyJava WordCount.java |
| 35 | $ jar -cvf wordcount.jar -C MyJava . |
| 36 | $ bin/hadoop jar wordcount.jar WordCount input/ output/ |
| 37 | $ bin/hadoop dfs -cat output/part-00000 |
| 38 | }}} |
| 39 | |
| 40 | ----- |
| 41 | |
| 42 | == Example 2 : == |
| 43 | |
| 44 | {{{ |
| 45 | $ echo "\." >pattern.txt && echo "\," >>pattern.txt |
| 46 | $ bin/hadoop dfs -put pattern.txt ./ |
| 47 | $ mkdir MyJava2 |
| 48 | }}} |
| 49 | |
| 50 | * 點此連結 [attachment:wiki:jazz/Hadoop_Lab6:WordCount2.java?format=raw WordCount2.java] 並將他存到 /opt/hadoop |
| 51 | |
| 52 | {{{ |
| 53 | $ javac -classpath hadoop-*-core.jar -d MyJava2 WordCount2.java |
| 54 | $ jar -cvf wordcount2.jar -C MyJava2 . |
| 55 | $ bin/hadoop jar wordcount2.jar WordCount2 input output2 -skip pattern.txt |
| 56 | $ bin/hadoop dfs -cat output2/part-00000 |
| 57 | $ bin/hadoop jar wordcount2.jar WordCount2 -Dwordcount.case.sensitive=false input output3 -skip pattern.txt |
| 58 | $ bin/hadoop dfs -cat output3/part-00000 |
| 59 | }}} |