使用如下java代码连接hbae,然后输出hbase其中一个表的记录(输出的代码就不贴出来了):
Configuration HBASE_CONFIG = new Configuration();
HBASE_CONFIG.set("hbase.zookeeper.quorum", "192.168.2.1");
// HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181");
Configuration configuration = HBaseConfiguration.create(HBASE_CONFIG);
try {
table = new HTable(configuration,"shorturl");
} catch (IOException e) {
e.printStackTrace();
}
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.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/home/develop/repo/ch/qos/logback/logback-classic/1.0.6/logback-classic-1.0.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/home/develop/repo/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.selector.DefaultContextSelector]
把机器192.168.2.1的域名添加到文件 /ect/hosts 中:
192.168.2.1 test-192-168-2-1
具体原理参照http://stackoverflow.com论坛里的回复:点击打开链接