gpt4 book ai didi

java - 在java中访问远程hbase,masterNotRunning

转载 作者:可可西里 更新时间:2023-11-01 14:58:52 26 4
gpt4 key购买 nike

最近需要用到HBase做数据库,所以想研究一下hbase。但是最近遇到一个问题,找了好多天都没有找到答案。先介绍一下我的机器。一台普通PC,系统win7,在win7下安装了虚拟机,虚拟机运行ubuntu10,配合Hadoop和HBase,都运行成功。虚拟机中的HBase shell和JAVA API成功运行HBase。

但问题是我想在JAVA API(win7)的PC机上访问hbase,然后失败了。Hbase-site.xml如下

<property>
<name>hbase.cluster.distributed</name>
<value>false</value>
</property>
<property>
<name>hbase.tmp.dir</name>
<value>/opt/tmp</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>hdfs://192.168.235.134:9000/hbase</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>192.168.235.134</value>
</property>

/etc/hosts如下

192.168.235.134 localhost ubuntu

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

PC(win7)JAVA API hbase-site.xml如下

<property>
<name>hbase.cluster.distributed</name>
<value>false</value>
</property>
<property>
<name>hbase.rootdir</name>
<value>hdfs://192.168.235.134:9000/hbase</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>192.168.235.134</value>
</property>

PC端JAVA代码如下。

HBaseAdmin.checkHBaseAvailable (HBaseConfiguration.create ());

以下错误:

Org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.net.ConnectException: Connection refused: no further information

其实我看过源码,发现在zookeeper中获取master地址总是返回localhost,问题应该出在这里。源代码如下。HConnectionManager.java

private Object makeStubNoRetries() throws IOException, KeeperException, ServiceException {
ZooKeeperKeepAliveConnection zkw;
try {
zkw = getKeepAliveZooKeeperWatcher();
} catch (IOException e) {
ExceptionUtil.rethrowIfInterrupt(e);
throw new ZooKeeperConnectionException("Can't connect to ZooKeeper", e);
}
try {
checkIfBaseNodeAvailable(zkw);

!----here always return localhost-----------------------!
ServerName sn = MasterAddressTracker.getMasterAddress(zkw);

if (sn == null) {
String msg = "ZooKeeper available but no active master location found";
LOG.info(msg);
throw new MasterNotRunningException(msg);
}
if (isDeadServer(sn)) {
throw new MasterNotRunningException(sn + " is dead.");
}
// Use the security info interface name as our stub key
String key = getStubKey(getServiceName(), sn.getHostAndPort());
connectionLock.putIfAbsent(key, key);
Object stub = null;
synchronized (connectionLock.get(key)) {
stub = stubs.get(key);
if (stub == null) {
BlockingRpcChannel channel = rpcClient.createBlockingRpcChannel(sn,
user, rpcTimeout);
stub = makeStub(channel);
isMasterRunning();
stubs.put(key, stub);
}
}
return stub;
} finally {
zkw.close();
}
}

我是中国人,英文不好,请见谅。

最佳答案

首先在win7的hosts文件中添加ip 192.168.235.134查看192.168.235.134是否开启2181端口,没有开启则开启。

要在 ubuntu 中打开一个端口,请查看 https://askubuntu.com/questions/293356/how-to-open-a-particular-port-in-ubuntu

关于java - 在java中访问远程hbase,masterNotRunning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23979112/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com