简体   繁体   English

Hbase客户端无法连接到本地hbase服务器

[英]Hbase client does not connect to local hbase server

I am attempting to run simple Hbase client program which talks to Hbase server(standalone) to create a table and a single row. 我正在尝试运行简单的Hbase客户端程序,该程序与Hbase服务器(独立)通信以创建表和单行。 However, unfortunately am seeing following exception while running through intelliJ. 但是,不幸的是,在通过intelliJ运行时遇到异常。

Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
Initializing HBaseAdmin
log4j:WARN No appenders could be found for logger (org.apache.hadoop.security.Groups).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Hbase running, Creating table
Adding data into table
Exception in thread "main"  org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException: Failed 1 action: User: 1 time, 
at org.apache.hadoop.hbase.client.AsyncProcess$BatchErrors.makeException(AsyncProcess.java:205)
at org.apache.hadoop.hbase.client.AsyncProcess$BatchErrors.access$500(AsyncProcess.java:189)
at org.apache.hadoop.hbase.client.AsyncProcess.getErrors(AsyncProcess.java:1042)
at org.apache.hadoop.hbase.client.HTable.backgroundFlushCommits(HTable.java:1037)
at org.apache.hadoop.hbase.client.HTable.flushCommits(HTable.java:1352)
at org.apache.hadoop.hbase.client.HTable.put(HTable.java:963)
at HbaseSample.main(HbaseSample.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Done

Client Program: 客户计划:

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;

import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.*;

public class HbaseSample {
public static void main(String[] args) throws Exception {
    System.out.println("Initializing HBaseAdmin");
    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.zookeeper.property.clientPort","2181");
    conf.set("hbase.master", "localhost:60000");
    HBaseAdmin admin = new HBaseAdmin(conf);
    try {
        HBaseAdmin.checkHBaseAvailable(conf);
        System.out.println("Hbase running, Creating table");
        HTable table = new HTable(conf, "User");
        Put put = new Put(Bytes.toBytes("msameer"));
        put.add(Bytes.toBytes("Info"), Bytes.toBytes("addr"), Bytes.toBytes("walnut creek"));
        System.out.println("Adding data into table");
        table.put(put);
    } finally {
        admin.close();
        System.out.println("Done");
    }
  }
}

My hbase-site.xml looks as follows: 我的hbase-site.xml如下所示:

<configuration>
<property>
  <name>hbase.rootdir</name>
  <value>file:///Users/msameer/Documents/Hbase/hbase-root</value>
</property>
<property>
  <name>hbase.zookeeper.property.dataDir</name>
  <value>/Users/msameer/Documents/Hbase/hbase-zookeper</value>
</property>
<property>
   <name>hbase.zookeeper.property.clientPort</name>
   <value>2181</value>
</property>
<property>
  <name>hbase.master</name>
  <value>localhost:60000</value>
</property>
</configuration>

Any help is very much appreciated. 很感谢任何形式的帮助。

Does your table already exist? 你的桌子已经存在吗? Because this code does not create a table: 因为此代码不会创建表:

HBaseAdmin.checkHBaseAvailable(conf);
System.out.println("Hbase running, Creating table");
HTable table = new HTable(conf, "User");

This will only use a table that already exists. 这只会使用已存在的表。 To create a table, you need to use HBaseAdmin : 要创建表,您需要使用HBaseAdmin

HBaseAdmin.checkHBaseAvailable(conf);
System.out.println("Hbase running, Creating table");
HTableDescriptor des = new HTableDescriptor("User");
HBaseAdmin.createTable(des);

Take a look at the documentation for schema creation. 查看架构创建的文档 It also shows the updated API calls. 它还显示更新的API调用。 The classes starting with H are now deprecated. 现在不推荐使用以H开头的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM