Flink服务的HA配置


默认情况下,每个 Flink 集群只有一个 JobManager,这将导致单点故障(SPOF),如果这个 JobManager 挂了,则不能提交新的任务,并且运行中的程序也会失败。使用JobManager HA,集群可以从 JobManager 故障中恢复,从而避免单点故障。用户可以在Standalone 或 Flink on Yarn 集群模式下配置 Flink 集群 HA(高可用性)。
Flink 的HA需要Zookeeper和HDFS,因此首先要安装启动 zk、hdfs。

Standalone 模式HA

Standalone 模式下,JobManager 的高可用性的基本思想是,任何时候都有一个 AliveJobManager 和多个 Standby JobManager。Standby JobManager 可以在 Alive JobManager挂掉的情况下接管集群成为 Alive JobManager,这样避免了单点故障,一旦某一个 StandbyJobManager 接管集群,程序就可以继续运行。Standby JobManagers 和 Alive JobManager实例之间没有明确区别,每个 JobManager 都可以成为 Alive 或 Standby。配置步骤如下

修改masters配置文件
增加master节点配置如下:

[root@server01 conf]# vi masters
server01:8081
server02:8081
server03:8081

修改 conf/flink-conf.yaml
增加高可用相关配置,配置如下配置项

high-availability: zookeeper

# The path where metadata for master recovery is persisted. While ZooKeeper stores
# the small ground truth for checkpoint and leader election, this location stores
# the larger objects, like persisted dataflow graphs.
#
# Must be a durable file system that is accessible from all nodes
# (like HDFS, S3, Ceph, nfs, ...)
#
high-availability.storageDir: hdfs://server01:9000/flink/ha

# The list of ZooKeeper quorum peers that coordinate the high-availability
# setup. This must be a list of the form:
# "host1:clientPort,host2:clientPort,..." (default clientPort: 2181)
#
high-availability.zookeeper.quorum: server03:2181

将修改的配置文件 复制到其他Flink节点上

root@server01 conf]# scp masters root@server03:/opt/apps/flink/conf
root@server01 conf]# scp masters root@server02:/opt/apps/flink/conf
root@server01 conf]# scp flink-conf.yaml root@server03:/opt/apps/flink/conf
root@server01 conf]# scp flink-conf.yaml root@server02:/opt/apps/flink/conf

启动集群

[root@server01 flink]# bin/start-cluster.sh 
Starting HA cluster with 3 masters.
Starting standalonesession daemon on host server01.
Starting standalonesession daemon on host server02.
Starting standalonesession daemon on host server03.
Starting taskexecutor daemon on host server01.
Starting taskexecutor daemon on host server02.
Starting taskexecutor daemon on host server03.

Flink On Yarn 模式HA

正常基于 Yarn 提交 Flink 程序,无论是使用 yarn-session 模式还是 yarn-cluster 模式 , 基 于 yarn 运 行 后 的 application 只 要 kill 掉 对 应 的 Flink 集 群 进 程“YarnSessionClusterEntrypoint”后,基于 Yarn 的 Flink 任务就失败了,不会自动进行重试,所以基于 Yarn 运行 Flink 任务,也有必要搭建 HA,这里同样还是需要借助 zookeeper来完成

修改所有 Hadoop 节点的 yarn-site.xml
将所有 Hadoop 节点的 yarn-site.xml 中的提交应用程序最大尝试次数调大,增加如下配置

<property>
<name>yarn.resourcemanager.am.max-attempts</name>
<value>4</value>
</property>

将修改后的文件复制到其他hadoop节点

[root@server01 hadoop]# scp yarn-site.xml  root@server02:/opt/apps/hadoop/etc/hadoop
yarn-site.xml                                                                                100% 1146   414.4KB/s   00:00    
[root@server01 hadoop]# scp yarn-site.xml  root@server03:/opt/apps/hadoop/etc/hadoop
yarn-site.xml                                                                                100% 1146   401.7KB/s   00:00    
[root@server01 hadoop]# 

重启 hdfs 和 zk

修改 flink-conf.yaml
修改内容如下:

high-availability: zookeeper

# The path where metadata for master recovery is persisted. While ZooKeeper stores
# the small ground truth for checkpoint and leader election, this location stores
# the larger objects, like persisted dataflow graphs.
#
# Must be a durable file system that is accessible from all nodes
# (like HDFS, S3, Ceph, nfs, ...)
#
high-availability.storageDir: hdfs://server01:9000/flink/ha

# The list of ZooKeeper quorum peers that coordinate the high-availability
# setup. This must be a list of the form:
# "host1:clientPort,host2:clientPort,..." (default clientPort: 2181)
#
high-availability.zookeeper.quorum: server03:2181

yarn.application-attempts: 10

启动

[root@server01 conf]# ../bin/yarn-session.sh -n 2
2020-08-21 16:29:04,396 INFO  org.apache.flink.configuration.GlobalConfiguration            - Loading configuration property: jobmanager.rpc.address, server01
2020-08-21 16:29:04,398 INFO  org.apache.flink.configuration.GlobalConfiguration            - Loading configuration property: jobmanager.rpc.port, 6123
2020-08-21 16:29:04,398 INFO  org.apache.flink.configuration.GlobalConfiguration            - Loading configuration property: jobmanager.heap.size, 1024m
2020-08-21 16:29:04,398 INFO  org.apache.flink.configuration.GlobalConfiguration            - Loading configuration property: 
2020-08-21 16:29:37,803 INFO  org.apache.flink.runtime.rest.RestClient                      - Rest client endpoint started.
Flink JobManager is now running on server03:43760 with leader id 0d61bb85-a445-4de1-8095-6316288dee5e.
JobManager Web Interface: http://server03:34306

通过yarn 可以看到我们启动的 flink集群
在这里插入图片描述
可以看到flink jobmanager 启动在server03上
在这里插入图片描述

进入对应的节点,kill 掉对应的“YarnSessionClusterEntrypoint”进程。

[root@server03 zookeeper]# jps
7506 DataNode
7767 QuorumPeerMain
8711 TaskManagerRunner
8760 Jps
7625 NodeManager
8761 Jps
8251 StandaloneSessionClusterEntrypoint
[root@server03 zookeeper]# kill -9 8251
[root@server03 zookeeper]# jps
9057 NodeManager
9475 YarnSessionClusterEntrypoint
7767 QuorumPeerMain
8711 TaskManagerRunner
9577 Jps
8958 DataNode
[root@server03 zookeeper]# kill -9 9475

Yarn中观察“applicationxxxx_0001”job 信息 重试后仍然可用
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Flink 动态读取配置文件指的是Flink在运行过程中可以通过某种方式动态的读取配置文件的信息,从而更新应用程序的配置,达到动态修改Flink应用行为的目的。Flink动态读取配置文件的实现方式主要包括两种方法,一种是通过自定义的source读取外部配置文件,另一种是通过Flink的Dynamic Properties参数进行配置。 首先,通过自定义的source读取外部配置文件,可以使Flink应用程序在运行时从外部文件中读取配置信息,通过定期读取或监听外部文件变化的方式,动态的更新应用配置。自定义source可以继承 Flink 的 SourceFunction 接口,实现一个可以每隔一段时间读取一次外部文件的类,然后通过`env.addSource(new CustomSource())`方式添加到 Flink 应用中,实现Flink动态修改配置的目的。 其次,Flink的 Dynamic Properties 功能也可以实现动态配置,此功能允许用户可以在运行时通过界面(如Flink WebUI)或API等方式调整Flink应用的配置属性。采用此方法可以避免频繁读取配置文件而带来的性能损耗,同时在修改配置属性时,Flink应用能够自动感知并应用新的配置,大大提高了应用程序的灵活性和可维护性。 总之,Flink动态读取配置文件可以使应用程序可以在运行时进行灵活的调整和优化,提高应用程序的可维护性和扩展性。因此,在Flink应用程序开发中,灵活运用动态读取配置文件的功能可以成为解决问题、迭代优化的好工具。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

catch that elf

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值