编写MR运行在Hbase上面注意事项

来源:互联网 发布:淘宝提前收款不能用了 编辑:程序博客网 时间:2024/06/05 15:09

最近很久没写blog了,主要精力在搭建和部署Hbase上面。

因为对Hbase了解不多,以下碰到的问题都是很基础问题:

1、运行MR程序时出现:
13/03/07 14:04:58 INFO mapred.JobClient: Task Id : attempt_201303031058_0325_m_000008_0, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.neusoft.test.HBaseToFile$TradeMap
        at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:867)
        at org.apache.hadoop.mapreduce.JobContext.getMapperClass(JobContext.java:199)
        at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:719)
        at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370)
        at org.apache.hadoop.mapred.Child$4.run(Child.java:255)
        at javax.security.auth.Subject.doAs(Subject.java:396)
        at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1121)
        at org.apache.hadoop.mapred.Child.main(Child.java:249)

这个问题描述很简单,就是各运行节点没有找到Class类。原因就是缺少一段代码:

job.setJarByClass(TradeMap.class);

 

2、运行MR程序时,出现了一个现象:

      13/03/07 11:37:12 ERROR mapreduce.TableInputFormatBase:
       Cannot resolve the host name for /10.200.187.78 because of javax.naming.NameNotFoundException: DNS name not found [response code 3];
       remaining name '78.187.200.10.in-addr.arpa'

       通过源码查找后,发现是需要设置nameServer,

       // Get the name server address and the default value is null.
      this.nameServer = context.getConfiguration().get("hbase.nameserver.address",null);

      因为没有设置过,所以在后面的验证处理过程中,就会有这样的报错信息。验证步骤如下:

      public static String reverseDns(InetAddress hostIp,String ns)throwsNamingException {
    //
    // Builds the reverse IP lookup form
    // This is formed by reversing the IP numbers and appending in-addr.arpa
    //
    String[] parts = hostIp.getHostAddress().split("\\.");
    String reverseIP = parts[3] + "." + parts[2] +"." + parts[1] +"."+ parts[0] + ".in-addr.arpa";
    DirContext ictx = newInitialDirContext();
    Attributes attribute =
      ictx.getAttributes("dns://"              // Use "dns:///" if the default
                         + ((ns == null) ? "" : ns) +
                         // nameserver is to be used
                         "/" + reverseIP,newString[] { "PTR" });
    ictx.close();
    return attribute.get("PTR").get().toString();
  }

 

总结以后,在出现相关的问题时,需要耐心解决,另外借助源码能够快速了解部分逻辑。

 

3、运行client端时,出现以下错误:

 Caused by: java.lang.RuntimeException: java.lang.RuntimeException: org.apache.hadoop.hbase.client.NoServerForRegionException: Unable to find region for tmp_order_not_closed,,99999999999999 after 10 tries.

主要原因是在client的机器这边,没有配置hbase集群的主机信息。简单的方法就是在/etc/hosts文件增加全部的节点IP信息,第二种就是使用DNS的方式。