hadoop自带的wordcount应用:
>1)本地文件hello.txt
 cat hello.txt
2)复制文件:
cp hello.txt hello2.txt
3)在远程创建d3文件夹
[email protected]:/usr/local/hadoop/share/hadoop/mapreduce$ hadoop fs -mkdir /user/hadoop/d3
4)分别将本地的hello.txt文件上传到远程hdfs
[email protected]:/usr/local/hadoop/share/hadoop/mapreduce$ hadoop fs -put hello.txt /user/hadoop/d3

[email protected]:/usr/local/hadoop/share/hadoop/mapreduce$ hadoop fs -put hello2.txt /user/hadoop/d3

5)执行任务,统计hadoop下d3文件夹下的文本文件单词
>hadoop jar hadoop-mapreduce-examples-2.8.0.jar wordcount /user/hadoop/d3 /user/hadoop/d3output
这个过程会有mapreduce执行的过程,输出很多info信息,时间从几十秒到几分钟,看统计任务的大小
   
6)查看输出文件夹,有Success文件表示成功
>hadoop fs -ls /user/hadoop/d3output
7)显示输出文件中内容结果:
>hadoop fs -cat /user/hadoop/d3output/part-r-00000

自定义的WordCount过程:

MapReduce基础-自定义WordCount过程MapReduce基础-自定义WordCount过程
MapReduce基础-自定义WordCount过程
MapReduce基础-自定义WordCount过程
运行完成后,将整个项目导出export成 jar file
(我导出的路径是本地的hadoop_file文件夹中的MyWordCount.jar)

在hadoop中的/user/hadoop/d3文件夹中放入了两个文档如下:
MapReduce基础-自定义WordCount过程
在导出的路径下执行:hadoop jar MyWordCount.jar MyWordCount 输入文件 输出文件
MapReduce基础-自定义WordCount过程
MapReduce基础-自定义WordCount过程
查看输出文件是否成功输出内容:
MapReduce基础-自定义WordCount过程
最后执行hadoop fs -cat /user/hadoop/output0502单词查看统计结果:
MapReduce基础-自定义WordCount过程
MapReduce基础-自定义WordCount过程

相关文章:

  • 2022-02-09
  • 2022-12-23
  • 2021-11-15
  • 2021-04-04
  • 2020-07-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-08
  • 2022-12-23
  • 2021-12-01
  • 2022-01-12
  • 2021-11-19
  • 2021-09-03
相关资源
相似解决方案