系统: Ubuntu14.04

Hadoop版本: 2.7.2

参照http://www.cnblogs.com/taichu/p/5264185.html中的分享,来学习运行第一个hadoop程序。

在hadoop的安装文件夹 /usr/local/hadoop下创建input文件夹

hadoop@hadoopmaster:/usr/local/hadoop$ mkdir ./input

然后copy几个文档到input文件夹中作为WordCount的输入

hadoop@hadoopmaster:/usr/local/hadoop$ cp *.txt ./input

执行WordCount

hadoop@hadoopmaster:/usr/local/hadoop$ hadoop jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.7.2-sources.jar org.apache.hadoop.examples.WordCount input/ output

运行时报错

Exception in thread "main" org.apache.hadoop.mapreduce.lib.input.InvalidInputException: Input path does not exist: hdfs://hadoopmaster:9000/user/hadoop/input

按照http://rangerwolf.iteye.com/blog/1900615中提供的解决方案把usr/local/hadoop/input文件夹put到hdfs中

hadoop@hadoopmaster:/usr/local/hadoop$ hdfs dfs -put ./input/ input (这里在input前加上 / 就不会报错了,后同)
报错:put: `input': No such file or directory

直接mkdir也会出现同样的问题

hadoop@hadoopmaster:~$ hdfs dfs -mkdir input
mkdir: `input': No such file or directory
加上 / 成功put了后再执行WordCount,仍然报错,Input path does not exist: hdfs://hadoopmaster:9000/user/hadoop/input

这里的input文件夹路径是/user/hadoop/input,但我的路径是/usr/local/input,是不是这个原因导致找不到路径呢

参考http://stackoverflow.com/questions/20821584/hadoop-2-2-installation-no-such-file-or-directory中的回答,在hdfs中创建/user/hadoop/

hadoop@hadoopmaster:hdfs dfs -mkdir -p /user/hadoop

将input文件夹添加到该文件夹下(这一步是在eclipse中进行的)

现在我的hdfs的文件结构是这样的

hadoop@hadoopmaster:/usr/local/hadoop/etc/hadoop$ hdfs dfs -ls -R /
drwxr-xr-x   - hadoop supergroup          0 2016-03-16 21:39 /input
-rw-r--r--   2 hadoop supergroup      15429 2016-03-16 21:39 /input/LICENSE.txt
-rw-r--r--   2 hadoop supergroup        101 2016-03-16 21:39 /input/NOTICE.txt
-rw-r--r--   2 hadoop supergroup       1366 2016-03-16 21:39 /input/README.txt
drwx------   - hadoop supergroup          0 2016-03-16 21:17 /tmp
drwx------   - hadoop supergroup          0 2016-03-16 21:17 /tmp/hadoop-yarn
drwx------   - hadoop supergroup          0 2016-03-16 21:17 /tmp/hadoop-yarn/staging
drwx------   - hadoop supergroup          0 2016-03-16 21:17 /tmp/hadoop-yarn/staging/hadoop
drwx------   - hadoop supergroup          0 2016-03-16 21:41 /tmp/hadoop-yarn/staging/hadoop/.staging
drwxr-xr-x   - hadoop supergroup          0 2016-03-16 21:51 /user
drwxr-xr-x   - hadoop supergroup          0 2016-03-16 22:02 /user/hadoop
drwxr-xr-x   - hadoop supergroup          0 2016-03-16 21:57 /user/hadoop/input
-rw-r--r--   3 hadoop supergroup      15429 2016-03-16 21:57 /user/hadoop/input/LICENSE.txt
-rw-r--r--   3 hadoop supergroup        101 2016-03-16 21:57 /user/hadoop/input/NOTICE.txt
-rw-r--r--   3 hadoop supergroup       1366 2016-03-16 21:57 /user/hadoop/input/README.txt
执行
hadoop@hadoopmaster:/usr/local/hadoop/etc/hadoop$ hadoop jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.7.2-sources.jar org.apache.hadoop.examples.WordCount input/ output
Not a valid JAR: /usr/local/hadoop/etc/hadoop/share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.7.2-sources.jar

换成hdfs jar则会

hadoop@hadoopmaster:/usr/local/hadoop/etc/hadoop$ hdfs jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.7.2-sources.jar org.apache.hadoop.examples.WordCount input/ output
Error: Could not find or load main class jar
尚不清楚原因,改天来解决。有高手知道为什么会出这样的问题的请不吝赐教。

在eclipse中执行WordCount,运行成功!下面是部分输出结果。

16/03/16 22:02:46 INFO mapreduce.Job:  map 100% reduce 100%
16/03/16 22:02:46 INFO mapreduce.Job: Job job_local1837130715_0001 completed successfully
16/03/16 22:02:46 INFO mapreduce.Job: Counters: 35
    File System Counters
        FILE: Number of bytes read=29752
        FILE: Number of bytes written=1200391
        FILE: Number of read operations=0
        FILE: Number of large read operations=0
        FILE: Number of write operations=0
        HDFS: Number of bytes read=66016
        HDFS: Number of bytes written=8983
        HDFS: Number of read operations=33
        HDFS: Number of large read operations=0
        HDFS: Number of write operations=6
    Map-Reduce Framework
        Map input records=322
        Map output records=2347
        Map output bytes=24935
        Map output materialized bytes=13001
        Input split bytes=355
        Combine input records=2347
        Combine output records=897
        Reduce input groups=840
        Reduce shuffle bytes=13001
        Reduce input records=897
        Reduce output records=840
        Spilled Records=1794
        Shuffled Maps =3
        Failed Shuffles=0
        Merged Map outputs=3
        GC time elapsed (ms)=17
        Total committed heap usage (bytes)=1444937728
    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=16896
    File Output Format Counters
        Bytes Written=8983

嗯,目前还不是很看得懂这个结果,明天开始看书了,基础还是最重要的。

备忘:

hadoop命令:

列出hdfs文件系统根目录下的目录和文件

hdfs dfs -ls /  (有 / )

hdfs dfs -ls    (没有有 / )

这两个的结果是不一样的,不理解为什么,这就是为什么明天要看书的原因

Error: Could not find or load main class jar
hadoop@hadoopmaster:/usr/local/hadoop/etc/hadoop$ hdfs dfs -ls(在hdfs dfs -mkdir -p /user/[current login user]
Found 2 items
drwxr-xr-x   - hadoop supergroup          0 2016-03-16 21:57 input
drwxr-xr-x   - hadoop supergroup          0 2016-03-16 22:02 output
hadoop@hadoopmaster:/usr/local/hadoop/etc/hadoop$ hdfs dfs -ls /
Found 3 items
drwxr-xr-x   - hadoop supergroup          0 2016-03-16 21:39 /input
drwx------   - hadoop supergroup          0 2016-03-16 21:17 /tmp
drwxr-xr-x   - hadoop supergroup          0 2016-03-16 21:51 /user

列出hdfs文件系统所有的目录和文件

hdfs dfs -ls  -R /(有 / 和没有 / 的结果也是不一样的,对应上面-ls的文件夹)

运行第一个Hadoop程序,WordCount的更多相关文章

  1. Eclipse上运行第一个Hadoop实例 - WordCount(单词统计程序)

    需求 计算出文件中每个单词的频数.要求输出结果按照单词的字母顺序进行排序.每个单词和其频数占一行,单词和频数之间有间隔. 比如,输入两个文件,其一内容如下: hello world hello had ...

  2. 第六篇:Eclipse上运行第一个Hadoop实例 - WordCount(单词统计程序)

    需求 计算出文件中每个单词的频数.要求输出结果按照单词的字母顺序进行排序.每个单词和其频数占一行,单词和频数之间有间隔. 比如,输入两个文件,其一内容如下: hello world hello had ...

  3. 在Hadoop1.2.1上运行第一个Hadoop程序FileSystemCat

  4. Spark认识&环境搭建&运行第一个Spark程序

    摘要:Spark作为新一代大数据计算引擎,因为内存计算的特性,具有比hadoop更快的计算速度.这里总结下对Spark的认识.虚拟机Spark安装.Spark开发环境搭建及编写第一个scala程序.运 ...

  5. 运行第一个ruby程序

    0x00 安装 首先需要安装一个ruby的环境,ruby分为win.linux.macOS版本.不用系统安装方法略有差异,不在这进行讲解. 0x01 运行第一个ruby程序 我这里是win环境,打开命 ...

  6. 运行第一个python程序,python 变量,常量,注释

    一.运行第一个python程序: print('Hello,world') 保存为.py文件 在cmd窗口: python3x:python  py文件路径 回车 python2x:python  p ...

  7. IntelliJ IDEA + Maven环境编写第一个hadoop程序

    1. 新建IntelliJ下的maven项目 点击File->New->Project,在弹出的对话框中选择Maven,JDK选择你自己安装的版本,点击Next 2. 填写Maven的Gr ...

  8. 第一个MapReduce程序——WordCount

    通常我们在学习一门语言的时候,写的第一个程序就是Hello World.而在学习Hadoop时,我们要写的第一个程序就是词频统计WordCount程序. 一.MapReduce简介 1.1 MapRe ...

  9. 第一个Hadoop程序-单词计数

    上一篇配置了Hadoop,本文将测试一个Hadoop的小案例 hadoop的Wordcount程序是hadoop自带的一个小的案例,是一个简单的单词统计程序,可以在hadoop的解压包里找到,如下: ...

随机推荐

  1. Nagios配置—添加linux主机监控

    nagios安装请参看:Nginx平台安装Nagios监控服务 下面是我添加linux监控机的过程,如有错误或者不当的地方请指出: 测试环境: 监控主机:nagios+nagios插件+nrpe+网站 ...

  2. JavaScript 客户端JavaScript之cookie和客户端持久性

    Document对象都有一个cookie属性,它使得JavaScript代码能够在用户的硬盘上持久地存储数据, 并且能够获取以这种方式存储的数据.客户端持久性是赋予WEB应用程序记忆力的一种简单方法. ...

  3. HDU 3721 Building Roads (2010 Asia Tianjin Regional Contest) - from lanshui_Yang

    感慨一下,区域赛的题目果然很费脑啊!!不过确实是一道不可多得的好题目!! 题目大意:给你一棵有n个节点的树,让你移动树中一条边的位置,即将这条边连接到任意两个顶点(边的大小不变),要求使得到的新树的直 ...

  4. Integer和int的详细比较(转)

    Integer与int的区别我们耳熟详的有两点:1.Integer是int的包装类.2.Integer的默认初始值是null,而int的默认初试值是0. 下面通过代码进行详细比较. public cl ...

  5. rtmp协议介绍

    概述: •tcp建立连接. •rtmp握手. •客户端与服务器对建立rtmp连接达成一致. •创建rtmp流 •客户端与服务器对play或者Publish达成一致. •客户端开始传送数据到服务器. • ...

  6. 2.2 文件 I/O 的基石:Path

    Path通常代表文件系统中的位置,能浏览任何类型的文件系统,包括zip归档文件系统: 文件系统中的几个概念:目录树.根目录.绝对路径.相对路径: NIO.2中的Path是一个抽象构造,你所创建和处理的 ...

  7. error on line 1 at column 6: XML declaration allowed only at the start of the document

    This page contains the following errors: error on line 1 at column 6: XML declaration allowed only a ...

  8. iOS中定时器NSTimer的使用-备用

    1.初始化 + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelect ...

  9. Android 自定义View 画圆 画线

    自定义一个DrawCircle继承View 实现构造方法: public DrawCircle(Context context) { super(context); this.mContext = c ...

  10. MySQL执行外部sql脚本

    1:-/mysql_test/test.sql create table student( sno int not null primary key auto_increment, sname ) n ...