Flink On Yarn提交方式

Flink On Yarn提交方式

1.前言

Flink On Yarn(1.13版本)官网链接:

https://nightlies.apache.org/flink/flink-docs-release-1.13/zh/docs/deployment/resource-providers/yarn/

与其网上各说纷纭,还不如看官网,下面所有的言论都出自该页面。

2.环境准备

  • 确认是否有yarn环境
#运行如下命令,不报错就表示yarn环境OK。
yarn top
  • 确认是否有HADOOP_CLASSPATH
#运行如下命令,有输出就表示HADOOP_CLASSPATH有值。
echo $HADOOP_CLASSPATH

3.get started

# we assume to be in the root directory of 
# the unzipped Flink distribution

# (0) export HADOOP_CLASSPATH
export HADOOP_CLASSPATH=`hadoop classpath`

# (1) Start YARN Session
./bin/yarn-session.sh --detached

# (2) You can now access the Flink Web Interface through the
# URL printed in the last lines of the command output, or through
# the YARN ResourceManager web UI.

# (3) Submit example job
./bin/flink run ./examples/streaming/TopSpeedWindowing.jar

# (4) Stop YARN session (replace the application id based 
# on the output of the yarn-session.sh command)
echo "stop" | ./bin/yarn-session.sh -id application_XXXXX_XXX

这就是 一个flink on yarn的demo。上述就是教你如何使用flink on yarn的。

根据上面的demo,下面就来详细说说,flink on yarn的一些模式。

4.Flink On Yarn有哪些模式

官网的说法,3个模式:

  • application 模式
#提交一个jar任务
./bin/flink run-application -t yarn-application ./examples/streaming/TopSpeedWindowing.jar

# List running job on the cluster,查看任务
./bin/flink list -t yarn-application -Dyarn.application.id=application_XXXX_YY

# Cancel running job,取消任务,取消后集群也就停止了。
./bin/flink cancel -t yarn-application -Dyarn.application.id=application_XXXX_YY <jobId>

#可以预先把jar准备到hdfs上,这样可以节省IO的消耗。
./bin/flink run-application -t yarn-application \
-Dyarn.provided.lib.dirs="hdfs://myhdfs/my-remote-flink-dist-dir" \
hdfs://myhdfs/jars/my-application.jar
  • per-job 模式
#提交一个jar任务
./bin/flink run -t yarn-per-job --detached ./examples/streaming/TopSpeedWindowing.jar

# List running job on the cluster,查看任务
./bin/flink list -t yarn-per-job -Dyarn.application.id=application_XXXX_YY

# Cancel running job,取消任务
./bin/flink cancel -t yarn-per-job -Dyarn.application.id=application_XXXX_YY <jobId>

任务取消后,集群也就停止了。

  • session 模式
  • attached mode (default): The yarn-session.sh client submits the Flink cluster to YARN, but the client keeps running, tracking the state of the cluster. If the cluster fails, the client will show the error. If the client gets terminated, it will signal the cluster to shut down as well.
  • detached mode (-d or --detached): The yarn-session.sh client submits the Flink cluster to YARN, then the client returns. Another invocation of the client, or YARN tools is needed to stop the Flink cluster.
#session模式有2种,分别是attached模式和detached模式。
attached模式,client端在客户端启动,会伴随任务的运行。类似于spark的client模式。

detached模式,任务提交后,客户端就退出了。类似于spark的cluster模式。

生产环境下,推荐使用application或者per-job模式。可以更好地进行资源隔离。

5.Flink On Yarn如何提交任务

  • application模式提交方式
#提交一个jar任务
./bin/flink run-application -t yarn-application ./examples/streaming/TopSpeedWindowing.jar


#或者可以预先把jar准备到hdfs上,这样可以节省IO的消耗。
./bin/flink run-application -t yarn-application \
-Dyarn.provided.lib.dirs="hdfs://myhdfs/my-remote-flink-dist-dir" \
hdfs://myhdfs/jars/my-application.jar
  • per-job模式提交方式
#提交一个jar任务,以attached方式,类似于spark的client模式,默认
./bin/flink run -t yarn-per-job --attached ./examples/streaming/TopSpeedWindowing.jar

#以detached方式,类似于spark的cluster模式
./bin/flink run -t yarn-per-job --detached ./examples/streaming/TopSpeedWindowing.jar
  • session模式提交方式
#提交格式一,使用flink run 提交
./bin/flink run -t yarn-session \
  -Dyarn.application.id=application_XXXX_YY \
  ./examples/streaming/TopSpeedWindowing.jar
  
#提交格式二,使用yarn-session命令提交
./bin/yarn-session.sh -id application_XXXX_YY

6.其他

官网还有几个模块,包括在yarn上配置flink、资源分配、yarn高可用、hadoop版本支持、flink on yarn任务穿透、jar和classpath等。在此就不细述了,改天使用到了再来补充。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值