[英]Get stuck when using java api to connect Hbase
My local environment: 我的本地环境:
OS X 10.9.2, Hbase-0.94.17, Java 1.6 OS X 10.9.2,Hbase-0.94.17,Java 1.6
My Hbase mode: standalone 我的Hbase模式:独立
I was able to do operation in shell, but when I used java api, it did not work. 我可以在shell中进行操作,但是当我使用java api时,它不起作用。
My java code: 我的Java代码:
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
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.util.Bytes;
public class MyLittleHBaseClient {
public static void main(String[] args) throws IOException {
Configuration config = HBaseConfiguration.create();
config.addResource("/Users/apple/Documents/tools/hbase-0.94.17/conf/hbase-site.xml");
HTable table = new HTable(config, "myLittleHBaseTable");
Put p = new Put(Bytes.toBytes("myLittleRow"));
p.add(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"),
Bytes.toBytes("Some Value"));
table.put(p);
Get g = new Get(Bytes.toBytes("myLittleRow"));
Result r = table.get(g);
byte [] value = r.getValue(Bytes.toBytes("myLittleFamily"),
Bytes.toBytes("someQualifier"));
String valueStr = Bytes.toString(value);
System.out.println("GET: " + valueStr);
Scan s = new Scan();
s.addColumn(Bytes.toBytes("myLittleFamily"), Bytes.toBytes("someQualifier"));
ResultScanner scanner = table.getScanner(s);
try {
for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
// print out the row we found and the columns we were looking for
System.out.println("Found row: " + rr);
}
} finally {
scanner.close();
}
}
}
Here is some of my conf doc: 这是我的一些会议文件:
export JAVA_HOME=`/usr/libexec/java_home -v '1.6*'` export HBASE_OPTS="-XX:+UseConcMarkSweepGC"
###########################################hbase-site.sh:
<configuration> <property> <name>hbase.rootdir</name> <value>file:///Users/apple/Documents/tools/hbase-0.94.17/hbase-rootdir/hbase</value> </property> <property> <name>hbase.zookeeper.property.dataDir</name> <value>/Users/apple/Documents/tools/hbase-0.94.17/hbase-zookeeper/zookeeper</value> </property> </configuration>
When I ran the java code above, I got the following information: 当我运行上面的Java代码时,我得到了以下信息:
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. 2014-03-31 13:20:15.037 java[873:1003] Unable to load realm info from SCDynamicStore
and then the console just stopped here and gave nothing more.(no more response) 然后控制台只是在这里停了下来,什么也没给。(没有更多响应)
Also I attach my /Users/apple/Documents/tools/hbase-0.94.17/logs/hbase-apple...local.log here: 另外我在这里附加我的/Users/apple/Documents/tools/hbase-0.94.17/logs/hbase-apple...local.log:
https://docs.google.com/file/d/0BxtBre5A8J61Y2k3SXNtNGs1WXM/edit
Thanks for your patient, your answer will be a great help to me :) 感谢您的耐心,您的回答将对我有很大帮助:)
In your conf file "hbase-env.sh": Instead of the lines that you are having : 在您的conf文件“ hbase-env.sh”中:而不是您所拥有的行:
export HBASE_OPTS="-XX:+UseConcMarkSweepGC"
Add : 添加:
-Djava.security.krb5.realm= -Djava.security.krb5.kdc=
So the line will be export HBASE_OPTS="-XX:+UseConcMarkSweepGC -Djava.security.krb5.realm= -Djava.security.krb5.kdc="
Look here for the context : Hadoop on OSX "Unable to load realm info from SCDynamicStore" 因此,该行将
export HBASE_OPTS="-XX:+UseConcMarkSweepGC -Djava.security.krb5.realm= -Djava.security.krb5.kdc="
在上下文中查找: Hadoop在OSX上“无法从SCDynamicStore加载领域信息“
You don't need 你不需要
Configuration config = HBaseConfiguration.create();
config.addResource("/Users/apple/Documents/tools/hbase-0.94.17/conf/hbase-site.xml");
if you add this in hbase-site.xml . 如果将其添加到hbase-site.xml中。
and add this to your hbase-site.xml : 并将其添加到您的hbase-site.xml中:
<property> <name>hbase.zookeeper.property.clientPort</name> <value>2181</value> </property>
I also met this problem. 我也遇到了这个问题。 I had config server name in hbase-site.xml rather than the IP, and my java client also stuck in this situation.
我在hbase-site.xml中有配置服务器名称,而不是IP,而我的Java客户端也陷入了这种情况。
So I set my client system host for the server name, and I solved this case. 因此,我将客户端系统主机设置为服务器名称,并解决了这种情况。
At first, You check clientPort in hbase-site.xml file: 首先,您检查hbase-site.xml文件中的clientPort:
<property>
<name>hbase.zookeeper.property.clientPort</name>
<value>2222</value>
</property>
And in java program: You must set clientPort the same as in hbase-site.xml file: 在Java程序中:必须将clientPort设置为与hbase-site.xml文件中的相同:
Configuration config = HBaseConfiguration.create();
config.set("hbase.zookeeper.property.clientPort", "2222");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.