Hbase 客户端 API 未连接到 Hbase
Posted
技术标签:
【中文标题】Hbase 客户端 API 未连接到 Hbase【英文标题】:Hbase client API not connecting to Hbase 【发布时间】:2016-11-18 12:18:12 【问题描述】:我正在关注this link 将数据插入我的 hbase。我按照所有步骤编写了以下代码:
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
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.KeyValue;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
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.Put;
import org.apache.hadoop.hbase.util.Bytes;
public class Startclass
private static Configuration conf = HBaseConfiguration.create();
public static void addRecord(String tableName, String rowKey,
String family, String qualifier, String value) throws Exception
try
HTable table = new HTable(conf, tableName);
Put put = new Put(Bytes.toBytes(rowKey));
put.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes
.toBytes(value));
table.put(put);
System.out.println("insert recored " + rowKey + " to table "
+ tableName + " ok.");
catch (IOException e)
e.printStackTrace();
public static void main(String[] agrs)
try
String tablename = "hl7";
Startclass.addRecord(tablename, "zkb", "pd", "dob", "10121993");
Startclass.addRecord(tablename, "zkb", "pd", "id", "007");
Startclass.addRecord(tablename, "zkb", "obr", "id", "007");
Startclass.addRecord(tablename, "zkb", "obr", "testname", "healthec");
Startclass.addRecord(tablename, "abc", "pd", "dob", "02051993");
Startclass.addRecord(tablename, "abc", "pd", "id", "011");
Startclass.addRecord(tablename, "abc", "obr", "id", "011");
Startclass.addRecord(tablename, "abc", "obr", "testname", "matrix");
catch (Exception e)
e.printStackTrace();
但我得到了低于结果
16/11/18 16:55:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.5-cdh5.8.0--1, built on 06/16/2016 19:37 GMT
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:host.name=quickstart.cloudera
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_67
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.home=/usr/java/jdk1.7.0_67-cloudera/jre
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.class.path=/home/cloudera/workspace/HbaseJav/bin:/home/cloudera/workspace/HbaseJav/conf:/usr/lib/hadoop/client/avro.jar:/usr/lib/hadoop/client/commons-beanutils-core.jar:/usr/lib/hadoop/client/commons-beanutils.jar:/usr/lib/hadoop/client/commons-cli.jar:/usr/lib/hadoop/client/commons-codec.jar:/usr/lib/hadoop/client/commons-collections.jar:/usr/lib/hadoop/client/commons-compress.jar:/usr/lib/hadoop/client/commons-configuration.jar:/usr/lib/hadoop/client/commons-digester.jar:/usr/lib/hadoop/client/commons-httpclient.jar:/usr/lib/hadoop/client/commons-io.jar:/usr/lib/hadoop/client/commons-lang.jar:/usr/lib/hadoop/client/commons-logging.jar:/usr/lib/hadoop/client/commons-math3.jar:/usr/lib/hadoop/client/commons-net.jar:/usr/lib/hadoop/client/guava.jar:/usr/lib/hadoop/client/hadoop-annotations.jar:/usr/lib/hadoop/client/hadoop-auth.jar:/usr/lib/hadoop/client/hadoop-common.jar:/usr/lib/hadoop/client/hadoop-hdfs.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-app.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-common.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-core.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-jobclient.jar:/usr/lib/hadoop/client/hadoop-mapreduce-client-shuffle.jar:/usr/lib/hadoop/client/hadoop-yarn-api.jar:/usr/lib/hadoop/client/hadoop-yarn-client.jar:/usr/lib/hadoop/client/hadoop-yarn-common.jar:/usr/lib/hadoop/client/hadoop-yarn-server-common.jar:/usr/lib/hadoop/client/htrace-core4.jar:/usr/lib/hadoop/client/jetty-util.jar:/usr/lib/hadoop/client/jsr305.jar:/usr/lib/hadoop/client/log4j.jar:/usr/lib/hadoop/client/paranamer.jar:/usr/lib/hadoop/client/protobuf-java.jar:/usr/lib/hadoop/client/slf4j-api.jar:/usr/lib/hadoop/client/snappy-java.jar:/usr/lib/hadoop/client/xmlenc.jar:/usr/lib/hadoop/client/xz.jar:/usr/lib/hadoop/client/zookeeper.jar:/home/cloudera/lib/mrunit-0.9.0-incubating-hadoop2.jar:/home/cloudera/lib/junit-4.11.jar:/home/cloudera/lib/hamcrest-all-1.1.jar:/home/cloudera/hbase-0.92.1.jar:/usr/lib/hbase/lib/commons-configuration-1.6.jar:/usr/lib/hbase/lib/commons-lang-2.6.jar:/usr/lib/hbase/lib/commons-logging-1.2.jar:/usr/lib/hbase/lib/log4j-1.2.17.jar:/usr/lib/hbase/lib/slf4j-api-1.7.5.jar:/usr/lib/hbase/lib/slf4j-log4j12.jar:/usr/lib/hbase/lib/zookeeper.jar:/usr/lib/hadoop-0.20-mapreduce/hadoop-core-2.6.0-mr1-cdh5.8.0.jar:/usr/lib/hadoop-0.20-mapreduce/hadoop-core-mr1.jar
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:os.version=2.6.32-573.el6.x86_64
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:user.name=cloudera
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:user.home=/home/cloudera
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Client environment:user.dir=/home/cloudera/workspace/HbaseJav
16/11/18 16:55:05 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=180000 watcher=hconnection
16/11/18 16:55:05 INFO zookeeper.RecoverableZooKeeper: The identifier of this process is 6315@quickstart.cloudera
16/11/18 16:55:05 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
16/11/18 16:55:05 INFO zookeeper.ClientCnxn: Socket connection established, initiating session, client: /127.0.0.1:41539, server: localhost/127.0.0.1:2181
16/11/18 16:55:05 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x15876ebae4a0138, negotiated timeout = 60000
我还创建了具有正确列族名称的 hbase 表。 我不知道我做错了什么。请帮忙。
【问题讨论】:
这里有什么问题,我没有看到任何错误日志。您是否扫描了可用的表“hl7”数据? 我扫描它没有数据存在。我看不到任何事情发生,只有这个结果即将到来,没有其他事情发生。 可以手动插入数据到表中吗?你是怎么做这份工作的?你能发布完整的日志吗 从 java 我正在运行应用程序。这是我得到的完整日志。是的,我可以手动在 hbase 中添加数据。 尝试作为hadoop作业运行 【参考方案1】:如果你运行命令 创建'hl7','pd','obr' 在运行这段代码之前,没有办法,它不会在表中插入数据。 只有这样的可能性是在传递不正确的配置或不兼容的 HBase(installation)-dependency(project) 的情况下。
【讨论】:
我通过在我的项目中添加适当的 jar 解决了这个问题。以上是关于Hbase 客户端 API 未连接到 Hbase的主要内容,如果未能解决你的问题,请参考以下文章