文章目录
- 1, hbase java api
- a, 使用kerberos认证: UserGroupInformation.loginUserFromKeytab(kerberosUser, keytabPath)
- 2, 具体代码
- 2, hive java api
1, hbase java api
a, 使用kerberos认证: UserGroupInformation.loginUserFromKeytab(kerberosUser, keytabPath)
import org.apache.hadoop.security.UserGroupInformation;
2, 具体代码
- maven依赖
复制代码
1
2
3
4
5
6
7
8
9
10
11<dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>1.2.0</version> </dependency> <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-server</artifactId> <version>1.2.0</version> </dependency>
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31import com.google.protobuf.ServiceException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.*; import org.apache.hadoop.security.UserGroupInformation; import java.io.IOException; public class TestKerberosHbase { public static void main(String[] args) throws IOException, ServiceException { // 注意加载:hbase-site.xml等配置文件到resources目录下,并打入jar包 System.setProperty("java.security.krb5.realm","CDH.COM"); System.setProperty("java.security.krb5.kdc","cdh-node2"); Configuration conf = HBaseConfiguration.create(); UserGroupInformation.setConfiguration(conf); final String user = "hbase/cdh-node1@CDH.COM"; final String keyPath = "/hbase.keytab"; UserGroupInformation.loginUserFromKeytab(user, keyPath); HTable table = new HTable(conf, "t1"); System.out.println("tablename:" + new String(table.getTableName())); Scan s = new Scan(); ResultScanner rs = table.getScanner(s); for (Result r : rs) { System.out.println(r.toString()); } } }
2, hive java api
最后
以上就是等待月饼最近收集整理的关于Kerberos认证下: hbase,hive连接1, hbase java api2, hive java api的全部内容,更多相关Kerberos认证下:内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复