wiki:jazz/Hadoop_Lab4

實做六: Hadoop 程式編譯

前言:啟動Hadoop環境

  • 重新啟動昨天的環境
    • 在 node1 上操作
      $ cd /opt/hadoop
      $ bin/hadoop start-dfs.sh
      $ ssh node02 "bin/hadoop start-mapred.sh"
      
    • 請檢查 hadoop 是否正確運作.

練習 1 : Word Count 初級版

  • 上傳內容到hdfs內
$ cd /opt/hadoop
$ bin/hadoop dfs -mkdir input
$ echo "I like NCHC Cloud Course." > input1
$ echo "I like nchc Cloud Course, and we enjoy this course." > input2
$ bin/hadoop dfs -put input1 input
$ bin/hadoop dfs -put input2 input
$ bin/hadoop dfs -ls input
  • 運作程式
$ mkdir MyJava
$ javac -classpath hadoop-*-core.jar -d MyJava WordCount.java
$ jar -cvf wordcount.jar -C MyJava .
$ bin/hadoop jar wordcount.jar WordCount input/ output/
$ bin/hadoop dfs -cat output/part-00000

練習 2 : Word Count 進階版

$ echo "\." >pattern.txt && echo "\," >>pattern.txt
$ bin/hadoop dfs -put pattern.txt ./
$ mkdir MyJava2
$ javac -classpath hadoop-*-core.jar -d MyJava2 WordCount2.java
$ jar -cvf wordcount2.jar -C MyJava2 .
$ bin/hadoop jar wordcount2.jar WordCount2 input output2 -skip pattern.txt
$ bin/hadoop dfs -cat output2/part-00000
$ bin/hadoop jar wordcount2.jar WordCount2 -Dwordcount.case.sensitive=false input output3 -skip pattern.txt
$ bin/hadoop dfs -cat output3/part-00000
Last modified 15 years ago Last modified on Sep 14, 2009, 1:21:20 AM