唉,网上的资料比较少,找了好久,压根不知道如入告诉 phoenix 客户端来使用 kerberos 啊。。

然后就想到了,这东西开源的应该有相关的单元测试吧。。啊哈哈哈哈哈哈,果然

https://github.com/apache/phoenix/blob/master/phoenix-core/src/test/java/org/apache/phoenix/jdbc/SecureUserConnectionsTest.java
private String joinUserAuthentication(String origUrl, String principal, File keytab) {
StringBuilder sb = new StringBuilder(64);
// Knock off the trailing terminator if one exists
if (origUrl.charAt(origUrl.length() - 1) == PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR) {
sb.append(origUrl, 0, origUrl.length() - 1);
} else {
sb.append(origUrl);
} sb.append(PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR).append(principal);
sb.append(PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR).append(keytab.getPath());
return sb.append(PhoenixRuntime.JDBC_PROTOCOL_TERMINATOR).toString();
}

通过 url 拼接就行了!! 测试代码:

public class Main {
public static void main(String[] args) throws ClassNotFoundException, LoginException {
System.setProperty("java.security.krb5.conf", "/app/conf/krb5.conf"); Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
try (Connection connection = DriverManager.getConnection("jdbc:phoenix:node1,node2,node3:storm-miras:/app/conf/storm.headless.keytab");
PreparedStatement preparedStatement = connection.prepareStatement("select * from phoenix_krb")) {
try (ResultSet resultSet = preparedStatement.executeQuery()) {
while (resultSet.next()) {
System.out.println(resultSet.getString("content"));
}
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}

  

1243 [main] WARN  o.a.h.u.Shell - Did not find winutils.exe: java.io.FileNotFoundException: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset. -see https://wiki.apache.org/hadoop/WindowsProblems
1408 [main] INFO o.a.p.q.ConnectionQueryServicesImpl - Trying to connect to a secure cluster with keytab:/app/conf/storm.headless.keytab
1485 [main] WARN o.a.h.u.NativeCodeLoader - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
1793 [main] INFO o.a.h.s.UserGroupInformation - Login successful for user storm-miras using keytab file /app/conf/storm.headless.keytab
1793 [main] INFO o.a.p.q.ConnectionQueryServicesImpl - Successfull login to secure cluster!!
1971 [main] INFO o.a.h.h.z.RecoverableZooKeeper - Process identifier=hconnection-0x1e4d3ce5 connecting to ZooKeeper ensemble=node2:2181,node3:2181
11612 [main] WARN o.a.h.h.s.DomainSocketFactory - The short-circuit local reads feature cannot be used because UNIX Domain sockets are not available on Windows.
11664 [main] INFO o.a.p.m.Metrics - Initializing metrics system: phoenix
11728 [main] WARN o.a.h.m.i.MetricsConfig - Cannot locate configuration: tried hadoop-metrics2-phoenix.properties,hadoop-metrics2.properties
11745 [main] INFO o.a.h.m.i.MetricsSystemImpl - Scheduled snapshot period at 10 second(s).
11745 [main] INFO o.a.h.m.i.MetricsSystemImpl - phoenix metrics system started
hello
world
2017-08-30 17:03:28,854 FATAL Unable to register shutdown hook because JVM is shutting down.
0: jdbc:phoenix:> select * from phoenix_krb;
+-----+----------+
| ID | CONTENT |
+-----+----------+
| 1 | hello |
| 2 | world |
+-----+----------+
2 rows selected (0.03 seconds)
0: jdbc:phoenix:>

最新文章

  1. android Service Activity交互之传递复杂数据类型的远程服务
  2. POJ 2484
  3. DataGridView中的单元格提示错误信息
  4. 如何在 Windows Azure 的虚拟机 ubuntu 上面安装和配置 openVPN(二)
  5. 如何使用Git——(一)
  6. Docker for Windows
  7. 一、Solr综述
  8. 项目与软件推荐之编辑器-QOwnNotes(刺激自己)
  9. chrome extension overview
  10. This application failed to start because it could not find or load the Qt platform plugin "windows" 的问题原因以及解决方案
  11. 给定整数a1、a2、a3、...、an,判断是否可以从中选出若干个数,使得它们的和等于k(k任意给定,且满足-10^8 <= k <= 10^8)。
  12. 全文搜索引擎——Solr
  13. MySql中三种注释写法
  14. Linux Install redis
  15. 线性表java实现
  16. ThreadLocal和ThreadLocalMap源码分析
  17. 【BZOJ5109】[CodePlus 2017]大吉大利,晚上吃鸡! 最短路+拓扑排序+DP
  18. bug优先级定义
  19. postman 请求 页面出现 Could not get any response 解决方法
  20. unity调用ios原生代码objective-c和回调

热门文章

  1. Python执行Linux系统命令的4种方法
  2. 将CRUD封装到一个工具类中
  3. CSS继承—深入剖析
  4. 周记【距gdoi:117天】
  5. CF840C On the Bench 解题报告
  6. Tomcat-Jdbc-Pool连接池参数说明
  7. Vim使用小记(一)常用操作
  8. taotao用户注册前台页面
  9. Ubuntu下安装LNMP之Mysql的安装及卸载
  10. 在Debian9安装node和npm