hbase.mapreduce.TableOutputFormat not found



我正在使用hdp 2.6和hbase1.1.2。

当我从不在 hdp 集群中的服务器提交地图缩减作业时,
我得到了以下异常:

Class org.apache.hadoop.hbase.mapreduce.TableOutputFormat not found.

我的映射器在本地作业模式下正确完成,我真的很确定这个类在我的类路径中,集群中的 lib 也有这个 jar。

我在谷歌上搜索了其他人做的几个步骤:
1. 使用 -libjars
2. 将hbase_classpath添加到 Hadoop.env 并重新启动群集
3. 将 HBase-master/lib 添加到 yarn-site.xml并重启集群
但这些都行不通。请帮助我,因为我只能使用 mr 来完成这项任务。

这是我的代码:

package com.test.service;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.mapreduce.ImportTsv;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.ToolRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class Tsv2HBaseService {
    private org.apache.hadoop.conf.Configuration  config;
    private String principle;
    private String keytab;
    Tsv2HBaseService(@Value("${hbase.kerberos.REALM}") String principle,
                     @Value("${hbase.kerberos.keytab}") String keytab) {
        this.config = HBaseConfiguration.create();
        this.principle = principle;
        this.keytab = keytab;
    }
    public int importMultiKeyWithTableTSV(String table, String tsvfile, String className) throws Exception {
        String args[] = {
                "-Dimporttsv.mapper.class=" + className,
                "-DtableStructure.file=" + tsvfile.replace(".csv", ".xml"),
                table,
                tsvfile,
                "-libjars ./hbase-client-1.1.2.jar,./hbase-server-1.1.2.jar,./hbase-protocol-1.1.2.jar,./hbase-common-1.1.2.jar"
        };
        config.set("hadoop.security.authentication" , "Kerberos");
        UserGroupInformation.setConfiguration(this.config);
        UserGroupInformation.loginUserFromKeytab(this.principle, this.keytab);
        return ToolRunner.run(config, new ImportTsv(), args);
    }
}
package com.test.web;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.CellCreator;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class GRZHXXTsvImporterMapper extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {
    private static final Logger logger = LoggerFactory.getLogger(Tsv2HbaseController.class);
    @Override
    public void map(LongWritable offset, Text value, Mapper<LongWritable, Text, ImmutableBytesWritable, Put>.Context context)
            throws IOException {
        try {
            String[] row = value.toString().split(",");
            ImmutableBytesWritable rowKey = new ImmutableBytesWritable((row[0]+row[1]+row[2]).getBytes());
            Put put = new Put(rowKey.copyBytes());
            KeyValue kv3 = new KeyValue(rowKey.copyBytes(), "PUBLIC".getBytes(),"GRJCJS".getBytes(), row[3].getBytes());
            put.add(kv3);
            // Write user table put
            context.write(rowKey, put);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

hadoop-env.sh:

...lots of settings...
HADOOP_CLASSPATH=${HADOOP_CLASSPATH}{JAVA_JDBC_LIBS}${HBASE_CLASSPATH}
...lots of settings...

纱线站点.xml:

...lots of settings...
yarn.application.classpath=.......,/usr/hdp/current/hbase-master/lib/*
...lots of settings...

最后我找到了解决方案。

将 hbase-master 添加到下面的类路径:纱线站点.xml地图网站.xml

应在群集和您自己的 JAR 资源中修改这两个 XML。

最新更新