紧接上篇,完成Hadoop的安装并跑起来之后,是该运行相关例子的时候了,而最简单最直接的例子就是HelloWorld式的WordCount例子。

 

参照博客进行运行:http://xiejianglei163.blog.163.com/blog/static/1247276201443152533684/

 

首先创建一个文件夹,并创建两个文件,目录随意,为以下文件结构:

examples

--file1.txt

--file2.txt

文件内容随意填写,我是从新闻copy下来的一段英文:

执行以下命令:

hadoop@ubuntu:/usr/local/gz/hadoop-2.4.1$ ./bin/hadoop fs -mkdir /data    #在hadoop中创建/data文件夹,该文件夹用来存放输入数据,这个文件不是Linux的根目录下的文件,而是hadoop下的文件夹
hadoop@ubuntu:/usr/local/gz/hadoop-2.4.1$ ./bin/hadoop fs -put -f ./data_input/* /data #将前面生成的两个 文件拷贝至/data下

 

执行WordCount命令,并查看结果:

hadoop@ubuntu:/usr/local/gz/hadoop-2.4.1$ ./bin/hadoop jar ./share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.4.1-sources.jar org.apache.hadoop.examples.WordCount /data /output
14/07/22 22:34:25 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
14/07/22 22:34:27 INFO client.RMProxy: Connecting to ResourceManager at /0.0.0.0:8032
14/07/22 22:34:29 INFO input.FileInputFormat: Total input paths to process : 2
14/07/22 22:34:29 INFO mapreduce.JobSubmitter: number of splits:2
14/07/22 22:34:30 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1406038146260_0001
14/07/22 22:34:32 INFO impl.YarnClientImpl: Submitted application application_1406038146260_0001
14/07/22 22:34:32 INFO mapreduce.Job: The url to track the job: http://ubuntu:8088/proxy/application_1406038146260_0001/
14/07/22 22:34:32 INFO mapreduce.Job: Running job: job_1406038146260_0001
14/07/22 22:34:58 INFO mapreduce.Job: Job job_1406038146260_0001 running in uber mode : false
14/07/22 22:34:58 INFO mapreduce.Job: map 0% reduce 0%
14/07/22 22:35:34 INFO mapreduce.Job: map 100% reduce 0%
14/07/22 22:35:52 INFO mapreduce.Job: map 100% reduce 100%
14/07/22 22:35:52 INFO mapreduce.Job: Job job_1406038146260_0001 completed successfully
14/07/22 22:35:53 INFO mapreduce.Job: Counters: 49
File System Counters
FILE: Number of bytes read=2521
FILE: Number of bytes written=283699
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=2280
HDFS: Number of bytes written=1710
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)=71182
Total time spent by all reduces in occupied slots (ms)=13937
Total time spent by all map tasks (ms)=71182
Total time spent by all reduce tasks (ms)=13937
Total vcore-seconds taken by all map tasks=71182
Total vcore-seconds taken by all reduce tasks=13937
Total megabyte-seconds taken by all map tasks=72890368
Total megabyte-seconds taken by all reduce tasks=14271488
Map-Reduce Framework
Map input records=29
Map output records=274
Map output bytes=2814
Map output materialized bytes=2527
Input split bytes=202
Combine input records=274
Combine output records=195
Reduce input groups=190
Reduce shuffle bytes=2527
Reduce input records=195
Reduce output records=190
Spilled Records=390
Shuffled Maps =2
Failed Shuffles=0
Merged Map outputs=2
GC time elapsed (ms)=847
CPU time spent (ms)=6410
Physical memory (bytes) snapshot=426119168
Virtual memory (bytes) snapshot=1953292288
Total committed heap usage (bytes)=256843776
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=2078
File Output Format Counters
Bytes Written=1710
hadoop@ubuntu:/usr/local/gz/hadoop-2.4.1$

上面的日志显示出了wordCount的详细情况,然后执行查看结果命令查看统计结果:

hadoop@ubuntu:/usr/local/gz/hadoop-2.4.1$ ./bin/hadoop fs -cat /output/part-r-00000
14/07/22 22:38:05 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
"as 1
"atrocious," 1
- 1
10-day 1
13 1
18 1
20, 1
2006. 1
3,000 1
432 1
65 1
7.4.52 1
:help 2
:help<Enter> 1
:q<Enter> 1
<F1> 1
Already, 1
Ban 1
Benjamin 1

后面省略了很多统计数据,wordCount统计结果完成。

[Linux][Hadoop] 运行WordCount例子的更多相关文章

  1. RedHat 安装Hadoop并运行wordcount例子

    1.安装 Red Hat 环境 2.安装JDK 3.下载hadoop2.8.0 http://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/had ...

  2. (四)伪分布式下jdk1.6+Hadoop1.2.1+HBase0.94+Eclipse下运行wordCount例子

    本篇先介绍HBase在伪分布式环境下的安装方式,然后将MapReduce编程和HBase结合起来使用,完成WordCount这个例子. HBase在伪分布环境下安装 一.   前提条件 已经成功地安装 ...

  3. hadoop运行wordcount实例,hdfs简单操作

    1.查看hadoop版本 [hadoop@ltt1 sbin]$ hadoop version Hadoop -cdh5.12.0 Subversion http://github.com/cloud ...

  4. hadoop执行wordcount例子

    1:下载hadoop.http://mirror.esocc.com/apache/hadoop/common/hadoop-1.2.1/hadoop-1.2.1.tar.gz 2:解压. tar - ...

  5. hadoop的wordcount例子运行

    可以通过一个简单的例子来说明MapReduce到底是什么: 我们要统计一个大文件中的各个单词出现的次数.由于文件太大.我们把这个文件切分成如果小文件,然后安排多个人去统计.这个过程就是”Map”.然后 ...

  6. 配置RHadoop与运行WordCount例子

    1.安装R语言环境 su -c 'rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch. ...

  7. [hadoop] hadoop 运行 wordcount

    讲准备好的文本文件放到hdfs中 执行 hadoop 安装包中的例子 [root@hadoop01 mapreduce]# hadoop jar hadoop-mapreduce-examples-2 ...

  8. CDH quick start VM 中运行wordcount例子

    需要注意的事情: 1. 对于wordcount1.0 ,按照http://www.cloudera.com/content/cloudera/en/documentation/HadoopTutori ...

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

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

随机推荐

  1. 使用 MongoDB 的_id 查询

    MongoDB 默认在插入数据时,生成一个主键_id,那么怎么使用_id来查询数据? 查询全部 > db.foo.find(){ "_id" : ObjectId(" ...

  2. springboot 整合Redis

    0.导入 maven依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifact ...

  3. C#函数参数

    当函数接受参数时,必须指定下属内容 函数在其定义中指定参数列表,以及这些参数的类型 在每个函数调用中匹配参数列表 参数匹配:当调用函数时,必须使参数与函数定义中指定的参数完全匹配,这意味着要匹配参数的 ...

  4. mysql索引无效且sending data耗时巨大原因分析

    一朋友最近新上线一个项目,本地测试环境跑得好好的,部署到线上却慢得像蜗牛一样.后来查询了一下发现一个sql执行了16秒,有些长的甚至80秒.本地运行都是毫秒级别的查询.下面记录一下困扰了两天的,其中一 ...

  5. libreoffice安装

    centos7下libreoffice的安装 #下载安装包wget http://mirrors.ustc.edu.cn/tdf/libreoffice/stable/5.1.1/rpm/x86_64 ...

  6. CEF3开发者系列之外篇——IE中JS与C++交互

    使用IE内核开发客户端产品,系统和前端页面之间的交互,通常给开发和维护带来很大的便利性.但操作系统和前端之间的交互却是比较复杂的.具体来说就是脚本语言和编译语言的交互.在IE内核中html和css虽然 ...

  7. ACM/ICPC 之 数据结构-线段树思想(POJ2182,含O(n^2)插入式解法)

    这道题在一定程度上体现了线段树的一种用法,解决的问题是:对于总计n个元素的第i个元素,已知其在[1,i]上部分序列的排名,求第i个元素在所有n个元素中的排名. 当然这道题数据比较水,所以用O(n^2) ...

  8. percona-toolkit 之 【pt-deadlock-logger】说明

    摘要: 死锁:是指两个或则多个事务在同一个资源上相互占用,并请求锁定对方占用的资源,而导致恶性循环的现象:当产生死锁的时候,MySQL会回滚一个小事务的SQL,确保另一个完成.上面是死锁的概念,而在M ...

  9. SQL删除约束

    )禁止所有表约束的SQL select 'alter table '+name+' nocheck constraint all' from sysobjects where type='U' )删除 ...

  10. 【HTTP】WireShark中获取Content-Encoding: gzip时的响应内容

    GZIP格式 详见:http://blog.csdn.net/jison_r_wang/article/details/52068607 表述的很清楚 关键:GZIP头以0x1F8B开始 用WireS ...