hadoop 自带的WordCount实例可以统计一批文本文件中各单词出现的次数。
下面介绍如何执行WordCount实例。

1.启动hadoop

[root@hadoop ~]# start-all.sh #启动hadoop

2.在本地新建目录及2个文件

[root@hadoop ~]# mkdir input
[root@hadoop ~]# cd input/
[root@hadoop input]# echo "hello world">test1.txt #新建2个测试文件
[root@hadoop input]# echo "hello hadoop">test2.txt

3.将本地文件系统上的input目录复制到HDFS根目录下,重命名为in

[root@hadoop ~]# hdfs dfs -put input/ /in
[root@hadoop ~]# hdfs dfs -ls / #查看根目录
Found 1 items
drwxr-xr-x - root supergroup 0 2018-07-20 03:06 /in
[root@hadoop ~]# hdfs dfs -ls /in #查看in根目录
Found 2 items
-rw-r--r-- 1 root supergroup 12 2018-07-20 03:06 /in/test1.txt
-rw-r--r-- 1 root supergroup 13 2018-07-20 03:06 /in/test2.txt

4.执行以下命令

[root@hadoop ~]# cd /usr/local/hadoop/share/hadoop/mapreduce/ #示例jar包在此目录中存放
[root@hadoop mapreduce]# hadoop jar hadoop-mapreduce-examples-2.7.7.jar wordcount /in /out #out为输出目录,执行命令之前必须为空或者不存在否则报错
[root@hadoop ~]# cd /usr/local/hadoop/share/hadoop/mapreduce/ #示例jar包在此目录中存放
[root@hadoop mapreduce]# hadoop jar hadoop-mapreduce-examples-2.7.7.jar wordcount /in /out
18/07/30 14:02:11 INFO client.RMProxy: Connecting to ResourceManager at hadoop/192.168.42.133:8032
18/07/30 14:02:13 INFO input.FileInputFormat: Total input paths to process : 2
18/07/30 14:02:13 INFO mapreduce.JobSubmitter: number of splits:2
18/07/30 14:02:14 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1532913019648_0002
18/07/30 14:02:14 INFO impl.YarnClientImpl: Submitted application application_1532913019648_0002
18/07/30 14:02:14 INFO mapreduce.Job: The url to track the job: http://hadoop:8088/proxy/application_1532913019648_0002/
18/07/30 14:02:14 INFO mapreduce.Job: Running job: job_1532913019648_0002
18/07/30 14:02:36 INFO mapreduce.Job: Job job_1532913019648_0002 running in uber mode : false
18/07/30 14:02:36 INFO mapreduce.Job: map 0% reduce 0%
18/07/30 14:04:37 INFO mapreduce.Job: map 67% reduce 0%
18/07/30 14:04:42 INFO mapreduce.Job: map 100% reduce 0%
18/07/30 14:05:21 INFO mapreduce.Job: map 100% reduce 100%
18/07/30 14:05:23 INFO mapreduce.Job: Job job_1532913019648_0002 completed successfully
18/07/30 14:05:26 INFO mapreduce.Job: Counters: 49
File System Counters
FILE: Number of bytes read=55
FILE: Number of bytes written=368074
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=217
HDFS: Number of bytes written=25
HDFS: Number of read operations=9
HDFS: Number of large read operations=0
HDFS: Number of write operations=2
Job Counters
Launched map tasks=2
Launched reduce tasks=1
Data-local map tasks=2
Total time spent by all maps in occupied slots (ms)=259093
Total time spent by all reduces in occupied slots (ms)=21736
Total time spent by all map tasks (ms)=259093
Total time spent by all reduce tasks (ms)=21736
Total vcore-milliseconds taken by all map tasks=259093
Total vcore-milliseconds taken by all reduce tasks=21736
Total megabyte-milliseconds taken by all map tasks=265311232
Total megabyte-milliseconds taken by all reduce tasks=22257664
Map-Reduce Framework
Map input records=2
Map output records=4
Map output bytes=41
Map output materialized bytes=61
Input split bytes=192
Combine input records=4
Combine output records=4
Reduce input groups=3
Reduce shuffle bytes=61
Reduce input records=4
Reduce output records=3
Spilled Records=8
Shuffled Maps =2
Failed Shuffles=0
Merged Map outputs=2
GC time elapsed (ms)=847
CPU time spent (ms)=4390
Physical memory (bytes) snapshot=461631488
Virtual memory (bytes) snapshot=6226669568
Total committed heap usage (bytes)=277356544
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=25
File Output Format Counters
Bytes Written=25

执行命令时显示MapReduce过程

5.查看输出结果

1)直接查看HDFS上的输出文件

[root@hadoop mapreduce]# hdfs dfs -ls /out
Found 2 items
-rw-r--r-- 1 root supergroup 0 2018-07-30 14:05 /out/_SUCCESS
-rw-r--r-- 1 root supergroup 25 2018-07-30 14:05 /out/part-r-00000
[root@hadoop mapreduce]# hdfs dfs -cat /out/part-r-00000
hadoop 1
hello 2
world 1

2)也可以输入以下命令查看

[root@hadoop mapreduce]# hdfs dfs -cat /out/*
hadoop 1
hello 2
world 1

3)还可以把文件复制到本地查看

[root@hadoop mapreduce]# hdfs dfs -get /out /root/output
[root@hadoop mapreduce]# cd /root/output/
[root@hadoop output]# ll
总用量 4
-rw-r--r-- 1 root root 25 7月 30 17:18 part-r-00000
-rw-r--r-- 1 root root 0 7月 30 17:18 _SUCCESS
[root@hadoop output]# cat part-r-00000
hadoop 1
hello 2
world 1

执行hadoop自带的WordCount实例的更多相关文章

  1. hadoop自带例子wordcount的具体运行步骤

    1.在hadoop所在目录“usr/local”下创建一个文件夹input root@ubuntu:/usr/local# mkdir input 2.在文件夹input中创建两个文本文件file1. ...

  2. windows环境下跑hadoop自带的wordcount遇到的问题

    hadoop环境自己之前也接触过,搭建的是一个伪分布的环境,主从节点都在我自己的机子上,即127.0.0.1,当初记得步骤很多很麻烦的样子(可能自己用ubuntu还不够熟练),包括myeclipse. ...

  3. Hadoop(1)---运行Hadoop自带的wordcount出错问题。

    在hadoop2.9.0版本中,对namenode.yarn做了ha,随后在某一台namenode节点上运行自带的wordcount程序出现偶发性的错误(有时成功,有时失败),错误信息如下: // : ...

  4. linux下在eclipse上运行hadoop自带例子wordcount

    启动eclipse:打开windows->open perspective->other->map/reduce 可以看到map/reduce开发视图.设置Hadoop locati ...

  5. 在命令行中运行Hadoop自带的WordCount程序

    1.启动所有的线程服务 start-all.sh 记得要查看线程是否启动 jps 2.在根目录创建 wordcount.txt 文件 放置一些数据 3.创建  hdfs dfs -mkdir /文件夹 ...

  6. 运行hadoop自带的wordcount例子程序

    1.准备文件 [root@master ~]# cat input.txt hello java hello python hello c hello java hello js hello html ...

  7. Hadoop环境搭建及wordcount程序

    目的: 前期学习了一些机器学习基本算法,实际企业应用中算法是核心,运行的环境和数据处理的平台是基础. 手段: 搭建简易hadoop集群(由于机器限制在自己的笔记本上通过虚拟机搭建) 一.基础环境介绍 ...

  8. Hadoop最基本的wordcount(统计词频)

    package com.uniclick.dapa.dstest; import java.io.IOException; import java.net.URI; import org.apache ...

  9. Hadoop3 在eclipse中访问hadoop并运行WordCount实例

    前言:       毕业两年了,之前的工作一直没有接触过大数据的东西,对hadoop等比较陌生,所以最近开始学习了.对于我这样第一次学的人,过程还是充满了很多疑惑和不解的,不过我采取的策略是还是先让环 ...

随机推荐

  1. [IR] Advanced XML Compression - ISX

    Ori paper: http://www.cse.unsw.edu.au/~wong/papers/www07.pdf ISX Requirements 1 Space does matter fo ...

  2. 14桥接模式Bridge

    一.什么是桥接模式 Bridge 模式又叫做桥接模式,是构造型的设 计模式之一.Bridge模式基于类的最小设计原则,通过 使用封装,聚合以及继承等行为来让不同的类承担不同 的责任.它的主要特点是把抽 ...

  3. go语言内置基础类型

    1.数值型(Number) 三种:整数型.浮点型和虚数型(有符号整数表示整数范围 -2n-1~2n-1-1:无符号整数表示整数范围 0~2n-1) go内置整型有:uint8, uint16, uin ...

  4. zabbix参考文档

    http://www.zsythink.net/archives/category/%E8%BF%90%E7%BB%B4%E7%9B%B8%E5%85%B3/zabbix/

  5. [Python] Python 虚拟机 - virtualenv

    virtualenv virtualenv 用于创建一个隔离的 Python 环境. 每个项目都有自己的依赖包,这些依赖包有时存在版本冲突,处理这种情况最好方法就是为每个项目创建一个专属的环境. 安装 ...

  6. Flask web开发之路十二

    ge请求和post请求 ### get请求和post请求:1. get请求: * 使用场景:如果只对服务器获取数据,并没有对服务器产生任何影响,那么这时候使用get请求. * 传参:get请求传参是放 ...

  7. logback logback.xml常用配置详解(一)<configuration> and <logger>

    logback logback.xml常用配置详解(一)<configuration> and <logger> 博客分类: Log java loglogback  原创文章 ...

  8. python3.6利用pyinstaller模块打包程序为.exe可执行程序

    步骤: 1.安装pyinstaller模块:(必须在联网情况下进行) 操作原理: python3.6已经自带了pip,所以只需要在cmd中执行 pip install pyinstaller 就可以安 ...

  9. [No000012C]WPF(4/7)类型转换器和标记扩展[译]

    介绍 之前讨论了WPF的基础架构,然后逐步开始学习布局面板,转换,介绍了不同的控件,容器,UI转换等.在这篇文章中,我将讨论每个创建XAML应用前的开发人员应该了解的关于XAML最重要的东西. 标记扩 ...

  10. 【每日一题】UVA - 1368 DNA Consensus String 字符串+贪心+阅读题

    https://cn.vjudge.net/problem/UVA-1368 二维的hamming距离算法: For binary strings a and b the Hamming distan ...