我写了一个很短的程序来连接 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();
}
}
}
使用与 lib
hbase目录如下:
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)
远程登录到hbase主机工作正常:
[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
. 是的,是的。所以,我更换了jar,但不幸的是错误没有消失。
请注意,我在安装了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外壳工程:
[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
那么,问题出在哪里呢?请帮忙。
1条答案
按热度按时间qlckcl4x1#
我做了以下几件事:
添加的路径
HBASE_CONF
最后classpath
,如下图所示(如果图像太小而无法理解,请在图像上单击鼠标右键并在新选项卡中打开):注意:在我的hbase主节点中,hbase_conf=/usr/lib/hbase/conf。
不幸的是,在略微修改的程序中使用了depreacted方法,但这是正确的:
注:
HBaseConfiguration()
已弃用,但适用于hbase-0.94.1(intel)。输出如下:
抱歉,代码荧光笔不适用于大代码。因此,我使用图像来正确地显示它们。