前言
Flink三种运行方式:Local、Standalone、Yarn(相当于yarn-cluster),Kubernetes。Local模式很简单,再这里不在介绍,下面着中介绍一下Standalon,On Yarn模式,Kubernetes模式。
1.standalone模式
1.1 安装
• 将本地文件上传到Linux服务器:
luomingkuideMacBook-Pro:Downloads luomingkui$ scp -r flink-1.7.0-bin-hadoop27-scala_2.11.tgz
• 解压缩:
cp /opt/software/flink-1.7.0-bin-hadoop27-scala_2.11.tgz /opt/module/
tar -zxvf flink-1.7.0-bin-hadoop27-scala_2.11.tgz
• 修改 flink/conf/flink-conf.yaml 文件
jobmanager.rpc.address: hadoop102
• 修改 /conf/slave文件
hadoop103
Hadoop104
• 分发另外两台机器
xsync flink-1.7.0/
• 启动
[luomk@hadoop102 bin]$ ./start-cluster.sh
Starting cluster.
Starting standalonesession daemon on host hadoop102.
Starting taskexecutor daemon on host hadoop103.
Starting taskexecutor daemon on host hadoop104.
[luomk@hadoop102 bin]$ xutils
================ luomk@hadoop102 ================
13460 StandaloneSessionClusterEntrypoint
13549 Jps
================ luomk@hadoop103 ================
2391 TaskManagerRunner
2487 Jps
================ luomk@hadoop104 ================
25017 Jps
24927 TaskManagerRunner
[luomk@hadoop102 bin]$
• 访问http://hadoop102:8081/#/overview
1.2 提交example离线任务运行
• 提交任务
[luomk@hadoop102 bin]$ ./flink run -p 2 ../examples/batch/WordCount.jar --input /opt/module/datas/WorldCount --output /opt/module/datas/WorldCount_out_20190709
Starting execution of program
Program execution finished
Job with JobID c184caab0b1adc6a4a08bf9e9ba931c1 has finished.
Job Runtime: 2820 ms
• 查看任务
[luomk@hadoop103 WorldCount_out_20190709]$ cat 2
hello 1
hive 1
i 1
java 1
spark 1
you 1
• 在webui控制台查看计算过程
2.yarn模式
2.1 启动hadoop集群
2.2 启动yarn-session
./yarn-session.sh -n 2 -s 2 -jm 1024 -tm 1024 -nm test -d
其中:
-n(--container):TaskManager的数量。
-s(—slots): 每个TaskManager的slot数量,默认一个slot一个core,默认每个taskmanager的slot的个数为1,有时可以多一些taskmanager,做冗余。
-jm:JobManager的内存(单位MB)。
-tm:每个taskmanager的内存(单位MB)。
-nm:yarn 的appName(现在yarn的ui上的名字)。
-d:后台执行。
2.3 提交example离线任务运行
• 执行脚本
./flink run -m yarn-cluster ../examples/batch/WordCount.jar --input /opt/module/datas/WorldCount --output /opt/module/datas/WorldCount_out_20190709_1
• 查看结果
[luomk@hadoop103 datas]$ cat WorldCount_out_20190709_1
bhase 1
hahoop 1
hello 1
helloworld 2
hive 1
i 1
java 1
love 1
luomk 1
spark 1
sunxieni 1
you 1
[luomk@hadoop103 datas]$
• 去yarn控制台查看任务状态
3.Kubernetes部署
容器化部署时目前业界很流行的一项技术,基于Docker镜像运行能够让用户更加方便地对应用进行管理和运维。容器管理工具中最为流行的就Kubernetes(k8s),而Flink也在最近的版本中支持了k8s部署模式。
3.1 搭建Kubernetes集群(略)
3.2 配置各组件的yaml文件
在k8s上构建Flink Session Cluster,需要将Flink集群的组件对应的docker镜像分别在k8s上启动,包括JobManager、TaskManager、JobManagerService三个镜像服务。每个镜像服务都可以从中央镜像仓库中获取。
3.3 启动Flink Session Cluster
// 启动jobmanager-service 服务
kubectl create -f jobmanager-service.yaml
// 启动jobmanager-deployment服务
kubectl create -f jobmanager-deployment.yaml
// 启动taskmanager-deployment服务
kubectl create -f taskmanager-deployment.yaml
3.4 访问Flink UI页面
集群启动后,就可以通过JobManagerServicers中配置的WebUI端口,用浏览器输入以下url来访问Flink UI页面了:
http://{JobManagerHost:Port}/api/v1/namespaces/default/services/flink-jobmanager:ui/proxy