【文件属性】:
文件名称:Hbase 基本操作类
文件大小:28KB
文件格式:JAVA
更新时间:2017-08-05 09:05:41
Hbase 基本操作类
Hbase 基本操作类
static {
//此处可以使用hbase的配置文件,也可以通过代码来实例化hbase连接
/*
* Configuration HBASE_CONFIG = new Configuration();
* HBASE_CONFIG.set("hbase.zookeeper.quorum", "10.229.171.45");
* HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181");
* HBASE_CONFIG.set("hbase.zookeeper.quorum","10.233.92.85,10.233.92.86,10.233.92.88");
* HBASE_CONFIG.set("hbase.zookeeper.property.clientPort", "2181");
* HBASE_CONFIG.set("zookeeper.znode.parent", "/hbase-unsecure"); conf = HBaseConfiguration.create(HBASE_CONFIG);
*/
conf = HBaseConfiguration.create();
if("kerberos".equals(conf.get("hbase.security.authentication"))){
try {
//设置hadoop.security.authentication为kerberos
conf.set("hadoop.security.authentication", "kerberos");
//获取kerberos配置文件路径(krb为kerberos配置文件)
String krbStr=Thread.currentThread().getContextClassLoader().getResource("krb").getFile();
//获取用户票据hezhong路径(hezhong为给合众分配的用户配置文件)
String keyStr=Thread.currentThread().getContextClassLoader().getResource("jdzy").getFile();
//初始化配置文件
System.setProperty("java.security.krb5.conf", krbStr);
//使用用户hezhong登录
UserGroupInformation.setConfiguration(conf);
UserGroupInformation.loginUserFromKeytab("jdzy/f04345e6-70c1-448a-9bbb-4ac6b4c0109b@POLICE.COM", keyStr);
} catch (IOException e) {
e.printStackTrace();
}
}
tablePool = new HTablePool(conf, poolsize);
logger.debug("create hbase connection success");
// System.out.println("create hbase connection success");
}
网友评论
- 挺不错的~~~~
- 还不错,很好用
- 还不错,很好用