java – 连接到在Docker中运行的HBase

前端之家收集整理的这篇文章主要介绍了java – 连接到在Docker中运行的HBase前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我无法连接到Windows上运行在Docker中的HBase(banno/hbase-standalone图像).但是,我可以连接到本地安装的HBase.

使用以下命令运行banno/hbase-standalone图像:

docker run -d -p 2181:2181 -p 60000:60000 -p 60010:60010 -p 60020:60020 -p 60030:60030 banno/hbase-standalone

我还在boot2docker-vm上设置了端口转发(在Windows上运行时需要):

我可以成功telnet到我的localhost上的所有端口.

接下来,这是我们在测试中使用的代码示例:

Configuration config = HBaseConfiguration.create();
config.clear();
config.setInt("timeout",12000);
config.set("zookeeper.znode.parent","/hbase");
config.set("hbase.zookeeper.quorum","127.0.0.1");
config.set("hbase.zookeeper.property.clientPort","2181");
config.set("hbase.master","127.0.0.1:60000");

final Configuration configuration = HBaseConfiguration.create(config);

JobDefinition.Buildable.dumpProperties(configuration,newArrayList("hbase.*"));

HBaseAdmin.checkHBaseAvailable(config);

这导致以下异常

Exception in thread "main" org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.net.UnknownHostException: unknown host: a3e6c240af20
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStub(HConnectionManager.java:1651)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(HConnectionManager.java:1677)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getKeepAliveMasterService(HConnectionManager.java:1885)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.isMasterRunning(HConnectionManager.java:900)
    at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:2366)
    at com.xxx.compute.hadoop.jobs.transaction.OurTest.main(OurTest.java:24)
Caused by: com.google.protobuf.ServiceException: java.net.UnknownHostException: unknown host: a3e6c240af20
    at org.apache.hadoop.hbase.ipc.RpcClient.callBlockingMethod(RpcClient.java:1674)
    at org.apache.hadoop.hbase.ipc.RpcClient$BlockingRpcChannelImplementation.callBlockingMethod(RpcClient.java:1715)
    at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:42561)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(HConnectionManager.java:1688)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(HConnectionManager.java:1597)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStub(HConnectionManager.java:1623)
    ... 5 more
Caused by: java.net.UnknownHostException: unknown host: a3e6c240af20
    at org.apache.hadoop.hbase.ipc.RpcClient$Connection.

这是可以解释的.我们运行Windows,这需要使用NAT运行boot2docker-vm虚拟机.图像的Docker容器也在boot2docker-vm内运行,也使用NAT.但是,端口对于运行测试的主机是“可见的”,因为Docker容器导出端口,而boot2docker-vm将端口转发给主机.名称a3e6c240af20实际上来自Docker容器ID,因此a3e6c240af20可能是Docker容器的主机名:

CONTAINER ID        IMAGE                           COMMAND                CREATED             STATUS              PORTS                                                                                                                            NAMES
a3e6c240af20        banno/hbase-standalone:latest   "/bin/sh -c '/opt/hb   24 minutes ago      Up 24 minutes       0.0.0.0:2181->2181/tcp,0.0.0.0:60000->60000/tcp,0.0.0.0:60010->60010/tcp,0.0.0.0:60020->60020/tcp,0.0.0.0:60030->60030/tcp   agitated_wozniak

我不确定HBase通信是如何工作的,但显然它会对实例进行RPC调用. HBase Docker返回其主机名,希望客户端在那里调用它.但由于boot2docker-vm和Docker容器都使用NAT运行,因此主机无法看到Docker容器.

我尝试将a3e6c240af20添加到我的hosts文件中:

127.0.0.1 a3e6c240af20

然后我在RPC调用期间得到了一个不同的错误,这实际上对我没什么帮助:

Exception in thread "main" org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.lang.NullPointerException
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStub(HConnectionManager.java:1651)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(HConnectionManager.java:1677)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getKeepAliveMasterService(HConnectionManager.java:1885)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.isMasterRunning(HConnectionManager.java:900)
    at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:2366)
    at com.xxx.compute.hadoop.jobs.transaction.OurTest.main(OurTest.java:24)
Caused by: com.google.protobuf.ServiceException: java.lang.NullPointerException
    at org.apache.hadoop.hbase.ipc.RpcClient.callBlockingMethod(RpcClient.java:1674)
    at org.apache.hadoop.hbase.ipc.RpcClient$BlockingRpcChannelImplementation.callBlockingMethod(RpcClient.java:1715)
    at org.apache.hadoop.hbase.protobuf.generated.MasterProtos$MasterService$BlockingStub.isMasterRunning(MasterProtos.java:42561)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$MasterServiceStubMaker.isMasterRunning(HConnectionManager.java:1688)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStubNoRetries(HConnectionManager.java:1597)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation$StubMaker.makeStub(HConnectionManager.java:1623)
    ... 5 more
Caused by: java.lang.NullPointerException
    at org.apache.hadoop.hbase.ipc.RpcClient$Connection.writeRequest(RpcClient.java:1051)
    at org.apache.hadoop.hbase.ipc.RpcClient.call(RpcClient.java:1440)
    at org.apache.hadoop.hbase.ipc.RpcClient.callBlockingMethod(RpcClient.java:1657)
    ... 10 more

有人建议如何解决这个问题吗?

最佳答案
尝试添加[boot2docker IP] a3e6c240af20而不是127.0.0.1,因为HBase Java客户端需要到达您的docker主机,而不是到达localhost才能到达zookeeper(CMIIW).不确定它是否可行,但它可以在我的Windows中运行.
原文链接:/docker/436626.html

猜你在找的Docker相关文章