ambari中hive启用kerberos进行jdbc连接操作正确方式

启用kerberos后,有两种操作方式连接hive;

1、直接连接:

jdbc:hive2://c2eng58:10000/default;principal=hive/[email protected]

2、通过zookerper连接

jdbc:hive2://c2eng47:2181,c2eng48:2181,c2eng58:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2;

如果设置了JaasConf,注意:此处ambari中填写的zookerper必须为域名地址,不能为ip地址。否则会提示

2018-07-30 16:35:39,087 ERROR [main-SendThread(172.17.81.48:2181)]: An error: (java.security.PrivilegedActionException: javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Server not found in Kerberos database (7) - LOOKING_UP_SERVER)]) occurred when evaluating Zookeeper Quorum Member's  received SASL token. Zookeeper Client will go to AUTH_FAILED state. org.apache.zookeeper.client.ZooKeeperSaslClient(388)
2018-07-30 16:35:39,090 ERROR [main-SendThread(172.17.81.48:2181)]: SASL authentication with Zookeeper Quorum member failed: javax.security.sasl.SaslException: An error: (java.security.PrivilegedActionException: javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Server not found in Kerberos database (7) - LOOKING_UP_SERVER)]) occurred when evaluating Zookeeper Quorum Member's  received SASL token. Zookeeper Client will go to AUTH_FAILED state. org.apache.zookeeper.ClientCnxn(1059)
Exception in thread "main" java.sql.SQLException: org.apache.hive.jdbc.ZooKeeperHiveClientException: Unable to read HiveServer2 configs from ZooKeeper
    at org.apache.hive.jdbc.HiveConnection.(HiveConnection.java:137)
    at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at com.creator.bigdata.hive.example.JDBCExample.main(JDBCExample.java:153)
Caused by: org.apache.hive.jdbc.ZooKeeperHiveClientException: Unable to read HiveServer2 configs from ZooKeeper
    at org.apache.hive.jdbc.ZooKeeperHiveClientHelper.configureConnParams(ZooKeeperHiveClientHelper.java:95)
    at org.apache.hive.jdbc.Utils.configureConnParams(Utils.java:509)
    at org.apache.hive.jdbc.Utils.parseURL(Utils.java:429)
    at org.apache.hive.jdbc.HiveConnection.(HiveConnection.java:135)
    ... 4 more
Caused by: org.apache.zookeeper.KeeperException$AuthFailedException: KeeperErrorCode = AuthFailed for /hiveserver2
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:123)
    at org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
    at org.apache.zookeeper.ZooKeeper.getChildren(ZooKeeper.java:1590)
    at org.apache.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:230)
    at org.apache.curator.framework.imps.GetChildrenBuilderImpl$3.call(GetChildrenBuilderImpl.java:219)
    at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:109)
    at org.apache.curator.framework.imps.GetChildrenBuilderImpl.pathInForeground(GetChildrenBuilderImpl.java:216)
    at org.apache.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:207)
    at org.apache.curator.framework.imps.GetChildrenBuilderImpl.forPath(GetChildrenBuilderImpl.java:40)
    at org.apache.hive.jdbc.ZooKeeperHiveClientHelper.configureConnParams(ZooKeeperHiveClientHelper.java:63)
    ... 7 more
 

具体原因可以在代码中加上:System.setProperty("sun.security.krb5.debug", "true");

>>>KRBError:
     cTime is Mon Feb 04 18:00:28 CST 1974 129204028000
     sTime is Mon Jul 30 16:36:00 CST 2018 1532939760000
     suSec is 440391
     error code is 7
     error Message is Server not found in Kerberos database
     crealm is EXAMPLE.COM
     cname is zookeeper/c2eng58
     realm is EXAMPLE.COM
     sname is zookeeper/172.17.81.48
     msgType is 30

已经很明显了

你可能感兴趣的:(Hive,Kerberos)