[[PageOutline]]
◢ <[wiki:III140322/Lab7 實作七]> | <[wiki:III140322 回課程大綱]> ▲ | <[wiki:III140322/Lab9 實作九]> ◣
= 實作八 Lab 8 =
{{{
#!html
在完全分散模式下編譯 MapReduce 程式
Compiling Hadoop MapReduce Java Program in Hadoop Cluster
}}}
{{{
#!text
以下練習,請連線至 hadoop.nchc.org.tw 操作。底下的 hXXXX 等於您的用戶名稱。
}}}
= Practice 1 : Word Count (Basic) =
* 上傳內容到 HDFS 內[[BR]]upload data to HDFS
{{{
$ mkdir lab8_input
$ echo "I like NCTU Cloud Course." > lab8_input/input1
$ echo "I like nctu Cloud Course, and we enjoy this course." > lab8_input/input2
$ hadoop fs -put lab8_input lab8_input
$ hadoop fs -ls lab8_input
Found 2 items
-rw-r--r-- 2 hXXXX supergroup 26 2011-04-19 10:07 /user/hXXXX/lab8_input/input1
-rw-r--r-- 2 hXXXX supergroup 52 2011-04-19 10:07 /user/hXXXX/lab8_input/input2
}}}
* 下載 [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
{{{
~$ wget http://www.classcloud.org/hadoop4win/WordCount.java
}}}
* 運作程式[[BR]]Compile WordCount.java and run it by '''hadoop jar''' command
{{{
$ mkdir MyJava
$ ln -s /opt/hadoop/hadoop-*-core.jar hadoop-core.jar
$ javac -classpath hadoop-core.jar -d MyJava WordCount.java
$ jar -cvf wordcount.jar -C MyJava .
$ hadoop jar wordcount.jar WordCount lab8_input/ lab8_out1/
$ hadoop fs -cat lab8_out1/part-00000
}}}
* lab8_out1 執行結果 [[BR]]You should see results like this :
{{{
#!text
Cloud 2
Course, 1
Course. 1
I 2
NCTU 1
and 1
course. 1
enjoy 1
like 2
nctu 1
this 1
we 1
}}}
-----