您现在的位置是:首页 > 文章详情

Hadoop单词统计

日期:2018-07-28点击:521

1. 本地创建文本文件

[root@s166 fantj]# mkdir input
[root@s166 fantj]# cd input/
[root@s166 input]# echo "hello fantj" > file1.txt
[root@s166 input]# echo "hello hadoop" > file2.txt
[root@s166 input]# echo "hello mapreduce" > file3.txt
[root@s166 input]# ls
file1.txt  file2.txt  file3.txt

2. 将文件上传到hadoop

[root@s166 input]# hadoop fs -mkdir /wordcount
[root@s166 input]# hadoop fs -ls /
Found 1 items
drwxr-xr-x   - root supergroup          0 2018-07-27 07:51 /wordcount
[root@s166 input]# cd ..
[root@s166 fantj]# ls
download  hadoop  input  jdk
[root@s166 fantj]# hadoop fs -put input/* /wordcount
[root@s166 fantj]# hadoop fs -ls /wordcount
Found 3 items
-rw-r--r--   3 root supergroup         12 2018-07-27 07:52 /wordcount/file1.txt
-rw-r--r--   3 root supergroup         13 2018-07-27 07:52 /wordcount/file2.txt
-rw-r--r--   3 root supergroup         16 2018-07-27 07:52 /wordcount/file3.txt

3. 启用hadoop自带单词统计进行处理

[root@s166 fantj]# cd /home/fantj/hadoop/share/hadoop/
[root@s166 hadoop]# ls
common  hdfs  httpfs  kms  mapreduce  tools  yarn
[root@s166 hadoop]# cd mapreduce/
[root@s166 mapreduce]# ls
hadoop-mapreduce-client-app-2.7.0.jar     hadoop-mapreduce-client-hs-plugins-2.7.0.jar       hadoop-mapreduce-examples-2.7.0.jar
hadoop-mapreduce-client-common-2.7.0.jar  hadoop-mapreduce-client-jobclient-2.7.0.jar        lib
hadoop-mapreduce-client-core-2.7.0.jar    hadoop-mapreduce-client-jobclient-2.7.0-tests.jar  lib-examples
hadoop-mapreduce-client-hs-2.7.0.jar      hadoop-mapreduce-client-shuffle-2.7.0.jar          sources
[root@s166 mapreduce]# hadoop jar hadoop-mapreduce-examples-2.7.0.jar wordcount /wordcount /print

查看结果

[root@s166 mapreduce]# hadoop fs -ls /print
Found 2 items
-rw-r--r--   3 root supergroup          0 2018-07-27 07:55 /print/_SUCCESS
-rw-r--r--   3 root supergroup         37 2018-07-27 07:55 /print/part-r-00000
[root@s166 mapreduce]# hadoop fs -cat /print/part-r-00000
fantj   1
hadoop  1
hello   3
mapreduce   1
原文链接:https://yq.aliyun.com/articles/650211
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章