我写了一个很短的程序来连接Hbase
。
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class HbaseMonitor {
public static void main(String args[]){
Configuration conf = new Configuration();
try{
HBaseAdmin hbaseAdmin = new HBaseAdmin(conf);
ClusterStatus clusterStatus = hbaseAdmin.getClusterStatus();
System.out.println("Has regions: "+clusterStatus.getRegionsCount());
}
catch(Exception ex){
ex.printStackTrace();
}
}
}
使用hbase的
lib
目录中可用的相同jar对其进行编译,如下所示:javac -cp /usr/lib/hbase/hbase-0.94.1-Intel.jar:/usr/lib/hadoop/hadoop-core-1.0.3-Intel.jar:/usr/lib/hbase/lib/commons-logging-1.1.1.jar:/usr/lib/hbase/lib/zookeeper.jar:/usr/lib/hbase/lib/commons-configuration-1.6.jar:/usr/lib/hbase/lib/commons-lang-2.5.jar:/usr/lib/hbase/lib/slf4j-api-1.4.3.jar:/usr/lib/hbase/lib/slf4j-log4j12-1.4.3.jar:/usr/lib/hbase/lib/log4j-1.2.16.jar:/usr/lib/hbase/lib/guava-11.0.2.jar:/usr/lib/hbase/lib/protobuf-java-2.4.0a.jar:. HbaseMonitor.java
当我运行它时,出现以下异常:
15/03/19 17:47:07 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection
15/03/19 17:47:07 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 17277@ostrich-node1
15/03/19 17:47:07 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (Unable to locate a login configuration)
15/03/19 17:47:07 INFO zookeeper.ClientCnxn: Socket connection established to localhost/0:0:0:0:0:0:0:1:2181, initiating session
15/03/19 17:47:07 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/0:0:0:0:0:0:0:1:2181, sessionid = 0x4c31791de7041e, negotiated timeout = 180000
15/03/19 17:47:07 INFO client.HConnectionManager$HConnectionImplementation: getMaster attempt 0 of 10 failed; retrying after sleep of 1006
java.io.IOException: Call to ostrich-node1/192.168.151.50:60000 failed on local exception: java.io.EOFException
at org.apache.hadoop.hbase.ipc.HBaseClient.wrapException(HBaseClient.java:1110)
at org.apache.hadoop.hbase.ipc.HBaseClient.call(HBaseClient.java:1079)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine$Invoker.invoke(WritableRpcEngine.java:150)
at com.sun.proxy.$Proxy5.getProtocolVersion(Unknown Source)
at org.apache.hadoop.hbase.ipc.WritableRpcEngine.getProxy(WritableRpcEngine.java:183)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:335)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:312)
at org.apache.hadoop.hbase.ipc.HBaseRPC.getProxy(HBaseRPC.java:364)
at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:710)
at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:141)
at HbaseMonitor.main(HbaseMonitor.java:17)
Caused by: java.io.EOFException
at java.io.DataInputStream.readInt(DataInputStream.java:375)
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.receiveResponse(HBaseClient.java:605)
at org.apache.hadoop.hbase.ipc.HBaseClient$Connection.run(HBaseClient.java:538)
Telnet到hbase-master可以正常工作:
[root@ostrich-node1 test]# telnet ostrich-node1 60000
Trying 192.168.151.50...
Connected to ostrich-node1.
Escape character is '^]'.
localhost的Telnet清楚地表明客户端可以连接到hbase:
[root@ostrich-node1 test]# telnet localhost 2181
Trying ::1...
Connected to localhost.
Escape character is '^]'.
^CConnection closed by foreign host.
对于上述异常,主日志(
hbase-hbase-master-ostrich-node1.log
)显示以下警告:2015-03-19 17:47:07,711 WARN org.apache.hadoop.ipc.SecureServer: Incorrect header or version mismatch from 192.168.151.50:57502 got version 3 expected version 4
从以上警告中可以看出,我用于
hadoop-core.jar
的hbase
与用于hadoop
的ojit_code不同。是的。因此,我更换了广口瓶,但不幸的是错误没有消失。请注意,我已经在安装了hbase的同一台计算机上执行了我的程序。
Hbase版本:
[root@ostrich-node1 logs]# hbase version
15/03/19 17:59:17 INFO util.VersionInfo: HBase 0.94.1-Intel
Hadoop版本:
[root@ostrich-node1 logs]# hadoop version
Hadoop 1.0.3-Intel
Hbase Shell的工作原理:
[root@ostrich-node1 logs]# hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.1-Intel, r17177, Wed Sep 18 14:52:53 CST 2013
hbase(main):001:0> list
TABLE
ATTR
RECO
SUBSCRIBER
SUBSCRIBER2
TPETEST
test
6 row(s) in 1.0700 seconds
那么,可能是什么问题呢?
请帮忙。
最佳答案
通过执行以下操作,这对我有用:
HBASE_CONF
的端中添加classpath
的路径,如下所示(如果图像太小,无法理解,请右键单击图像并在新选项卡中将其打开):注意:在我的hbase主节点中,HBASE_CONF = / usr / lib / hbase / conf。
注意:不建议使用
HBaseConfiguration()
,但适用于hbase-0.94.1(Intel)。输出如下所示:
关于java - Java:连接到Hbase 0.94.1时发生异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29144818/