在java中访问远程hbase,masterNotRunning
最近,需要使用HBase作为数据库,所以想研究HBase。但是最近遇到了一个问题,很多天都没有找到答案。 首先描述一下我的机器。一台普通PC机,系统win7,在win7上安装了一台虚拟机,虚拟机运行ubuntu10,使用Hadoop和HBase,它们都运行成功。虚拟机中的HBase外壳和JAVA API成功运行HBase 但问题是,我想使用JAVA API(win7)中的PC机访问hbase,但失败了。 Hbase-site.xml如下所示在java中访问远程hbase,masterNotRunning,java,hadoop,hbase,Java,Hadoop,Hbase,最近,需要使用HBase作为数据库,所以想研究HBase。但是最近遇到了一个问题,很多天都没有找到答案。 首先描述一下我的机器。一台普通PC机,系统win7,在win7上安装了一台虚拟机,虚拟机运行ubuntu10,使用Hadoop和HBase,它们都运行成功。虚拟机中的HBase外壳和JAVA API成功运行HBase 但问题是,我想使用JAVA API(win7)中的PC机访问hbase,但失败了。 Hbase-site.xml如下所示 <property> <nam
<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>
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
<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(win7)JAVA API 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>
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
<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>
出现以下错误:
Org.apache.hadoop.hbase.MasterNotRunningException: com.google.protobuf.ServiceException: java.net.ConnectException: Connection refused: no further information
事实上,我已经看过源代码了,在zookeeper中发现获取主地址总是返回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();
}
}
我是中国人,英语不好,请原谅。首先将ip 192.168.235.134添加到win7和 检查端口2181是否在192.168.235.134处打开,如果未打开,则将其打开 要在ubuntu中打开端口,请查看
您还可以添加在客户端中运行的客户端java代码。您是否找到了解决此问题的方法。我也在努力解决同样的问题。请告诉我你的决定。