flink的应用部署模式
1.flink的应用部署模式应用部署模式非常简单与单作业模式类似直接执行 flink run-applicatiion 命令即可。#提交作业 bin/flink run-application -t yarn-application -c com.ycl.WordCountStreamUnboundedDemo lib/FlinkTuTorial-1.17-1.0-SNAPSHOT.jar SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/module/flink-1.17.0/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/module/hadoop-3.3.6/share/hadoop/common/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] 2026-07-01 21:49:05,623 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-flink. 2026-07-01 21:49:05,623 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-flink. 2026-07-01 21:49:05,801 WARN org.apache.flink.yarn.configuration.YarnLogConfigUtil [] - The configuration directory (/opt/module/flink-1.17.0/conf)already contains a LOG4J config file.If you want to use logback, then please delete or rename the log configuration file. 2026-07-01 21:49:06,152 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - No path for the flink jar passed. Using the location of classorg.apache.flink.yarn.YarnClusterDescriptor to locate the jar 2026-07-01 21:49:06,232 INFO org.apache.hadoop.yarn.client.ConfiguredRMFailoverProxyProvider [] - Failing over to yarnrm2 2026-07-01 21:49:06,298 INFO org.apache.hadoop.conf.Configuration [] - resource-types.xml not found 2026-07-01 21:49:06,298 INFO org.apache.hadoop.yarn.util.resource.ResourceUtils [] - Unable to find resource-types.xml. 2026-07-01 21:49:06,346 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - The configured JobManager memory is 1600 MB. YARN will allocate 2048 MB to make up an integer multiple of its minimum allocation memory (1024 MB, configured via yarn.scheduler.minimum-allocation-mb). The extra 448 MB may not be used by Flink. 2026-07-01 21:49:06,346 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - The configured TaskManager memory is 1728 MB. YARN will allocate 2048 MB to make up an integer multiple of its minimum allocation memory (1024 MB, configured via yarn.scheduler.minimum-allocation-mb). The extra 320 MBmay not be used by Flink. 2026-07-01 21:49:06,346 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Cluster specification: ClusterSpecification{masterMemoryMB1600, taskManagerMemoryMB1728, slotsPerTaskManager1} 2026-07-01 21:49:12,292 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Cannot use kerberos delegation token manager, no valid kerberos credentials provided. 2026-07-01 21:49:12,298 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Submitting application master application_1782912326958_0005 2026-07-01 21:49:12,549 INFO org.apache.hadoop.yarn.client.api.impl.YarnClientImpl [] - Submitted application application_1782912326958_0005 2026-07-01 21:49:12,549 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Waiting for the cluster to be allocated 2026-07-01 21:49:12,560 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Deploying cluster, current state ACCEPTED 2026-07-01 21:49:18,429 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - YARN application has been deployed successfully. 2026-07-01 21:49:18,430 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Found Web Interface hadoop002:16924 of application application_1782912326958_0005.#查看作业 bin/flink list -t yarn-application -Dyarn.application.idapplication_1782912326958_0005 [flinkhadoop001 flink-1.17.0]$ bin/flink list -t yarn-application -Dyarn.application.idapplication_1782912326958_0006 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/module/flink-1.17.0/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/module/hadoop-3.3.6/share/hadoop/common/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] 2026-07-01 21:51:22,515 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-flink. 2026-07-01 21:51:22,515 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-flink. 2026-07-01 21:51:22,673 WARN org.apache.flink.yarn.configuration.YarnLogConfigUtil [] - The configuration directory (/opt/module/flink-1.17.0/conf)already contains a LOG4J config file.If you want to use logback, then please delete or rename the log configuration file. 2026-07-01 21:51:22,966 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - No path for the flink jar passed. Using the location of classorg.apache.flink.yarn.YarnClusterDescriptor to locate the jar 2026-07-01 21:51:23,031 INFO org.apache.hadoop.yarn.client.ConfiguredRMFailoverProxyProvider [] - Failing over to yarnrm2 2026-07-01 21:51:23,088 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Found Web Interface hadoop003:21200 of application application_1782912326958_0006. Waiting for response... ------------------ Running/Restarting Jobs ------------------- 01.07.2026 21:51:07 : b2fd68c72f3c83b1b14578780d6f8ab4 : Flink Streaming Job (RUNNING) -------------------------------------------------------------- No scheduled jobs. 代码是在jobmanager端去解析而不是直接在客户端解析。#查看作业 bin/flink list -t yarn-application -Dyarn.application.idapplication_1782912326958_0005 [flinkhadoop001 flink-1.17.0]$ bin/flink list -t yarn-application -Dyarn.application.idapplication_1782912326958_0006 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/module/flink-1.17.0/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/module/hadoop-3.3.6/share/hadoop/common/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] 2026-07-01 21:51:22,515 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-flink. 2026-07-01 21:51:22,515 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-flink. 2026-07-01 21:51:22,673 WARN org.apache.flink.yarn.configuration.YarnLogConfigUtil [] - The configuration directory (/opt/module/flink-1.17.0/conf)already contains a LOG4J config file.If you want to use logback, then please delete or rename the log configuration file. 2026-07-01 21:51:22,966 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - No path for the flink jar passed. Using the location of classorg.apache.flink.yarn.YarnClusterDescriptor to locate the jar 2026-07-01 21:51:23,031 INFO org.apache.hadoop.yarn.client.ConfiguredRMFailoverProxyProvider [] - Failing over to yarnrm2 2026-07-01 21:51:23,088 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Found Web Interface hadoop003:21200 of application application_1782912326958_0006. Waiting for response... ------------------ Running/Restarting Jobs ------------------- 01.07.2026 21:51:07 : b2fd68c72f3c83b1b14578780d6f8ab4 : Flink Streaming Job (RUNNING) -------------------------------------------------------------- No scheduled jobs.代码是在jobmanager端去解析而不是直接在客户端解析。#取消作业bin/flink cancel -t yarn-application -Dyarn.application.idapplication_1782912326958_0008 b2fd68c72f3c83b1b14578780d6f8ab4#flink的应用模式。#flink1.11开始建议使用application模式。一个集群就是一个main方法的类。application 模式需要将 flink的依赖和 jar上传到HDFS 上。 jobmanager 就是 AM;提前上传可以减少带宽消耗。flink的依赖包jar包可以提前上传到 HDFS 上。另外自己编写的jar提前上传到 HDFS;加载flink的依赖和自己写的JAR 包都直接从HDFS 上加载。#上传 HDFS 提交。可以通过 yarn.provided.lib.dirs 配置选项指定位置将flink的依赖上传到远程。#上传 flink 的lib 和 pluginshadoop fs -mkdir /flink-disthadoop fs -put lib/ /flink-disthadoop fs -put plugins/ /flink-dist#上传自己的 jar 包到 hdfs;hadoop fs -mkdir /flink-jarshadoop fs -put FlinkTuTorial-1.17-1.0-SNAPSHOT.jar /flink-jars#提交作业 #配置了 HA 就不要 使用IP:PORT; 而是 nameservice; #单节点可以使用 ip:port #bin/flink run-application -t yarn-application -Dyarn.provided.lib.dirshdfs://hadoop001:50070/flink-dist -c com.ycl.WordCountStreamUnboundedDemo hdfs://hadoop001:50070/flink-jars/FlinkTuTorial-1.17-1.0-SNAPSHOT.jar bin/flink run-application -t yarn-application -Dyarn.provided.lib.dirshdfs://hadoopns/flink-dist -c com.ycl.WordCountStreamUnboundedDemo hdfs://hadoopns/flink-jars/FlinkTuTorial-1.17-1.0-SNAPSHOT.jar [flinkhadoop001 flink-1.17.0]$ bin/flink run-application -t yarn-application -Dyarn.provided.lib.dirshdfs://hadoopns/flink-dist -c com.ycl.WordCountStreamUnboundedDemo hdfs://hadoopns/flink-jars/FlinkTuTorial-1.17-1.0-SNAPSHOT.jar SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/module/flink-1.17.0/lib/log4j-slf4j-impl-2.17.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/module/hadoop-3.3.6/share/hadoop/common/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] 2026-07-01 22:39:22,086 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-flink. 2026-07-01 22:39:22,086 INFO org.apache.flink.yarn.cli.FlinkYarnSessionCli [] - Found Yarn properties file under /tmp/.yarn-properties-flink. 2026-07-01 22:39:22,239 WARN org.apache.flink.yarn.configuration.YarnLogConfigUtil [] - The configuration directory (/opt/module/flink-1.17.0/conf)already contains a LOG4J config file.If you want to use logback, then please delete or rename the log configuration file. 2026-07-01 22:39:22,421 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - No path for the flink jar passed. Using the location of classorg.apache.flink.yarn.YarnClusterDescriptor to locate the jar 2026-07-01 22:39:22,497 INFO org.apache.hadoop.yarn.client.ConfiguredRMFailoverProxyProvider [] - Failing over to yarnrm2 2026-07-01 22:39:22,557 INFO org.apache.hadoop.conf.Configuration [] - resource-types.xml not found 2026-07-01 22:39:22,558 INFO org.apache.hadoop.yarn.util.resource.ResourceUtils [] - Unable to find resource-types.xml. 2026-07-01 22:39:22,611 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - The configured JobManager memory is 1600 MB. YARN will allocate 2048 MB to make up an integer multiple of its minimum allocation memory (1024 MB, configured via yarn.scheduler.minimum-allocation-mb). The extra 448 MB may not be used by Flink. 2026-07-01 22:39:22,611 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - The configured TaskManager memory is 1728 MB. YARN will allocate 2048 MB to make up an integer multiple of its minimum allocation memory (1024 MB, configured via yarn.scheduler.minimum-allocation-mb). The extra 320 MBmay not be used by Flink. 2026-07-01 22:39:22,612 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Cluster specification: ClusterSpecification{masterMemoryMB1600, taskManagerMemoryMB1728, slotsPerTaskManager1} 2026-07-01 22:39:23,324 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Cannot use kerberos delegation token manager, no valid kerberos credentials provided. 2026-07-01 22:39:23,329 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Submitting application master application_1782912326958_0012 2026-07-01 22:39:23,573 INFO org.apache.hadoop.yarn.client.api.impl.YarnClientImpl [] - Submitted application application_1782912326958_0012 2026-07-01 22:39:23,573 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Waiting for the cluster to be allocated 2026-07-01 22:39:23,576 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Deploying cluster, current state ACCEPTED 2026-07-01 22:39:28,628 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - YARN application has been deployed successfully. 2026-07-01 22:39:28,629 INFO org.apache.flink.yarn.YarnClusterDescriptor [] - Found Web Interface hadoop003:13395 of application application_1782912326958_0012.这种方式下flink本身的依赖和用户可以预先上传到 HDFS,而不需要单独发送到集群这就使得作业提交更加轻量。-Dyarn.provided.lib.dirs 指定flink的自身依赖。应用模式可以实现资源隔离。可以提前上传依赖包生产环境推荐。写入数据结果展示。