我是 hadoop 和 hbase 的新手,在 windows8 中安装了 hadoop。 我启动 hadoop Like image 并通过字数统计程序测试 map-reduce 并且它的工作。(在 eclipse 中)
但是我不会用hbase!我为 eclipse 使用了一个 hbase 插件。 (来自 eclipse 市场网站) 我有一个用于连接和创建表的类,....
public class HBaseConnector {
private static Configuration configuration = null;
private static HTable hTable;
private static HBaseAdmin admin;
private static Logger logger = Logger.getLogger(HBaseConnector.class);
static {
configuration = HBaseConfiguration.create();
}
public void creatTable(String tableName, String[] familys) {
try {
admin = new HBaseAdmin(configuration);
if (admin.tableExists(tableName)) {
logger.debug(tableName + "table already exists !!");
} else {
HTableDescriptor tableDesc = new HTableDescriptor(tableName);
for (int i = 0; i < familys.length; i++) {
tableDesc.addFamily(new HColumnDescriptor(familys[i]));
}
admin.createTable(tableDesc);
logger.debug(tableName + " table created successfully !! ");
}
admin.close();
} catch (MasterNotRunningException e) {
logger.error(e.getMessage());
} catch (ZooKeeperConnectionException e) {
logger.error(e.getMessage());
} catch (IOException e) {
logger.error(e.getMessage());
}
}
在主函数中我有这些代码:
String tablename = "employee";
String[] familys = { "personal", "professional" };
HBaseConnector connector = new HBaseConnector();
connector.creatTable(tablename, familys);
但是无法连接:
18:59:34 WARN zookeeper.RecoverableZooKeeper: Possibly transient ZooKeeper exception: org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /hbase/master
16/03/18 18:59:34 INFO util.RetryCounter: Sleeping 4000ms before retry #2...
16/03/18 18:59:34 INFO zookeeper.ClientCnxn: Opening socket connection to server 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (Unable to locate a login configuration)
16/03/18 18:59:34 ERROR zookeeper.ClientCnxnSocketNIO: Unable to open socket to 0:0:0:0:0:0:0:1/0:0:0:0:0:0:0:1:2181
16/03/18 18:59:34 WARN zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.SocketException: Address family not supported by protocol family: connect
at sun.nio.ch.Net.connect(Native Method)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at org.apache.zookeeper.ClientCnxnSocketNIO.registerAndConnect(ClientCnxnSocketNIO.java:266)
at org.apache.zookeeper.ClientCnxnSocketNIO.connect(ClientCnxnSocketNIO.java:276)
at org.apache.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:958)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:993)
16/03/18 18:59:34 DEBUG zookeeper.ClientCnxnSocketNIO: Ignoring exception during shutdown input
java.nio.channels.ClosedChannelException
我如何运行一个简单的 HBase 程序?
最佳答案
在我看来,您忘记安装或启动 HBase。 HBase 是一个额外的组件,据我所知,您只运行 HDFS 和 Yarn。
你的最后一条日志消息说它无法连接到 Zookeeper。它是 Hadoop 组件的(分布式)键/值存储。您的简单 HBase 程序正在尝试连接到 Zookeeper 并获取值 /hbase/master
znode。这样做失败了,因此无法继续连接到 HBase master。
安装HBase master + 至少一台RegionServer。如果您遵循安装文档,您还将处理 Zookeeper:
https://hbase.apache.org/book.html#standalone_dist
我的个人建议:使用 1.1.3 而不是 1.2.0,除非你出于某种原因确实需要 1.2.0。我在启动 1.2.0 时遇到了问题。
关于java - 如何配置测试hbase程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36088422/