阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下执行Hadoop WordCount.jar

93次阅读
没有评论

共计 5043 个字符,预计需要花费 13 分钟才能阅读完成。

Linux 执行 Hadoop WordCount

Ubuntu 终端进入快捷键:ctrl + Alt +t

hadoop 启动命令:start-all.sh

 

正常执行效果如下:

hadoop@HADOOP:~$ start-all.sh

Warning: $HADOOP_HOME is deprecated.

 

starting namenode, logging to /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-namenode-HADOOP.MAIN.out

HADOOP.MAIN: starting datanode, logging to/home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-datanode-HADOOP.MAIN.out

HADOOP.MAIN: starting secondarynamenode,logging to/home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-secondarynamenode-HADOOP.MAIN.out

starting jobtracker, logging to/home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-jobtracker-HADOOP.MAIN.out

HADOOP.MAIN: starting tasktracker, loggingto /home/hadoop/hadoop-1.1.2/libexec/../logs/hadoop-hadoop-tasktracker-HADOOP.MAIN.out

 

jps 命令查看启动的 hadoop 服务

hadoop@HADOOP:~$ jps

3615 Jps

2699 NameNode

3461 TaskTracker

2922 DataNode

3137 SecondaryNameNode

3231 JobTracker

 

本地创建一个文件夹

hadoop@HADOOP:~$ mkdir ~/file

 

在 file 文件创建两个 txt 文件

hadoop@HADOOP:~$ cd file

hadoop@HADOOP:~/file$ echo “Hello World” > file1.txt

hadoop@HADOOP:~/file$ echo “Hello Hadoop” > file2.txt

hadoop@HADOOP:~/file$ ls

file1.txt file2.txt

hadoop@HADOOP:~/file$

 

在 HDFS 上创建一个输入文件夹

hadoop@HADOOP:~/file$ hadoop fs -mkdir input

查看创建的 input 文件夹路径

hadoop@HADOOP:~$ hadoop fs -ls

Warning: $HADOOP_HOME is deprecated.

 

Found 5 items

-rw-r–r–  3 Administrator supergroup   6296230 2014-09-03 10:38 /user/hadoop/cloud.txt

drwxr-xr-x  – hadoop        supergroup          0 2014-09-02 16:31/user/hadoop/hadi_curbm

drwxr-xr-x  – hadoop        supergroup          0 2014-09-04 09:59 /user/hadoop/input

drwxr-xr-x  – hadoop        supergroup          0 2014-09-02 16:31/user/hadoop/pegasus

hadoop@HADOOP:~$

 

可以看到目录被创建到 /user/hadoop/input 目录

 

上传本地 file 文件到 input 目录

hadoop@HADOOP:~$hadoop fs put ~/file/*.txt  /user/hadoop/input

 

找到 hadoop 目录下的 examples.jar 程序包

hadoop@HADOOP:~$ cd hadoop-1.1.2

hadoop@HADOOP:~/hadoop-1.1.2$ ls

bin         docs                         hadoop-test-1.1.2.jar  LICENSE.txt src

build.xml   hadoop-ant-1.1.2.jar         hadoop-tools-1.1.2.jar  logs        webapps

c++         hadoop-client-1.1.2.jar      ivy                    NOTICE.txt  wordcount.jar

CHANGES.txt hadoop-core-1.1.2.jar        ivy.xml                README.txt

conf        hadoop-examples-1.1.2.jar    lib                    sbin

contrib     hadoop-minicluster-1.1.2.jar libexec                share

hadoop@HADOOP:~/hadoop-1.1.2$

 

执行 jar 程序代码 统计 input 目录下文件的 Wordcount

hadoop@HADOOP:~$ hadoop jar /home/hadoop/hadoop-1.1.2/hadoop-examples-1.1.2.jar wordcount  /user/hadoop/input output

Warning: $HADOOP_HOME is deprecated.

 

14/09/04 10:10:44 INFOinput.FileInputFormat: Total input paths to process : 0

14/09/04 10:10:45 INFO mapred.JobClient:Running job: job_201409040943_0001

14/09/04 10:10:46 INFOmapred.JobClient:  map 0% reduce 0%

14/09/04 10:10:54 INFOmapred.JobClient:  map 0% reduce 100%

14/09/04 10:10:55 INFO mapred.JobClient:Job complete: job_201409040943_0001

14/09/04 10:10:55 INFO mapred.JobClient:Counters: 18

14/09/04 10:10:55 INFOmapred.JobClient:  Job Counters

14/09/04 10:10:55 INFOmapred.JobClient:    Launched reducetasks=1

14/09/04 10:10:55 INFOmapred.JobClient:    SLOTS_MILLIS_MAPS=4087

14/09/04 10:10:55 INFOmapred.JobClient:    Total time spent byall reduces waiting after reserving slots (ms)=0

14/09/04 10:10:55 INFOmapred.JobClient:    Total time spent byall maps waiting after reserving slots (ms)=0

14/09/04 10:10:55 INFO mapred.JobClient:    SLOTS_MILLIS_REDUCES=4068

14/09/04 10:10:55 INFOmapred.JobClient:  File Output FormatCounters

14/09/04 10:10:55 INFOmapred.JobClient:    Bytes Written=0

14/09/04 10:10:55 INFOmapred.JobClient:  FileSystemCounters

14/09/04 10:10:55 INFO mapred.JobClient:    FILE_BYTES_WRITTEN=55309

14/09/04 10:10:55 INFOmapred.JobClient:  Map-Reduce Framework

14/09/04 10:10:55 INFOmapred.JobClient:    Reduce inputgroups=0

14/09/04 10:10:55 INFOmapred.JobClient:    Combine outputrecords=0

14/09/04 10:10:55 INFOmapred.JobClient:    Reduce shufflebytes=0

14/09/04 10:10:55 INFOmapred.JobClient:    Physical memory(bytes) snapshot=35037184

14/09/04 10:10:55 INFOmapred.JobClient:    Reduce outputrecords=0

14/09/04 10:10:55 INFO mapred.JobClient:     Spilled Records=0

14/09/04 10:10:55 INFOmapred.JobClient:    CPU time spent(ms)=120

14/09/04 10:10:55 INFOmapred.JobClient:    Total committedheap usage (bytes)=15925248

14/09/04 10:10:55 INFOmapred.JobClient:    Virtual memory(bytes) snapshot=377499648

14/09/04 10:10:55 INFOmapred.JobClient:    Combine inputrecords=0

14/09/04 10:10:55 INFOmapred.JobClient:    Reduce inputrecords=0

hadoop@HADOOP:~$

 

 

显示结果

hadoop@HADOOP:~$ hadoop fs -ls output

Warning: $HADOOP_HOME is deprecated.

 

Found 3 items

-rw-r–r–  1 hadoop supergroup          02014-09-04 10:10 /user/hadoop/output/_SUCCESS

drwxr-xr-x  – hadoop supergroup          02014-09-04 10:10 /user/hadoop/output/_logs

-rw-r–r–  1 hadoop supergroup          02014-09-04 10:10 /user/hadoop/output/part-r-00000

hadoop@HADOOP:~$

 

查看执行结果

hadoop@HADOOP:~$ hadoop fs -cat output/part-r-00000

Hadoop 1

Hello   2

World  1

Ubuntu 13.04 上搭建 Hadoop 环境 http://www.linuxidc.com/Linux/2013-06/86106.htm

Ubuntu 12.10 +Hadoop 1.2.1 版本集群配置 http://www.linuxidc.com/Linux/2013-09/90600.htm

Ubuntu 上搭建 Hadoop 环境(单机模式 + 伪分布模式)http://www.linuxidc.com/Linux/2013-01/77681.htm

Ubuntu 下 Hadoop 环境的配置 http://www.linuxidc.com/Linux/2012-11/74539.htm

单机版搭建 Hadoop 环境图文教程详解 http://www.linuxidc.com/Linux/2012-02/53927.htm

搭建 Hadoop 环境(在 Winodws 环境下用虚拟机虚拟两个 Ubuntu 系统进行搭建)http://www.linuxidc.com/Linux/2011-12/48894.htm

更多 Hadoop 相关信息见 Hadoop 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=13

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计5043字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中