在 Amazon EMR 上使用 java 中的 hbase 时遇到问题

2024-05-11

因此,我尝试使用作为 MapReduce 步骤启动的自定义 jar 来查询 Amazon ec2 上的 hbase 集群。我的 jar (在地图函数内)我这样调用 Hbase:

public void map( Text key, BytesWritable value, Context contex ) throws IOException, InterruptedException {
    Configuration conf = HBaseConfiguration.create();
    HTable table = new HTable(conf, "tablename");
      ...

问题是,当它到达 HTable 行并尝试连接到 hbase 时,该步骤失败,并且出现以下错误:

2014-02-28 18:00:49,936 INFO [main] org.apache.zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection
2014-02-28 18:00:49,974 INFO [main] org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper: The identifier of this process is [email protected] /cdn-cgi/l/email-protection
2014-02-28 18:00:49,998 INFO [main-SendThread(localhost:2181)] org.apache.zookeeper.ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2014-02-28 18:00:50,005 WARN [main-SendThread(localhost:2181)] org.apache.zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused

      ...

2014-02-28 18:01:05,542 WARN [main] org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper: Possibly transient ZooKeeper exception: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/hbaseid
2014-02-28 18:01:05,542 ERROR [main] org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper: ZooKeeper exists failed after 3 retries
2014-02-28 18:01:05,542 WARN [main] org.apache.hadoop.hbase.zookeeper.ZKUtil: hconnection Unable to set watcher on znode (/hbase/hbaseid)
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/hbaseid

      ... and on and on

我可以很好地使用 hbase shell,并且可以从 shell 查询数据和所有内容。我不知道从哪里开始,我已经在谷歌上搜索了几个小时但没有运气。互联网上的大多数此类问题都没有提及亚马逊的具体修复方法。我认为zookeeper和hbase应该通过亚马逊引导程序自动正确连接。

我使用 hbase 0.94.17 jar,亚马逊正在运行 hbase 0.94.7,我很确定这不是问题,我猜更多的是我没有正确设置 Java 代码。如果有人可以提供帮助,我们将不胜感激。谢谢


好吧,经过近 30 个小时的尝试,我找到了解决方案。 对此有很多注意事项,并且版本很重要。

在本例中,我使用 amazon emr hadoop2 (ami 3.0.4) 和 Hbase 0.94.7,并尝试在同一集群上运行自定义 jar 以通过 java 在本地访问 hbase。

因此,第一件事是,由于 EC2 面临的外部/内部 IP 特性,默认的 hbase 配置将不起作用。所以你不能使用 HConfiguration (因为它默认为本地主机仲裁) 您需要做的就是使用亚马逊为您设置的配置(位于 /home/hadoop/hbase/conf/hbase-site.xml ),然后手动将其添加到空白配置对象中。

连接代码如下所示:

Configuration conf = new Configuration();
conf.addResource("/home/hadoop/hbase/conf/hbase-site.xml");
HBaseAdmin.checkHBaseAvailable(conf);

其次,您必须使用正确的 hbase jar 打包到您的自定义 jar 中。原因是因为 hbase 94.x 默认是为 hadoop1 编译的,所以你必须获取名为 hbase-0.94.6-cdh4.3.0.jar 的 cloudera hbase jar(你可以在网上找到它),它是针对 hadoop2 编译的。如果您不执行此部分,您将收到许多令人讨厌的、无法通过谷歌搜索的错误,包括 org.apache.hadoop.net.NetUtils 异常。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Amazon EMR 上使用 java 中的 hbase 时遇到问题 的相关文章

随机推荐