大家。我正在使用Mr处理某些日志文件,该文件位于hdfs上。我想从文件中检索一些信息并将其存储到hbase。

所以我开始工作

HADOOP_CLASSPATH=`${HBASE_HOME}/bin/hbase classpath` ${HADOOP_HOME}/bin/hadoop jar crm_hbase-1.0.jar /datastream/music/useraction/2014-11-30/music_useraction_20141130-230003072+0800.24576015364769354.00018022.lzo

如果我只是将作业作为“hadoop jar xxxx”运行,则会显示“找不到HbaseConfiguraion”

我的代码很简单,
  public int run(String[] strings) throws Exception {


    Configuration config = HBaseConfiguration.create();

    String  kerbConfPrincipal = "[email protected]";
    String  kerbKeytab = "/srv/zwj/ndir.keytab";



    UserGroupInformation.loginUserFromKeytab(kerbConfPrincipal, kerbKeytab);
    UserGroupInformation ugi = UserGroupInformation.getLoginUser();

    System.out.println(" auth: " + ugi.getAuthenticationMethod());
    System.out.println(" name: " + ugi.getUserName());
    System.out.println(" using keytab:" + ugi.isFromKeytab());

    HBaseAdmin.checkHBaseAvailable(config);

    //set job name
    Job job = new Job(config, "Import from file ");
    job.setJarByClass(LogRun.class);
    //set map class
    job.setMapperClass(LogMapper.class);

    //set output format and output table name
    job.setOutputFormatClass(TableOutputFormat.class);
    job.getConfiguration().set(TableOutputFormat.OUTPUT_TABLE, "crm_data");
    job.setOutputKeyClass(ImmutableBytesWritable.class);
    job.setOutputValueClass(Put.class);
    job.setNumReduceTasks(0);
    TableMapReduceUtil.addDependencyJars(job);

但是,当我尝试运行此MR时,无法执行“context.write(null,put)”,似乎“map”在此行停止了。
我认为它与“kerbKeytab”有关,这是否意味着我在运行“ map ”过程时需要“登录”

最佳答案

添加TableMapReduceUtil后,它可以工作

    Job job = new Job(config, "Import from file ");
    job.setJarByClass(LogRun.class);
    //set map class
    job.setMapperClass(LogMapper.class);

    TableMapReduceUtil.initTableReducerJob(table, null, job);
    job.setNumReduceTasks(0);
    TableMapReduceUtil.addDependencyJars(job);
    FileInputFormat.setInputPaths(job,input);
    //FileInputFormat.addInputPath(job, new Path(strings[0]));
    int ret = job.waitForCompletion(true) ? 0 : 1;

关于hadoop - 无法使用hbase和hadoop在map函数中执行 “put”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27223799/

10-16 18:28