有这样的一个业务场景-客户端通过接口访问impala Daemon,impala做查询并返回数据给到客户端;
下面通过impala jdbc访问服务方式来介绍客户端调用接口访问impala场景
访问实例前,会做kerberos认证; 通过后就允许访问相关服务
在实施方案前,假设读者已经基本熟悉以下技术 (不细说)
Java,maven
impala, hdfs,kerberos
方案实施
把kdc服务端krb5.conf拷贝到本地工程目录
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
default_realm = WONHIGH.COM
dns_lookup_realm = false
dns_lookup_kdc = false
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
[realms]
WONHIGH.COM = {
#注意这里最好改成IP,因为你部署工程的机器有可能并不知道host对应的ip
kdc = 172.17.194.20
admin_server = 172.17.194.20
}
生成的keytab文件并拷贝都工程目录下
kadmin.local: xst -norandkey -k wms_dev.keytab wms_dev@WONHIGH.COM
工程目录
keytab_krb5.png
然后就是代码了,不多说,直接上 (头晕的直接拉到最下面看效果即可)
pom.xml
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
deng.yb
impalaJdbc
0.0.1-SNAPSHOT
jar
impalaJdbc
http://maven.apache.org
UTF-8
2.5.42
junit
junit
3.8.1
test
com.cloudera
impala-jdbc41
${hive.version}
com.alibaba
fastjson
1.2.44
org.apache.hadoop
hadoop-client
2.6.5
org.apache.hive
hive-jdbc
1.1.0
\主类
package impala.kerberos;
import impala.conf.KbsConfiguration;
import impala.kerberos.callback.CallBack;
import impala.utils.Tools;
import java.io.IOException;
import java.security.PrivilegedAction;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.MessageFormat;
import org.apache.hadoop.security.UserGroupInformation;
public class KBImpalaJBDC {
private static String JDBC_DRIVER = "com.cloudera.impala.jdbc41.Driver";
private static String CONNECTION_URL = "jdbc:impala://{0}:21050/;AuthMech=1;KrbRe