最近,需要使用hbase作为数据库,所以想研究HBase。但是最近遇到一个问题,很多天都没有找到答案。首先描述一下我的机器。一台普通的PC机,system win7,在win7上安装了一台虚拟机,虚拟机运行ubuntu10,配合Hadoop和HBase,都运行成功。虚拟机中的HBase外壳和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-allhostsPC (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中获取主地址总是返回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();
}
}我是中国人,英语不好,请原谅。
发布于 2014-06-02 16:04:26
首先将ip 192.168.235.134添加到win7的hosts文件中,检查端口2181在192.168.235.134处是否打开,如果没有打开,则打开。
要在ubuntu中打开一个端口,请查看https://askubuntu.com/questions/293356/how-to-open-a-particular-port-in-ubuntu
https://stackoverflow.com/questions/23979112
复制相似问题