我无法通过简单的Java客户端连接到hbase 1.0.3。 该程序挂起:
[main] zookeeper.ZooKeeper: Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=90000 watcher=hconnection-0x1e67b8720x0, quorum=127.0.0.1:2181, baseZNode=/hbaseenter code here
[main-SendThread(127.0.0.1:2181)] zookeeper.ClientCnxn: Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
[main-SendThread(127.0.0.1:2181)] zookeeper.ClientCnxn: Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
[main-SendThread(127.0.0.1:2181)] zookeeper.ClientCnxn: Session establishment complete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x153d8383c530008, negotiated timeout = 40000
代码非常简单:
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
public class ScanAllTables {
public static void main(String args[]) throws IOException{
// Instantiating Configuration class
Configuration config = HBaseConfiguration.create();
System.out.println(config.get("hbase.rootdir"));
System.out.println(config.get("hbase.zookeeper.property.dataDir"));
System.out.println(config.get("hbase.zookeeper.quorum"));
System.out.println(config.get("hbase.zookeeper.property.clientPort"));
Connection connection = ConnectionFactory.createConnection(config);
//System.out.println(connection);
// Instantiating Table class
Table table = connection.getTable(TableName.valueOf(HBaseTables.APPLICATION_TRACE_INDEX));
//System.out.println(table.getName());
// Instantiating the Scan class
Scan scan = new Scan();
// Scanning the required columns
//scan.addFamily(HBaseTables.APPLICATION_TRACE_INDEX_CF_TRACE);
//scan.setId("ApplicationTraceIndexScan");
// Getting the scan result
ResultScanner scanner = table.getScanner(scan);
// Reading values from scan result
for (Result result = scanner.next(); result != null; result = scanner.next()) {
System.out.println("Found row : " + result);
}
//closing the scanner
scanner.close();
table.close();
connection.close();
}
}
我使用的罐子是:
commons-collections-3.2.1.jar
commons-configuration-1.6.jar
commons-lang-2.6.jar
commons-logging-1.2.jar
guava-12.0.1.jar
hadoop-auth-2.5.1.jar
hadoop-client-2.5.1.jar
hadoop-common-2.5.1.jar
hbase-client-1.0.3.jar
hbase-common-1.0.3.jar
hbase-hadoop-compat-1.0.3.jar
hbase-hadoop2-compat-1.0.3.jar
hbase-it-1.0.3.jar
hbase-protocol-1.0.3.jar
hbase-resource-bundle-1.0.3.jar
hbase-rest-1.0.3.jar
htrace-core-3.0.4.jar
htrace-core-3.1.0-incubating.jar
log4j-1.2.17.jar
netty-3.2.4.Final.jar
netty-all-4.0.23.Final.jar
protobuf-java-2.5.0.jar
slf4j-api-1.7.7.jar
slf4j-log4j12-1.7.7.jar
zookeeper-3.4.6.jar
我的hbase-site.xml是
<configuration>
<property>
<name>hbase.rootdir</name>
<value>file:///path/to/data/hbase</value>
</property>
<property>
<name>hbase.zookeeper.property.dataDir</name>
<value>file:///path/to/data/zookeeper</value>
</property>
<property>
<name>hbase.zookeeper.quorum</name>
<value>127.0.0.1</value>
</property>
</configuration>
在我的主持人中,我有这个条目: 127.0.0.1 localhost.localdomain localhost Sachin-PC
同样在hbase中,regionservers有localhost 我已经为hbase.zookeeper.quorum尝试了很多选项,比如localhost,Sachin-PC,但都没有。
另请注意我使用的jar在hbase lib中的版本相同。
我只是无法解决这个简单代码扫描表失败的原因。
注意代码在ResultScanner scan = table.getScanner(scan)行停止; 所以连接正在发生,但它没有获得任何数据。
请帮忙!
由于 萨钦
PS:
DEBUG [hconnection-0x1e67b872-shared--pool1-t1] ipc.AbstractRpcClient: Use SIMPLE authentication for service ClientService, sasl=false
DEBUG [hconnection-0x1e67b872-shared--pool1-t1] ipc.AbstractRpcClient: Connecting to Sachin-PC/127.0.0.1:55161
DEBUG [hconnection-0x1e67b872-shared--pool1-t1] ipc.AbstractRpcClient: Use SIMPLE authentication for service ClientService, sasl=false
DEBUG [hconnection-0x1e67b872-shared--pool1-t1] ipc.AbstractRpcClient: Not trying to connect to Sachin-PC/127.0.0.1:55161 this server is in the failed servers list
请参阅以下附加日志: 我们可以看到连接发生,并且还获取了区域位置详细信息。 但是当它尝试连接到该区域以实际获取表扫描详细信息时,我们会收到套接字关闭错误,然后将其添加到失败的服务器列表中。这个过程一次又一次地重复,因此过程被卡住了。
[main-EventThread] zookeeper.ZooKeeperWatcher: hconnection-0x1e67b872-0x153e135af570008 connected
[main] client.ZooKeeperRegistry: Looking up meta region location in ZK, connection=org.apache.hadoop.hbase.client.ZooKeeperRegistry@69b794e2
[main] client.ZooKeeperRegistry: Looked up meta region location, connection=org.apache.hadoop.hbase.client.ZooKeeperRegistry@69b794e2; serverName=sachin-pc,55964,1459772310378
[main] client.MetaCache: Cached location: [region=hbase:meta,,1.1588230740, hostname=sachin-pc,55964,1459772310378, seqNum=0]
[hconnection-0x1e67b872-shared--pool1-t1] ipc.AbstractRpcClient: Connecting to Sachin-PC/127.0.0.1:55964
java.net.SocketException: Socket is closed
at sun.nio.ch.SocketAdaptor.getOutputStream(Unknown Source)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.closeConnection(RpcClientImpl.java:429)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.handleConnectionFailure(RpcClientImpl.java:477)
java.net.SocketException: Socket is closed
at sun.nio.ch.SocketAdaptor.getInputStream(Unknown Source)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.closeConnection(RpcClientImpl.java:436)
at org.apache.hadoop.hbase.ipc.RpcClientImpl$Connection.handleConnectionFailure(RpcClientImpl.java:477)
[hconnection-0x1e67b872-shared--pool1-t1] ipc.AbstractRpcClient: IPC Client (1890187342) connection to Sachin-PC/127.0.0.1:55964 from Sachin: marking at should close, reason: Connection refused: no further information
答案 0 :(得分:0)
我想出了这个问题。 区域服务器正在侦听192.168.1.102:55964而不是127.0.0.1:55964。 192.168.1.102是我的机器的IP,Sachin-PC是我的机器名。
在主持人中,我的参赛作品是 127.0.0.1 localhost.localdomain localhost Sachin-PC
我从那里删除了Sachin-PC,现在可以使用了。客户端现在连接到192.168.1.102:55964。
但我不明白一件事: 在regionservers中我指定:127.0.0.1 另外在我指定的hbase-site.xml中 hbase.zookeeper.quorum为127.0.0.1
当我做netstat时,我看到zookeeper,master,master web UI,区域服务器web UI都在0.0.0.0收听 但是,regionserver监听192.168.1.102,这是我机器的IP地址。
那么为什么regionserver会在不同的IP上进行监听。
还有一件事,当我启动hbase时,我看不到生成的日志文件。如何指定要生成的日志文件。