http://chqz1987.blog.163.com/blog/static/514383112013261505866/
假如执行下面命令:
cd /home/hadoop/ && hadoop jar ./test/wordcount/wordcount.jar org.codetree.hadoop.v1.WordCount /test/chqz/input /test/chqz/output
那么这个命令内部到底做了些什么呢?
1、首先,在 ${HADOOP_HOME}/bin/hadoop 脚本中我们可以看到有如下代码:
由于这里$starting_secure_dn=false的(这里可以参见hadoop脚本),所以最终会执行下面这行代码:
从上面shell脚本中,我们可以明确看出当执行hadoop jar命令时,实际上执行了org.apache.hadoop.util.RunJar类。
下面#run it这一行代码实质上是为执行这个类的main方法设置所需的类路径classpath。
2、继续研究org.apache.hadoop.util.RunJar来内发生的事情:
因此,命令hadoop jar ./test/wordcount/wordcount.jar org.codetree.hadoop.v1.WordCount /test/chqz/input /test/chqz/output的各段的含义:
(1) hadoop:${HADOOP_HOME}/bin下的shell脚本名。
(2) jar:hadoop脚本需要的command参数。
(3) ./test/wordcount/wordcount.jar:要执行的jar包在本地文件系统中的完整路径,参递给RunJar类。
(4) org.codetree.hadoop.v1.WordCount:main方法所在的类,参递给RunJar类。
(5) /test/chqz/input:传递给WordCount类,作为DFS文件系统的路径,指示输入数据来源。
(6) /test/chqz/output:传递给WordCount类,作为DFS文件系统的路径,指示输出数据路径。
3、org.codetree.hadoop.v1.WordCount类代码:
Source Code
1. | package org.myorg; |
2. | |
3. | import java.io.IOException; |
4. | import java.util.*; |
5. | |
6. | import org.apache.hadoop.fs.Path; |
7. | import org.apache.hadoop.conf.*; |
8. | import org.apache.hadoop.io.*; |
9. | import org.apache.hadoop.mapred.*; |
10. | import org.apache.hadoop.util.*; |
11. | |
12. | public class WordCount { |
13. | |
14. | public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { |
15. | private final static IntWritable one = new IntWritable(1); |
16. | private Text word = new Text(); |
17. | |
18. | public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { |
19. | String line = value.toString(); |
20. | StringTokenizer tokenizer = new StringTokenizer(line); |
21. | while (tokenizer.hasMoreTokens()) { |
22. | word.set(tokenizer.nextToken()); |
23. | output.collect(word, one); |
24. | } |
25. | } |
26. | } |
27. | |
28. | public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> { |
29. | public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { |
30. | int sum = 0; |
31. | while (values.hasNext()) { |
32. | sum += values.next().get(); |
33. | } |
34. | output.collect(key, new IntWritable(sum)); |
35. | } |
36. | } |
37. | |
38. | public static void main(String[] args) throws Exception { |
39. | JobConf conf = new JobConf(WordCount.class); |
40. | conf.setJobName("wordcount"); |
41. | |
42. | conf.setOutputKeyClass(Text.class); |
43. | conf.setOutputValueClass(IntWritable.class); |
44. | |
45. | conf.setMapperClass(Map.class); |
46. | conf.setCombinerClass(Reduce.class); |
47. | conf.setReducerClass(Reduce.class); |
48. | |
49. | conf.setInputFormat(TextInputFormat.class); |
50. | conf.setOutputFormat(TextOutputFormat.class); |
51. | |
52. | FileInputFormat.setInputPaths(conf, new Path(args[0])); |
53. | FileOutputFormat.setOutputPath(conf, new Path(args[1])); |
54. | |
55. | JobClient.runJob(conf); |
57. | } |
58. | } |
59. |
相关推荐
NULL 博文链接:https://byx5185.iteye.com/blog/1490172
> hadoop jar test-1.0-SNAPSHOT-jar-with-dependencies.jar /user/test/input /user/test/out 2.运行Jar包指定类中的主函数 > java -cp test-1.0-SNAPSHOT-jar-with-dependencies.jar com.test.main.MainTest
(6) 将数据集从本地传输到HDFS上,使用hadoop jar命令,输入驱动类规定参数,使用Apriori.jar包,运行AprioriDriver驱动类,实现算法效果。 (7) 运行结束使用hadoop fs -cat /output命令查看结果。
hadoop的jar包,已经经Linux系统编译过的,下载后直接解压就可以用
资源是求ncdc气象数据中最低气温的代码jar包,下载后可使用hadoop jar 命令在hdfs上运行
在windows下搭建hadoop环境,一般需要借助虚拟机或者cygwin来模拟一个linux的启动环境。但这样搭建一个环境太麻烦了,其实可以直接像linux上一样来配置变量,然后启动,他的启动命令就是上面jar包中的bin
# 解压命令 tar -zxvf flink-shaded-hadoop-2-uber-3.0.0-cdh6.2.0-7.0.jar.tar.gz # 介绍 用于CDH部署 Flink所依赖的jar包
1.3 cp hadoop-gpl-compression-0.1.0/hadoop-gpl-compression-0.1.0.jar /usr/local/hadoop-1.0.2/lib/ 2.安装 lzo apt-get install gcc apt-get install lzop 3.在本地测试 可以 执行 压缩及解压缩命令 下载 ...
bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar *** 输入文件目录 输出文件目录 *** 本地运行案例 bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar ...
自己的第一个hadoop 实例,好高兴分享一下。 运行命令hadoop jar ‘/home/hadoop/downloas/max.jar’ upload.MaxTemperature
(1)熟悉Hadoop开发包 (2)编写MepReduce程序 (3)调试和运行MepReduce程序 (4)完成上课老师演示的内容 二、实验环境 Windows 10 VMware Workstation Pro虚拟机 Hadoop环境 Jdk1.8 二、实验内容 1.单词计数实验...
hadoop k-means算法实现java工程的打包类,可直接在terminal中运行,运行命令为: $HADOOP_HOME/bin/hadoop jar ClusterDemo.jar main.Cluster 然后直接确定就可以看到提示的运行参数或者参考下面: +"<input> ...
hadoop2.8.3的eclipse插件,eclipse版本是mars,亲测可用。如果遇到这个错误:An internal error occurred during: "Map/Reduce location status updater"不是插件问题,请执行命令:hadoop dfs -mkdir /用户名。
云计算时入门级hadoop应用,测试可以用,类名是WordCount,使用命令是hadoop jar wordcount.jar WordCount /input /output
hadoop jar /Users/hello/Desktop/accessMR.jar accessMR.AccessMR /logs/access.log /user/output检查输出。 hadoop fs -cat /user/output/part-00000运行hadoop命令的快捷方式: 编辑〜/ .profile并设置h
Hadoop输出快照 MapReduce 程序以 snappy 压缩格式输出 作者:Yvonne Zhao 邮箱: 用法:1. 将项目导出为 JAR 文件 2. 使用 hadoop jar 命令运行 JAR 文件 3. 输入:纯文本 输出:snappy 压缩文本
Hadoop 命令 hadoop fs -ls(列出用户主目录中的所有文件) hadoop fs -cat datasets/test.txt(在hdfs位置打开文件) hadoop fs -mkdir datasets/hello(在数据集目录中创建一个文件夹) hadoop fs -rm -r ...
主要介绍了解决-BASH: /HOME/JAVA/JDK1.8.0_221/BIN/JAVA: 权限不够的问题,需要的朋友可以参考下
Hadoop PCAP分析器 该项目是基于Hadoop和Hive的pcap软件包分析工具。 安装 安装Apache Hadoop 安装Apache Hive Pcap分析 分析网络层上的pcap软件包 ... hadoop jar ./analyzer-0.0.1-SNAPSHOT.jar co
在Windows下连接远程Hadoop集群时,注意本地要安装cygwin,并将cygwin/bin目录设置到PATH,以便程序能使用chmod命令。 另,Hadoop Eclipse插件只能连接相应版本的Hadoop集群,例如,本插件只能连接hadoop-0.20.2-cdh...