我正在尝试使用java客户端(使用Cloudera-quickstart-vm-5.5.0.0-vmware播放器)将数据加载到hbase中。
代码:
package com.hbase.stock.record;
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 HbaseStockRecord
{
public static void main(String[] args) throws IOException
{
//HBaseConfiguration hconfig = new HBaseConfiguration(new Configuration());
Configuration con = HBaseConfiguration.create();
HTableDescriptor htable = new HTableDescriptor("User");
htable.addFamily( new HColumnDescriptor("Id"));
htable.addFamily( new HColumnDescriptor("Name"));
System.out.println( "Connecting..." );
HBaseAdmin hbase_admin = new HBaseAdmin( con );
System.out.println( "Creating Table..." );
hbase_admin.createTable( htable );
System.out.println("Done!");
}
}
但是当我通过eclipse执行程序时,我收到以下错误
Connecting...
16/04/23 03:12:07 INFO zookeeper.RecoverableZooKeeper: Process identifier=hconnection-0x64c182ee connecting to ZooKeeper ensemble=localhost:2181
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:zookeeper.version=3.4.5-cdh5.5.0--1, built on 11/09/2015 20:31 GMT
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:host.name=quickstart.cloudera
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:java.version=1.7.0_67
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:java.vendor=Oracle Corporation
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:java.home=/usr/java/jdk1.7.0_67-cloudera/jre
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:java.class.path=/home/cloudera/workspace/Hbase_Stockrecord/bin:/usr/lib/hbase/lib/activation-1.1.jar:/usr/lib/hbase/lib/apacheds-i18n-2.0.0-M15.jar:/usr/lib/hbase/lib/apacheds-kerberos-codec-2.0.0-M15.jar:/usr/lib/hbase/lib/api-asn1-api-1.0.0-M20.jar:/usr/lib/hbase/lib/api-util-1.0.0-M20.jar:/usr/lib/hbase/lib/asm-3.2.jar:/usr/lib/hbase/lib/avro.jar:/usr/lib/hbase/lib/commons-beanutils-1.7.0.jar:/usr/lib/hbase/lib/commons-beanutils-core-1.8.0.jar:/usr/lib/hbase/lib/commons-cli-1.2.jar:/usr/lib/hbase/lib/commons-codec-1.9.jar:/usr/lib/hbase/lib/commons-collections-3.2.1.jar:/usr/lib/hbase/lib/commons-compress-1.4.1.jar:/usr/lib/hbase/lib/commons-configuration-1.6.jar:/usr/lib/hbase/lib/commons-daemon-1.0.3.jar:/usr/lib/hbase/lib/commons-digester-1.8.jar:/usr/lib/hbase/lib/commons-el-1.0.jar:/usr/lib/hbase/lib/commons-httpclient-3.1.jar:/usr/lib/hbase/lib/commons-io-2.4.jar:/usr/lib/hbase/lib/commons-lang-2.6.jar:/usr/lib/hbase/lib/commons-logging-1.2.jar:/usr/lib/hbase/lib/commons-math3-3.1.1.jar:/usr/lib/hbase/lib/commons-math-2.1.jar:/usr/lib/hbase/lib/commons-net-3.1.jar:/usr/lib/hbase/lib/core-3.1.1.jar:/usr/lib/hbase/lib/curator-client-2.7.1.jar:/usr/lib/hbase/lib/curator-framework-2.7.1.jar:/usr/lib/hbase/lib/curator-recipes-2.7.1.jar:/usr/lib/hbase/lib/disruptor-3.3.0.jar:/usr/lib/hbase/lib/findbugs-annotations-1.3.9-1.jar:/usr/lib/hbase/lib/gson-2.2.4.jar:/usr/lib/hbase/lib/guava-12.0.1.jar:/usr/lib/hbase/lib/hamcrest-core-1.3.jar:/usr/lib/hbase/lib/hbase-annotations-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-annotations-1.0.0-cdh5.5.0-tests.jar:/usr/lib/hbase/lib/hbase-checkstyle-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-client-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-common-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-common-1.0.0-cdh5.5.0-tests.jar:/usr/lib/hbase/lib/hbase-examples-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-hadoop2-compat-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-hadoop2-compat-1.0.0-cdh5.5.0-tests.jar:/usr/lib/hbase/lib/hbase-hadoop-compat-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-hadoop-compat-1.0.0-cdh5.5.0-tests.jar:/usr/lib/hbase/lib/hbase-it-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-it-1.0.0-cdh5.5.0-tests.jar:/usr/lib/hbase/lib/hbase-prefix-tree-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-protocol-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-rest-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-server-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-server-1.0.0-cdh5.5.0-tests.jar:/usr/lib/hbase/lib/hbase-shell-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-testing-util-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/hbase-thrift-1.0.0-cdh5.5.0.jar:/usr/lib/hbase/lib/high-scale-lib-1.1.1.jar:/usr/lib/hbase/lib/hsqldb-1.8.0.10.jar:/usr/lib/hbase/lib/htrace-core.jar:/usr/lib/hbase/lib/htrace-core4-4.0.1-incubating.jar:/usr/lib/hbase/lib/htrace-core-3.2.0-incubating.jar:/usr/lib/hbase/lib/httpclient-4.2.5.jar:/usr/lib/hbase/lib/httpcore-4.2.5.jar:/usr/lib/hbase/lib/jackson-core-asl-1.8.8.jar:/usr/lib/hbase/lib/jackson-jaxrs-1.8.8.jar:/usr/lib/hbase/lib/jackson-mapper-asl-1.8.8.jar:/usr/lib/hbase/lib/jackson-xc-1.8.8.jar:/usr/lib/hbase/lib/jamon-runtime-2.3.1.jar:/usr/lib/hbase/lib/jasper-compiler-5.5.23.jar:/usr/lib/hbase/lib/jasper-runtime-5.5.23.jar:/usr/lib/hbase/lib/java-xmlbuilder-0.4.jar:/usr/lib/hbase/lib/jaxb-api-2.1.jar:/usr/lib/hbase/lib/jaxb-impl-2.2.3-1.jar:/usr/lib/hbase/lib/jcodings-1.0.8.jar:/usr/lib/hbase/lib/jersey-client-1.9.jar:/usr/lib/hbase/lib/jersey-core-1.9.jar:/usr/lib/hbase/lib/jersey-json-1.9.jar:/usr/lib/hbase/lib/jersey-server-1.9.jar:/usr/lib/hbase/lib/jets3t-0.9.0.jar:/usr/lib/hbase/lib/jettison-1.3.3.jar:/usr/lib/hbase/lib/jetty-6.1.26.cloudera.4.jar:/usr/lib/hbase/lib/jetty-sslengine-6.1.26.cloudera.4.jar:/usr/lib/hbase/lib/jetty-util-6.1.26.cloudera.4.jar:/usr/lib/hbase/lib/joni-2.1.2.jar:/usr/lib/hbase/lib/jruby-cloudera-1.0.0.jar:/usr/lib/hbase/lib/jsch-0.1.42.jar:/usr/lib/hbase/lib/jsp-2.1-6.1.14.jar:/usr/lib/hbase/lib/jsp-api-2.1.jar:/usr/lib/hbase/lib/jsp-api-2.1-6.1.14.jar:/usr/lib/hbase/lib/jsr305-1.3.9.jar:/usr/lib/hbase/lib/junit-4.12.jar:/usr/lib/hbase/lib/leveldbjni-all-1.8.jar:/usr/lib/hbase/lib/libthrift-0.9.2.jar:/usr/lib/hbase/lib/log4j-1.2.17.jar:/usr/lib/hbase/lib/metrics-core-2.2.0.jar:/usr/lib/hbase/lib/netty-3.6.6.Final.jar:/usr/lib/hbase/lib/netty-all-4.0.23.Final.jar:/usr/lib/hbase/lib/paranamer-2.3.jar:/usr/lib/hbase/lib/protobuf-java-2.5.0.jar:/usr/lib/hbase/lib/servlet-api-2.5.jar:/usr/lib/hbase/lib/servlet-api-2.5-6.1.14.jar:/usr/lib/hbase/lib/slf4j-api-1.7.5.jar:/usr/lib/hbase/lib/slf4j-log4j12.jar:/usr/lib/hbase/lib/snappy-java-1.0.4.1.jar:/usr/lib/hbase/lib/xercesImpl-2.9.1.jar:/usr/lib/hbase/lib/xml-apis-1.3.04.jar:/usr/lib/hbase/lib/xmlenc-0.52.jar:/usr/lib/hbase/lib/xz-1.0.jar:/usr/lib/hbase/lib/zookeeper.jar:/home/cloudera/Downloads/hadoop-core-1.2.1.jar
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:java.io.tmpdir=/tmp
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:java.compiler=<NA>
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:os.name=Linux
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:os.arch=amd64
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:os.version=2.6.32-358.el6.x86_64
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:user.name=cloudera
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:user.home=/home/cloudera
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Client environment:user.dir=/home/cloudera/workspace/Hbase_Stockrecord
16/04/23 03:12:07 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=90000 watcher=hconnection-0x64c182ee0x0, quorum=localhost:2181, baseZNode=/hbase
16/04/23 03:12:07 INFO zookeeper.ClientCnxn: Opening socket connection to server quickstart.cloudera/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
16/04/23 03:12:07 INFO zookeeper.ClientCnxn: Socket connection established, initiating session, client: /127.0.0.1:48396, server: quickstart.cloudera/127.0.0.1:2181
16/04/23 03:12:07 INFO zookeeper.ClientCnxn: Session establishment complete on server quickstart.cloudera/127.0.0.1:2181, sessionid = 0x15442866725001f, negotiated timeout = 60000
Creating Table...
16/04/23 03:12:58 INFO client.RpcRetryingCaller: Call exception, tries=10, retries=35, started=49344 ms ago, cancelled=false, msg=
16/04/23 03:13:18 INFO client.RpcRetryingCaller: Call exception, tries=11, retries=35, started=69374 ms ago, cancelled=false, msg=
我能够使用独立的hadoop和hbase-0.94.15成功执行相同的程序。但不是通过cloudera。
请提供帮助,如果需要更多信息,请与我们联系。
答案 0 :(得分:1)
你需要设置
hbase.zookeeper.quorum
hbase.zookeeper.property.clientPort
到您的Configuration
对象,如下所示
Configuration config = HBaseConfiguration.create();
config.set("hbase.zookeeper.quorum", "xxx.xx.xx.xxx");
config.set("hbase.zookeeper.property.clientPort", "2181");
并使用此Configuration对象创建HBase连接并执行操作......
Connection connection = ConnectionFactory.createConnection(config);
Admin admin = admin = connection.getAdmin();
有关详细信息,请查看this