我写了一个很短的程序来连接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
使用的[root@ostrich-node1 logs]# hbase version
15/03/19 17:59:17 INFO util.VersionInfo: HBase 0.94.1-Intel
不同。是的。所以,我更换了罐子但遗憾的是错误并没有消失。
请注意,我已经在安装了hbase的同一台机器上执行了我的程序。
Hbase版本:
[root@ostrich-node1 logs]# hadoop version
Hadoop 1.0.3-Intel
Hadoop版本:
[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 shell工作:
{{1}}
那么,问题可能是什么? 请帮忙。
答案 0 :(得分:0)
通过做以下事情,这对我有用:
HBASE_CONF
的结束中添加classpath
的路径,如下所示(右键点击图片并在新标签中打开,如果它们也是小理解):
注意:在我的hbase主节点中,HBASE_CONF = / usr / lib / hbase / conf。
注意:HBaseConfiguration()
已弃用,但适用于hbase-0.94.1(英特尔)。
输出如下所示:
抱歉,代码突出显示器无法处理大型代码。所以,我 使用图像正确显示它们。