【Flink系列六】构建实时计算平台——Flink 1.10+通过Kerberos连接HiveCatalog
1.【Flink系列二十】Flink Example AsyncIOExample long running 应用程序的应用2.【Flink系列二十一】深入理解 JVM的类型加载约束,解决 Flink 类型加载冲突问题的通用方法3.【Flink系列十九】Flink 作业Hadoop 依赖冲突解决NoSuchMethodError4.HDFS_DELEGATION_TOKEN过期的问题解决汇总5.【Flink系列十八】History Server 重新登场,如何实现Yarn日志集成6.【Flink系列十七】Flink 最新yarn-application和yarn-per-job部署模式的Classpath传递分析7.【Flink系列十六】PrometheusPushGatewayReporter 限流压力过大解决8.【Flink系列十五】FLINK-24950 registerTemporaryFunction NullPointerException9.【Flink系列十四】Flink JVM参数不生效的问题分析和解决10.【Flink系列十三】Flink-Kafka-Connector KafkaSource FlinkKafkaConsumer没有上报指标11.【Flink系列十二】使用OpenResty 在InfluxDB协议层拦截Flink指标12.【Flink系列十一】FlinkSQL Gateway以及支持Kerberos多租户的实现思路13.【Flink系列十】Flink作业提交过程的调试和诊断14.【Flink系列九】Flink 作业提交遇到的问题记录以及原理15.【Flink系列八】构建实时计算平台——动态加载Catalog中的UDF16.【Flink系列零】构建实时计算平台——FlinkSQL 作业菜鸟笔记17.【Flink系列七】构建实时计算平台——校验FlinkSQL
18.【Flink系列六】构建实时计算平台——Flink 1.10+通过Kerberos连接HiveCatalog
19.【Flink系列五】构建实时计算平台——flink-connector-hive连接HiveMetastore遇到问题20.【Flink系列四】构建实时计算平台——Flink SQLClient启动失败的问题笔记21.【Flink系列三】构建实时计算平台——特别篇,Influxdb Java客户端访问指标数据22.【Flink系列二】构建实时计算平台——特别篇,用InfluxDb收集Flink Metrics23.【Flink系列一】构建实时计算平台——Flink开启和恢复Checkpoint背景
因为要开发Flinksql,决定要使用HiveCatalog的支持,Flink当前最新版本是1.12.2,集群Hive的版本是1.1.0,而且需要用某个Linux用户进行代理。
在实际开发中,遇到两个问题:
- Hive 1.1.0 使用的不是jdbc,而是 MetastoreClient,通过Thrift进行连接,而他不支持HADOOP_PROXY_USER。
- Kerberos认证需要什么配置文件,是否需要在代码里配置UGI?
问题一:HADOOP_PROXY_USER支持
这个问题上一篇文章 已经给出解决方案。
具体请参考:hive-metastore(HIVE-15579)
Github代码CommitGithub链接
问题二:Kerberos认证需要什么配置文件,是否需要在代码里配置UGI?
经过测试,发现并不需要在代码中写任何 UserGroupInformation 和 doAs 相关的代码。
需要的配置文件如下:
hive-site.xml
<!--First created by Slankka-->
<configuration>
<property>
<name>hive.metastore.uris</name>
<value>thrift://xxxxx.xxxxx.xxxxxx.com:xxxxx</value>
</property>
<property>
<name>hive.metastore.client.socket.timeout</name>
<value>300</value>
</property>
<!--property>
<name>hive.metastore.execute.setugi</name>
<value>slankka</value>
</property-->
<property>
<name>hive.cluster.delegation.token.store.class</name>
<value>org.apache.hadoop.hive.thrift.MemoryTokenStore</value>
</property>
<!--property>
<name>hive.server2.enable.doAs</name>
<value>true</value>
</property-->
<property>
<name>hive.metastore.sasl.enabled</name>
<value>true</value>
</property>
<!--property>
<name>hive.server2.authentication</name>
<value>kerberos</value>
</property-->
<property>
<name>hive.metastore.kerberos.principal</name>
<value>hive/_HOST@slankka.COM</value>
</property>
<property>
<name>hive.server2.authentication.kerberos.principal</name>
<value>hive/_HOST@slankka.COM</value>
</property>
</configuration>
另外还需要一个文件:
core-site.xml
<configuration>
<property>
<name>hadoop.security.authentication</name>
<value>kerberos</value>
</property>
</configuration>
这样在程序启动的时候,只需要指定这两个配置文件即可。
另外不需要任何HADOOP_CONF_DIR或者HIVE_CONF_DIR。
以上内容就是最小化配置。
代码示例:
public static void main(String[] args) {
Catalog catalog = new HiveCatalog("slankka", "flink", args[0], args[1], "1.1.0");
try {
// List<String> strings = catalog.listDatabases();
// for (String database : strings) {
// System.out.println(database);
// }
// ObjectPath objectPath = new ObjectPath("flink", "objectName");
// catalog.createFunction(objectPath, new CatalogFunctionImpl("className", FunctionLanguage.JAVA), false);
// catalog.dropFunction(objectPath, false);
// catalog.alterFunction(objectPath, new CatalogFunctionImpl("className", FunctionLanguage.JAVA), false);
// CatalogFunction function = catalog.getFunction(objectPath);
// catalog.listFunctions("flink");
// catalog.createTable(objectPath, new CatalogTableImpl());
catalog.open();
EnvironmentSettings settings = EnvironmentSettings.newInstance().useBlinkPlanner().build();
TableEnvironment tableEnv = TableEnvironment.create(settings);
String[] strings = tableEnv.listCatalogs();
Arrays.stream(strings).forEach(System.out::println);
boolean pfc = Arrays.asList(strings).contains("slankka");
if (!pfc) {
tableEnv.registerCatalog("slankka", catalog);
}
tableEnv.useCatalog("slankka");
tableEnv.useDatabase("flink");
tableEnv.executeSql("drop table if exists slankka.flink.WordCountSink");
TableResult tableResult = tableEnv.executeSql("create table slankka.flink.WordCountSink (\n" +
" word STRING,\n" +
" len INT\n" +
") WITH (\n" +
" 'connector' = 'jdbc',\n" +
" 'url' = 'jdbc:mysql://slankka.com:3306/rtc',\n" +
" 'table-name' = 'flink_sink_test',\n" +
" 'username' = 'root',\n" +
" 'password' = '1'\n" +
")");
tableResult.print();
String[] tables = tableEnv.listTables();
System.out.println("Tables: --->");
Arrays.stream(tables).forEach(System.out::println);
} finally {
catalog.close();
}
}
}
执行结果如下:
21/03/15 15:23:08 INFO hive.HiveCatalog: Setting hive conf dir as /data/work/cloudservice/slankka/lib/
21/03/15 15:23:09 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
21/03/15 15:23:09 INFO hive.HiveCatalog: Created HiveCatalog 'slankka'
21/03/15 15:23:09 INFO hive.metastore: HADOOP_PROXY_USER is set. Using delegation token for HiveMetaStore connection.
21/03/15 15:23:09 INFO hive.metastore: Trying to connect to metastore with URI thrift://xxxxx.xxxxx.xxxxx.com:xxxx
21/03/15 15:23:09 INFO hive.metastore: Opened a connection to metastore, current connections: 1
21/03/15 15:23:09 INFO hive.metastore: Connected to metastore.
21/03/15 15:23:09 INFO hive.metastore: Closed a connection to metastore, current connections: 0
21/03/15 15:23:09 INFO hive.metastore: Trying to connect to metastore with URI thrift://xxxxx.xxxxx.xxxxx.com:xxxx
21/03/15 15:23:09 INFO hive.metastore: Opened a connection to metastore, current connections: 1
21/03/15 15:23:09 INFO hive.metastore: Connected to metastore.
21/03/15 15:23:09 INFO hive.HiveCatalog: Connected to Hive metastore
default_catalog
21/03/15 15:23:10 INFO catalog.CatalogManager: Set the current default catalog as [slankka] and the current default database as [flink].
+--------+
| result |
+--------+
| OK |
+--------+
1 row in set
Tables: --->
wordcountsink
合集:
助力长期平稳运行大数据作业
分类:
构建实时计算平台
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!