最近公司大資料叢集統一更新了 kerberos,那原先 的opentsdb就不能使用了,需要使用keytab方式登陸驗證。
在百度找了好久沒找到解決方案,還是組裡勇哥看opentsdb源碼才發現opentsdb怎麼驗證keytab.
下面是具體代碼片斷:
未使用kerberos 時候,直接使用下面的舊代碼:
HBaseClient hbaseClient = new HBaseClient(zookeeper);
激活了kerberos需要:
複制
System.setProperty("java.security.auth.login.config", "D:/kbs/ksm_jaas.conf");
System.setProperty("zookeeper.sasl.client", "false");
//下面行隻在本地打開
System.setProperty("java.security.krb5.conf", "D:/kbs/krb5.conf");
org.hbase.async.Config asyncConfig = new org.hbase.async.Config();
asyncConfig.overrideConfig("hbase.zookeeper.quorum", zookeeper);
asyncConfig.overrideConfig("hbase.security.auth.enable", "true");
asyncConfig.overrideConfig("hbase.security.authentication", "kerberos");
asyncConfig.overrideConfig("hbase.sasl.clientconfig", "Client");
asyncConfig.overrideConfig("hbase.kerberos.regionserver.principal", "hbase/[email protected]");
HBaseClient hbaseClient = new HBaseClient(asyncConfig);
//認證
KerberosClientAuthProvider authProvider = new KerberosClientAuthProvider(hbaseClient);
需要注意的是maven jar包,低版本的opentsdb的确不支援kerberos
複制
<dependency>
<groupId>net.opentsdb</groupId>
<artifactId>opentsdb</artifactId>
<version>2.3.0-RC1</version>
</dependency>
複制
<dependency>
<groupId>org.hbase</groupId>
<artifactId>asynchbase</artifactId>
<version>1.7.2</version>
</dependency>
複制