连接Hbase集群的客户端配置和依赖

因为Hbase的Master有可能转移,所有客户端需要访问ZooKeeper来获得现在的位置。ZooKeeper会保存这些值。因此客户端必须知道Zookeeper集群的地址,否则做不了任何事情。通常这个地址存在 hbase-site.xml 里面,客户端可以从CLASSPATH取出这个文件.

如果你是使用一个IDE来运行Hbase客户端,你需要将conf/放入你的 classpath,这样 hbase-site.xml就可以找到了,(或者把hbase-site.xml放到 src/test/resources,这样测试的时候可以使用).

Hbase客户端最小化的依赖是 hbase, hadoop, log4j,commons-logging, commons-lang, 和 ZooKeeper ,这些jars 需要能在 CLASSPATH 中找到。

下面是一个基本的客户端 hbase-site.xml 例子:

 

<?xml version="1.0"?><?xml-stylesheettype="text/xsl"href="configuration.xsl"?><configuration>  <property>    <name>hbase.zookeeper.quorum</name>   <value>example1,example2,example3</value>    <description>The directory shared byregion servers.   </description> </property></configuration>

3.7.1. Java客户端配置

Java是如何读到hbase-site.xml 的内容的

Java客户端使用的配置信息是被映射在一个HBaseConfiguration 实例中. HBaseConfiguration有一个工厂方法, HBaseConfiguration.create();,运行这个方法的时候,他会去CLASSPATH,下找hbase-site.xml,读他发现的第一个配置文件的内容。 (这个方法还会去找hbase-default.xml ; hbase.X.X.X.jar里面也会有一个an hbase-default.xml). 不使用任何hbase-site.xml文件直接通过Java代码注入配置信息也是可以的。例如,你可以用编程的方式设置ZooKeeper信息,只要这样做:

 

Configuration config =HBaseConfiguration.create();config.set("hbase.zookeeper.quorum","localhost");  // Here we arerunning zookeeper locally

如果有多ZooKeeper实例,你可以使用逗号列表。(就像在hbase-site.xml 文件中做得一样). 这个 Configuration 实例会被传递到 HTable, 之类的实例里面去.

 


[10] Be careful editing XML. Make sure you close all elements. Run yourfile through xmllint or similar to ensure well-formedness ofyour document after an edit session.

[11] 参见 Section B.2,“ hbase.regionserver.codecs ” 可以看到关于LZO安装的具体信息,帮助你放在安装失败。

[12] What follows is taken from the javadoc at the head ofthe org.apache.hadoop.hbase.util.RegionSplitter tool added to HBasepost-0.90.0 release.

更多精彩内容请关注:http://www.crxy.cn 

扫一扫关注超人学院微信:


转载于:https://my.oschina.net/crxy/blog/601357

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值