系统: 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. Swift - 41 - swift1.2新特性(2)

    swift 和 OC 的桥接 //: Playground - noun: a place where people can play import UIKit var PI = "3.14 ...

  2. PHP Date/Time 函数

    Runtime 配置 Date/Time 函数的行为受到 php.ini 中设置的影响: 名称 描述 默认 PHP 版本 date.timezone 规定默认时区(所有的 Date/Time 函数使用 ...

  3. HTML5学习参考资料整理

    给大家推荐一下学习研究HTML5必备的一些个网站,更加有利于大家对HTML5的学些和研究.如果各位童鞋还有更多的,欢迎投递资源给我们,也可以支持 我们,让我们利用大家的力量收集更多的HTML5学习资料 ...

  4. po 和 mo 的互相转换

    反编译 mo 文件成 po 文件 msgunfmt test.mo -o test.po 编码 po 文件为 mo 文件 msgfmt -o test.mo test.po 记着备用.

  5. C++通过OCCI操作Oracle数据库详解

    1.安装OCCI 如果oracle数据库默认没有安装OCCI,可以自己从官网上下载与自己数据库版本一致的API,其中包含四个软件包: oracle-instantclient-sqlplus-10.2 ...

  6. 《python基础教程》笔记之 字符串

    字符串格式化 字符串格式化使用字符串格式化操作符即百分号%来实现.在%的左侧放置一个字符串(格式化字符串),而在右侧则放置希望格式化的值,可以使用一个值,如一个字符串或者数字,也可以使用多个值的元组或 ...

  7. Swift语法之 ---- ?和!区别

    1.常量和变量 Swift语言中是用let来定义常量,并且要初始化.var来定义变量,在let或者var后面申明类型,冒号+空格,然后再加上类型名称. 2.optional(可选)变量 可选变量用于处 ...

  8. c++学习笔记和思考

    1.内置类型:int float等编程语言自己定义的类型 类类型:自己声明的类,即是对对象的抽象 2.const double *cp 表示cp是指向一个const类型double类型数据的指针,而非 ...

  9. ural 1090 In the Army Now

    http://acm.timus.ru/problem.aspx?space=1&num=1090 #include <cstdio> #include <cstring&g ...

  10. BZOJ 2693 jzptab

    http://www.lydsy.com/JudgeOnline/problem.php?id=2693 题解: 考虑把lcm转化成gcd那答案就是然后神奇的设:就有:一样可以枚举 的取值,这是O(√ ...