《LINUX實(shí)操:運(yùn)行Hadoop自帶的wordcount單詞統(tǒng)計(jì)程序》要點(diǎn):
本文介紹了LINUX實(shí)操:運(yùn)行Hadoop自帶的wordcount單詞統(tǒng)計(jì)程序,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
0.前言
? ? 前面一篇《Hadoop初體驗(yàn):快速搭建Hadoop偽分布式環(huán)境》搭建了一個(gè)Hadoop的環(huán)境,現(xiàn)在就使用Hadoop自帶的wordcount法式來做單詞統(tǒng)計(jì)的案例.
1.使用示例法式實(shí)現(xiàn)單詞統(tǒng)計(jì)
(1)wordcount法式
wordcount法式在hadoop的share目錄下,如下:
[root@linuxidc mapreduce]# pwd
/usr/local/hadoop/share/hadoop/mapreduce
[root@linuxidc mapreduce]# ls
hadoop-mapreduce-client-app-2.6.5.jar? ? ? ? hadoop-mapreduce-client-jobclient-2.6.5-tests.jar
hadoop-mapreduce-client-common-2.6.5.jar? ? ? hadoop-mapreduce-client-shuffle-2.6.5.jar
hadoop-mapreduce-client-core-2.6.5.jar? ? ? ? hadoop-mapreduce-examples-2.6.5.jar
hadoop-mapreduce-client-hs-2.6.5.jar? ? ? ? ? lib
hadoop-mapreduce-client-hs-plugins-2.6.5.jar? lib-examples
hadoop-mapreduce-client-jobclient-2.6.5.jar? sources
就是這個(gè)hadoop-mapreduce-examples-2.6.5.jar程序.
?
(2)創(chuàng)建HDFS數(shù)據(jù)目錄
? ? 創(chuàng)建一個(gè)目錄,用于保留MapReduce任務(wù)的輸入文件:
[root@linuxidc ~]# hadoop fs -mkdir -p /data/wordcount
? ? 創(chuàng)建一個(gè)目錄,用于保留MapReduce任務(wù)的輸出文件:
[root@linuxidc ~]# hadoop fs -mkdir /output
? ? 查看剛剛創(chuàng)立的兩個(gè)目錄:
[root@linuxidc ~]# hadoop fs -ls /
drwxr-xr-x? - root supergroup? ? ? ? ? 0 2017-09-01 20:34 /data
drwxr-xr-x? - root supergroup? ? ? ? ? 0 2017-09-01 20:35 /output
(3)創(chuàng)立一個(gè)單詞文件,并上傳到HDFS
? ? 創(chuàng)立的單詞文件如下:
?[root@linuxidc ~]# cat myword.txt?
linuxidc yyh
yyh xplinuxidc
katy ling
yeyonghao linuxidc
xpleaf katy
? ? 上傳該文件到HDFS中:
[root@linuxidc ~]# hadoop fs -put myword.txt /data/wordcount
? ? 在HDFS中查看方才上傳的文件及內(nèi)容:
[root@linuxidc ~]# hadoop fs -ls /data/wordcount
-rw-r--r--? 1 root supergroup? ? ? ? 57 2017-09-01 20:40 /data/wordcount/myword.txt
[root@linuxidc ~]# hadoop fs -cat /data/wordcount/myword.txt
linuxidc yyh
yyh xplinuxidc
katy ling
yeyonghao linuxidc
xpleaf katy
(4)運(yùn)行wordcount法式
? ? 執(zhí)行如下命令:
[root@linuxidc ~]# hadoop jar /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.5.jar wordcount /data/wordcount /output/wordcount
...
17/09/01 20:48:14 INFO mapreduce.Job: Job job_local1719603087_0001 completed successfully
17/09/01 20:48:14 INFO mapreduce.Job: Counters: 38
? ? ? ? File System Counters
? ? ? ? ? ? ? ? FILE: Number of bytes read=585940
? ? ? ? ? ? ? ? FILE: Number of bytes written=1099502
? ? ? ? ? ? ? ? FILE: Number of read operations=0
? ? ? ? ? ? ? ? FILE: Number of large read operations=0
? ? ? ? ? ? ? ? FILE: Number of write operations=0
? ? ? ? ? ? ? ? HDFS: Number of bytes read=114
? ? ? ? ? ? ? ? HDFS: Number of bytes written=48
? ? ? ? ? ? ? ? HDFS: Number of read operations=15
? ? ? ? ? ? ? ? HDFS: Number of large read operations=0
? ? ? ? ? ? ? ? HDFS: Number of write operations=4
? ? ? ? Map-Reduce Framework
? ? ? ? ? ? ? ? Map input records=5
? ? ? ? ? ? ? ? Map output records=10
? ? ? ? ? ? ? ? Map output bytes=97
? ? ? ? ? ? ? ? Map output materialized bytes=78
? ? ? ? ? ? ? ? Input split bytes=112
? ? ? ? ? ? ? ? Combine input records=10
? ? ? ? ? ? ? ? Combine output records=6
? ? ? ? ? ? ? ? Reduce input groups=6
? ? ? ? ? ? ? ? Reduce shuffle bytes=78
? ? ? ? ? ? ? ? Reduce input records=6
? ? ? ? ? ? ? ? Reduce output records=6
? ? ? ? ? ? ? ? Spilled Records=12
? ? ? ? ? ? ? ? Shuffled Maps =1
? ? ? ? ? ? ? ? Failed Shuffles=0
? ? ? ? ? ? ? ? Merged Map outputs=1
? ? ? ? ? ? ? ? GC time elapsed (ms)=92
? ? ? ? ? ? ? ? CPU time spent (ms)=0
? ? ? ? ? ? ? ? Physical memory (bytes) snapshot=0
? ? ? ? ? ? ? ? Virtual memory (bytes) snapshot=0
? ? ? ? ? ? ? ? Total committed heap usage (bytes)=241049600
? ? ? ? Shuffle Errors
? ? ? ? ? ? ? ? BAD_ID=0
? ? ? ? ? ? ? ? CONNECTION=0
? ? ? ? ? ? ? ? IO_ERROR=0
? ? ? ? ? ? ? ? WRONG_LENGTH=0
? ? ? ? ? ? ? ? WRONG_MAP=0
? ? ? ? ? ? ? ? WRONG_REDUCE=0
? ? ? ? File Input Format Counters?
? ? ? ? ? ? ? ? Bytes Read=57
? ? ? ? File Output Format Counters?
? ? ? ? ? ? ? ? Bytes Written=48
(5)查看統(tǒng)計(jì)成果
? ? 如下:
[root@linuxidc ~]# hadoop fs -cat /output/wordcount/part-r-00000
katy? ? 2
linuxidc? ? 2
ling? ? 1
xplinuxidc? 2
yeyonghao? ? ? 1
yyh? ? 2
更多Hadoop相關(guān)信息見Hadoop 專題頁面 /topicnews.aspx?tid=13
本文永遠(yuǎn)更新鏈接地址:
歡迎參與《LINUX實(shí)操:運(yùn)行Hadoop自帶的wordcount單詞統(tǒng)計(jì)程序》討論,分享您的想法,維易PHP學(xué)院為您提供專業(yè)教程。
轉(zhuǎn)載請(qǐng)注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/7693.html