无法使用 java 创建 hbase
Not able to create hbase using java
我已经编写了一个简单的 java 代码用于在 hbase 中创建 table 但不知何故它不起作用。我检查了所有服务是否正常工作,即 HMaster
、Regionserver
和 Zookeeper
。下面是我写的代码
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class CreateSchema
{
public static void main(String[] args) throws IOException
{
try
{
HBaseConfiguration conf = new HBaseConfiguration(new Configuration());
HBaseAdmin hbase = new HBaseAdmin(conf);
HTableDescriptor desc = new HTableDescriptor("sample");
HColumnDescriptor meta = new HColumnDescriptor("samplecolumn1".getBytes());
HColumnDescriptor prefix = new HColumnDescriptor("samplecolumn2".getBytes());
desc.addFamily(meta);
desc.addFamily(prefix);
System.out.println("Creating table");
hbase.createTable(desc);
System.out.println("Done");
}
catch(Exception e)
{
System.out.println("Error Ocuured");
}
}
}
这是动物园管理员日志。
2015-01-15 07:46:01,594 - INFO
[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServer``CnxnFactory@197]
- Accepted socket connection from /127.0.0.1:60599 2015-01-15 07:46:01,595 - WARN
[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@822] -
Connection request from old client /127.0.0.1:60599; will be dropped
if server is in r-o mode 2015-01-15 07:46:01,595 - INFO
[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@868] -
Client attempting to establish new session at /127.0.0.1:60599
2015-01-15 07:46:01,619 - INFO [SyncThread:0:ZooKeeperServer@617] -
Established session 0x14aec781bb9000b with negotiated timeout 40000
for client /127.0.0.1:60599 2015-01-15 07:46:37,151 - INFO
[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] -
Accepted socket connection from /10.0.2.15:58102 2015-01-15
07:46:37,152 - WARN
[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@357] - caught
end of stream exception EndOfStreamException: Unable to read
additional data from client sessionid 0x0, likely client has closed
socket
at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:228)
at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)
at java.lang.Thread.run(Thread.java:745) 2015-01-15 07:46:37,153 - INFO
[NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1007] -
Closed socket connection for client /10.0.2.15:58102 (no session
established for client)
在 运行 Hbase java 编程之后没有任何反应。
java CreateSchema
Creating table
请让我知道可能是什么问题。
发生这种情况的原因之一是您的 hbase-site.xml
在类路径中不可用。
当你运行:
HBaseConfiguration conf = new HBaseConfiguration(new Configuration());
HbaseConfiguration based the hbase-site.xml is created.
PS:我 运行 你的代码在我的 eclipse 中运行良好。 table 样本的创建没有任何错误。
我已经编写了一个简单的 java 代码用于在 hbase 中创建 table 但不知何故它不起作用。我检查了所有服务是否正常工作,即 HMaster
、Regionserver
和 Zookeeper
。下面是我写的代码
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class CreateSchema
{
public static void main(String[] args) throws IOException
{
try
{
HBaseConfiguration conf = new HBaseConfiguration(new Configuration());
HBaseAdmin hbase = new HBaseAdmin(conf);
HTableDescriptor desc = new HTableDescriptor("sample");
HColumnDescriptor meta = new HColumnDescriptor("samplecolumn1".getBytes());
HColumnDescriptor prefix = new HColumnDescriptor("samplecolumn2".getBytes());
desc.addFamily(meta);
desc.addFamily(prefix);
System.out.println("Creating table");
hbase.createTable(desc);
System.out.println("Done");
}
catch(Exception e)
{
System.out.println("Error Ocuured");
}
}
}
这是动物园管理员日志。
2015-01-15 07:46:01,594 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServer``CnxnFactory@197] - Accepted socket connection from /127.0.0.1:60599 2015-01-15 07:46:01,595 - WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@822] - Connection request from old client /127.0.0.1:60599; will be dropped if server is in r-o mode 2015-01-15 07:46:01,595 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@868] - Client attempting to establish new session at /127.0.0.1:60599 2015-01-15 07:46:01,619 - INFO [SyncThread:0:ZooKeeperServer@617] - Established session 0x14aec781bb9000b with negotiated timeout 40000 for client /127.0.0.1:60599 2015-01-15 07:46:37,151 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@197] - Accepted socket connection from /10.0.2.15:58102 2015-01-15 07:46:37,152 - WARN [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@357] - caught end of stream exception EndOfStreamException: Unable to read additional data from client sessionid 0x0, likely client has closed socket at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:228) at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208) at java.lang.Thread.run(Thread.java:745) 2015-01-15 07:46:37,153 - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxn@1007] - Closed socket connection for client /10.0.2.15:58102 (no session established for client)
在 运行 Hbase java 编程之后没有任何反应。
java CreateSchema
Creating table
请让我知道可能是什么问题。
发生这种情况的原因之一是您的 hbase-site.xml
在类路径中不可用。
当你运行:
HBaseConfiguration conf = new HBaseConfiguration(new Configuration());
HbaseConfiguration based the hbase-site.xml is created.
PS:我 运行 你的代码在我的 eclipse 中运行良好。 table 样本的创建没有任何错误。