如何配置测试hbase程序

时间:2016-03-18 15:34:36

标签: java eclipse hadoop hbase hadoop2

我是hadoop和hbase的新手,并在windows8中安装了hadoop。 我开始hadoop像图像和测试地图 - 通过字数计划减少它的工作。(在eclipse中) enter image description here

但我不能使用hbase!我使用hbase插件进行eclipse。 (来自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程序?

1 个答案:

答案 0 :(得分:1)

在我看来,你忘了安装或启动HBase。 HBase是一个额外的组件,从我看来你只运行HDFS和纱线。

您的上一条日志消息显示它无法连接到Zookeeper。它是Hadoop组件的(分布式)键/值存储。您的简单HBase程序正在尝试连接到Zookeeper并获取值/hbase/master znode。它无法执行此操作,因此无法继续并连接到HBase master。

安装HBase master +至少一个RegionServer。如果你按照安装文档,你也将处理Zookeeper:

https://hbase.apache.org/book.html#standalone_dist

我的个人建议:除非你因某种原因确实需要1.2.0,否则请使用1.1.3而不是1.2.0。我无法启动1.2.0。