Hadoop2.8第一個案例 運行wordcount

1. 查看hadoop中MapReduce路徑

[root@master mapreduce]# pwd
/opt/hadoop/hadoop2.8/share/hadoop/mapreduce

2. 創建word.txt,生成數據文件

touch word.txt
echo "hello world" >> word.txt
echo "hello hadoop" >> word.txt
echo "hello hive" >> word.txt

3. 查看文件

[root@master mapreduce]# ls
hadoop-mapreduce-client-app-2.8.5.jar              hadoop-mapreduce-client-shuffle-2.8.5.jar
hadoop-mapreduce-client-common-2.8.5.jar           hadoop-mapreduce-examples-2.8.5.jar
hadoop-mapreduce-client-core-2.8.5.jar             jdiff
hadoop-mapreduce-client-hs-2.8.5.jar               lib
hadoop-mapreduce-client-hs-plugins-2.8.5.jar       lib-examples
hadoop-mapreduce-client-jobclient-2.8.5.jar        sources
hadoop-mapreduce-client-jobclient-2.8.5-tests.jar  word.txt

4. 創建HDFS目錄

hdfs dfs -mkdir /work/data/input

5. 將數據文件word.txt上傳到HDFS /work/data/input 目錄下

hdfs dfs -put ./word.txt /work/data/input

6. 以文本形式讀出文件

[root@master mapreduce]# hdfs dfs -text /work/data/input/word.txt
hello world
hello hadoop
hello hive

7. 運行wordcount例子

[root@master mapreduce]# hadoop jar hadoop-mapreduce-examples-2.8.5.jar wordcount /work/data/input /work/data/output

8. 查看結果

[root@master mapreduce]# hdfs dfs -ls /work/data/output
Found 2 items
-rw-r--r--   2 root supergroup          0 2019-03-01 19:36 /work/data/output/_SUCCESS
-rw-r--r--   2 root supergroup         32 2019-03-01 19:36 /work/data/output/part-r-00000

[root@master mapreduce]# hdfs dfs -text /work/data/output/part-r-00000
hadoop	1
hello	3
hive	1
world	1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章