我有一个容器化的flink群集,其中包含一个独立的JobManager和2个任务管理器。当我提交仅包含我需要的连接器和代码的胖jar时,一切运行良好,但是仅包含我的代码的jar将失败-即使我已将连接器jar添加到/ opt / flink / lib并且容器进程显示它们将被添加到类路径。当我尝试从IDE进行远程连接时,也会发生相同的故障;不用说,每次都必须捆绑一个胖子,这会带来惨痛的开发经验。
我需要做些什么以使flink理解我在/ opt / flink / lib中放置的其他jar应该与所有新作业一起使用?
类加载器异常:
org.apache.flink.streaming.runtime.tasks.StreamTaskException:无法 加载用户类: org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer
flink Dockerfile:
FROM flink:1.7.2
ADD http://central.maven.org/maven2/org/apache/flink/flink-connector-kafka_2.12/1.7.2/flink-connector-kafka_2.12-1.7.2.jar /opt/flink/lib/
ADD http://central.maven.org/maven2/org/apache/flink/flink-avro-confluent-registry/1.7.2/flink-avro-confluent-registry-1.7.2.jar /opt/flink/lib/
ADD http://central.maven.org/maven2/org/apache/flink/flink-connector-elasticsearch6_2.12/1.7.2/flink-connector-elasticsearch6_2.12-1.7.2.jar /opt/flink/lib/
工作管理器容器:
root@2406b722dae1:/tmp# ps ax | more
PID TTY STAT TIME COMMAND
1 ? Ssl 1:01 /docker-java-home/jre/bin/java -Xms1024m -Xmx1024m -Dlog4j.configuration=file:/opt/flink/conf/log4j-console.properties -Dlogback.configurationFil
e=file:/opt/flink/conf/logback-console.xml -classpath /opt/flink/lib/flink-avro-confluent-registry-1.7.2.jar:/opt/flink/lib/flink-connector-elasticsearch6_2.12-1.7.2.jar:/o
pt/flink/lib/flink-connector-kafka_2.12-1.7.2.jar:/opt/flink/lib/flink-python_2.12-1.7.2.jar:/opt/flink/lib/log4j-1.2.17.jar:/opt/flink/lib/slf4j-log4j12-1.7.15.jar:/opt/fl
ink/lib/flink-dist_2.12-1.7.2.jar::: org.apache.flink.runtime.entrypoint.StandaloneSessionClusterEntrypoint --configDir /opt/flink/conf --executionMode cluster
任务管理器容器:
root@bd1aa6e35b5a:/tmp# ps ax | more
PID TTY STAT TIME COMMAND
1 ? Ssl 0:28 /docker-java-home/jre/bin/java -XX:+UseG1GC -Xms922M -Xmx922M -XX:MaxDirectMemorySize=8388607T -Dlog4j.configuration=file:/opt/flink/conf/log4j-c
onsole.properties -Dlogback.configurationFile=file:/opt/flink/conf/logback-console.xml -classpath /opt/flink/lib/flink-avro-confluent-registry-1.7.2.jar:/opt/flink/lib/flin
k-connector-elasticsearch6_2.12-1.7.2.jar:/opt/flink/lib/flink-connector-kafka_2.12-1.7.2.jar:/opt/flink/lib/flink-python_2.12-1.7.2.jar:/opt/flink/lib/log4j-1.2.17.jar:/op
t/flink/lib/slf4j-log4j12-1.7.15.jar:/opt/flink/lib/flink-dist_2.12-1.7.2.jar::: org.apache.flink.runtime.taskexecutor.TaskManagerRunner --configDir /opt/flink/conf
正在运行的JobManager和TaskManager上的/ opt / flink / lib:
root@bd1aa6e35b5a:/opt/flink/lib# ls -lh
total 84M
-rw------- 1 root root 2.7M Feb 11 16:25 flink-avro-confluent-registry-1.7.2.jar
-rw------- 1 root root 30K Feb 11 16:21 flink-connector-elasticsearch6_2.12-1.7.2.jar
-rw------- 1 root root 67K Feb 11 16:24 flink-connector-kafka_2.12-1.7.2.jar
-rw-r--r-- 1 flink flink 81M Feb 11 14:50 flink-dist_2.12-1.7.2.jar
-rw-r--r-- 1 flink flink 139K Feb 11 14:49 flink-python_2.12-1.7.2.jar
-rw-rw-r-- 1 flink flink 479K Feb 11 14:32 log4j-1.2.17.jar
-rw-rw-r-- 1 flink flink 9.7K Feb 11 14:32 slf4j-log4j12-1.7.15.jar
以防万一-班级在预期的罐子里
root@bd1aa6e35b5a:/opt/flink/lib# unzip -l flink-connector-kafka_2.12-1.7.2.jar | grep FlinkKafkaConsumer
14272 2019-02-12 00:24 org/apache/flink/streaming/connectors/kafka/FlinkKafkaConsumer.class
答案 0 :(得分:0)
我知道了。我的第一个问题是flink在flink用户下运行,从清单中可以看出,我在Dockerfile中添加的文件由root拥有。之后我遇到的问题是sbt-assembly为您捆绑了所有传递性依赖项,您必须在Dockerfile中手动进行此操作(胖jar文件大小和我添加的文件之间的差异应该已经消除了)。
我修复了Dockerfile的所有权问题和Kafka连接器的传递依赖项(elasticsearch可能仍然缺少很多依赖项):
FROM flink:1.7.2
ADD --chown=flink:flink http://central.maven.org/maven2/org/apache/flink/flink-connector-kafka_2.12/1.7.2/flink-connector-kafka_2.12-1.7.2.jar /opt/flink/lib/
ADD --chown=flink:flink http://central.maven.org/maven2/org/apache/flink/flink-connector-kafka-base_2.12/1.7.2/flink-connector-kafka-base_2.12-1.7.2.jar /opt/flink/lib/
ADD --chown=flink:flink http://central.maven.org/maven2/org/apache/flink/flink-avro/1.7.2/flink-avro-1.7.2.jar /opt/flink/lib/
ADD --chown=flink:flink http://central.maven.org/maven2/org/apache/flink/flink-json/1.7.2/flink-json-1.7.2.jar /opt/flink/lib/
ADD --chown=flink:flink http://central.maven.org/maven2/org/apache/avro/avro/1.8.2/avro-1.8.2.jar /opt/flink/lib/
ADD --chown=flink:flink http://central.maven.org/maven2/org/apache/kafka/kafka-clients/0.10.2.1/kafka-clients-0.10.2.1.jar /opt/flink/lib/
ADD --chown=flink:flink http://central.maven.org/maven2/net/jpountz/lz4/lz4/1.3.0/lz4-1.3.0.jar /opt/flink/lib/
ADD --chown=flink:flink http://central.maven.org/maven2/org/xerial/snappy/snappy-java/1.1.2.6/snappy-java-1.1.2.6.jar /opt/flink/lib/
ADD --chown=flink:flink http://central.maven.org/maven2/org/apache/flink/flink-avro-confluent-registry/1.7.2/flink-avro-confluent-registry-1.7.2.jar /opt/flink/lib/
ADD --chown=flink:flink http://central.maven.org/maven2/org/apache/flink/flink-connector-elasticsearch6_2.12/1.7.2/flink-connector-elasticsearch6_2.12-1.7.2.jar /opt/flink/lib/