【发布时间】:2013-08-17 19:22:09
【问题描述】:
我在 3 个虚拟机中运行 cloudera 集群,并尝试通过 map reduce 作业执行 hbase 批量加载。但我总是得到错误:
error: Class org.apache.hadoop.hbase.mapreduce.HFileOutputFormat not found
所以,map 进程似乎没有找到该类。所以我尝试了这个:
1) 将 hbase.jar 添加到每个节点上的 HADOOP_CLASSPATH
2) 将 TableMapReduceUtil.addDependencyJars(job) / TableMapReduceUtil.addDependencyJars(myConf, HFileOutputFormat.class) 添加到我的源代码中
没有任何效果。我完全不知道为什么找不到该类,因为 jar/类肯定在类路径中可用。
如果我查看 job.xml,我会看到以下条目:
name=tmpjars value=file:/C:/Users/Thomas/.m2/repository/org/apache/zookeeper/zookeeper/3.4.5-cdh4.3.0/zookeeper-3.4.5-cdh4.3.0.jar,file:/C:/Users/Thomas/.m2/repository/org/apache/hbase/hbase/0.94.6-cdh4.3.0/hbase-0.94.6-cdh4.3.0.jar,file:/C:/Users/Thomas/.m2/repository/org/apache/hadoop/hadoop-core/2.0.0-mr1-cdh4.3.0/hadoop-core-2.0.0-mr1-cdh4.3.0.jar,file:/C:/Users/Thomas/.m2/repository/com/google/guava/guava/11.0.2/guava-11.0.2.jar,file:/C:/Users/Thomas/.m2/repository/com/google/protobuf/protobuf-java/2.4.0a/protobuf-java-2.4.0a.jar
这对我来说似乎有点奇怪,这些是我在 Windows 系统上的本地 jar。也许这应该是hdfs jars?如果是,如何更改“tmpjars”的值?
这是我尝试执行的java代码:
configuration = new Configuration(false);
configuration.set("mapred.job.tracker", "192.168.2.41:8021");
configuration.set("fs.defaultFS", "hdfs://192.168.2.41:8020/");
configuration.set("hbase.zookeeper.quorum", "192.168.2.41");
configuration.set("hbase.zookeeper.property.clientPort", "2181");
Job job = new Job(configuration, "HBase Bulk Import for "
+ tablename);
job.setJarByClass(HBaseKVMapper.class);
job.setMapperClass(HBaseKVMapper.class);
job.setMapOutputKeyClass(ImmutableBytesWritable.class);
job.setMapOutputValueClass(KeyValue.class);
job.setOutputFormatClass(HFileOutputFormat.class);
job.setPartitionerClass(TotalOrderPartitioner.class);
job.setInputFormatClass(TextInputFormat.class);
HFileOutputFormat.configureIncrementalLoad(job, hTable);
FileInputFormat.addInputPath(job, new Path("myfile1"));
FileOutputFormat.setOutputPath(job, new Path("myfile2"));
job.waitForCompletion(true);
LoadIncrementalHFiles loader = new LoadIncrementalHFiles(
configuration);
loader.doBulkLoad(new Path("myFile3"), hTable);
编辑:
我尝试了更多,但它完全奇怪。我将以下行添加到 java 代码中:
job.setJarByClass(HFileOutputFormat.class);
我执行后,错误消失了,但出现了另一个类未找到异常:
java.lang.RuntimeException: java.lang.ClassNotFoundException: Class mypackage.bulkLoad.HBaseKVMapper not found
HBaseKVMapper 是我想要执行的自定义 Mapper 类。因此,我尝试使用“job.setJarByClass(HBaseKVMapper.class)”添加它,但它不起作用,因为它只有一个类文件,没有 jar。所以我生成了一个包含 HBaseKVMapper.class 的 Jarfile。之后,我再次执行它,现在又得到了 HFileOutputFormat.class not found 异常。
稍微调试了一下,发现setJarByClass Methode只是把本地的jar文件拷贝到HDFS上的.staging/job_#number/job.jar中。所以,这个 setJarByClass() 方法只适用于一个 jar 文件,因为它在用另一个 jar 再次执行 setJarByClass() 后覆盖了 job.jar。
在搜索 eroor 时,我在作业分期目录中看到了以下结构:
在 libjars 目录中我看到了相关的 jar 文件
所以,hbase jar 位于 libjars 目录中,但 jobtracker 不使用它来执行作业。为什么?
【问题讨论】:
-
尝试删除该行:
configuration.set("mapred.job.tracker", "192.168.2.41:8021"); -
嘿,谢谢你的回答。如果我删除该行,程序会尝试使用本地 jobtracker 并且没有服务正在运行。我的设置:cloudera 集群中的 Node1+Node2+Node3 和 Windows1 作为连接到 Node1 的客户端
-
您必须在运行 Java 程序的机器上安装 Hadoop 客户端。那么基本上,您只需要使用
configuration.set("fs.default.name", "hdfs://192.168.2.41:8020/");来指定它是一个dfs 集群。 -
"设置 haddop 客户端" = 在类路径中创建 core-site.xml/hbase-site.xml?如果是,我之前也这样做过,但我遇到了同样的错误
-
如果你删除我告诉的那行,你会得到任何错误吗?
标签: apache hadoop mapreduce hbase cloudera