我使用的安装文件是 flink-1.9.3-bin-scala_2.12.tgz ,以下内容均以此版本进行说明。
说明
搭建集群首先要进行集群的规划【哪台做主节点,哪些做从节点】,这里简单搭建一个 3 节点的 Flink Standalone 集群,其中三台主机Flink01、Flink02、Flink03 均为 worker 节点,Flink01 为 master 节点。
1. 配置免密登录【每台服务器】
Flink 组件之间需要基于 SSH 进行通讯。
1.1 配置映射
配置 ip 地址和主机名映射:==很关键==通过ifconfig查询本机的ip地址,这个地方没有配置正确的话节点会有问题。
vim /etc/hosts
xxx.xx.x.x flink01 flink01
xxx.xx.x.x flink02 flink02
xxx.xx.x.x flink03 flink03
1.2 生成公私钥
执行下面命令行生成公匙和私匙:
[root@flink01 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:BtWqdvRxf90QPhg5p2OOIBwgEGTu4lxAd92icFc5cwE root@tcloud
The key's randomart image is:
+---[RSA 2048]----+
|+*...o. +Eo... |
|+ .o...= =..+ o |
| o o.+...+ B . |
|. . .o.+ . * + |
|.. . +So * o oo|
|+ . o.. o . . +|
| o . . . |
| |
| |
+----[SHA256]-----+
1.3 授权
进入 /root/.ssh/ 目录下,查看生成的公匙和私匙,并将公匙写入到授权文件:
[root@flink01 .ssh]# ll
total 16
-rw------- 1 root root 786 Jul 6 11:57 authorized_keys
-rw-r--r-- 1 root root 0 Jul 5 11:06 config
-rw-r--r-- 1 root root 0 Jul 5 11:06 iddummy.pub
-rw------- 1 root root 1679 Jul 27 17:42 id_rsa
-rw-r--r-- 1 root root 393 Jul 27 17:42 id_rsa.pub
-rw-r--r-- 1 root root 1131 Jul 6 13:31 known_hosts
# 写入公匙到授权文件
[root@flink01 .ssh]# cat id_rsa.pub >> authorized_keys
[root@flink01 .ssh]# chmod 600 authorized_keys
1.4 集群间免密登录
# 1.生成密钥对
# 在每台主机上使用 ssh-keygen 命令生成公钥私钥对【上边已介绍】
[root@flink01 ~]# ssh-keygen -t rsa
# 2.免密登录
# 将flink01的公钥写到本机和远程机器的 ~/ .ssh/authorized_key 文件中:
ssh-copy-id -i ~/.ssh/id_rsa.pub flink01
ssh-copy-id -i ~/.ssh/id_rsa.pub flink02
ssh-copy-id -i ~/.ssh/id_rsa.pub flink03
# 3.验证免密登录
ssh flink02
ssh flink03
2. 安装配置
2.1 解压
[root@flink01 flink]# tar -zxvf flink-1.9.3-bin-scala_2.12.tgz
[root@flink01 flink]# mv ./flink-1.9.3-bin-scala_2.12 /usr/local/flink
2.2 修改配置文件
进入到${FLINK_HOME}/conf/目录下,编辑 flink-conf.yaml 配置文件:
[root@flink01 flink]# cd ./conf/ [root@flink01 conf]# vi flink-conf.yaml # 修改一下配置 jobmanager.rpc.address: flink01 # The RPC port where the JobManager is reachable. jobmanager.rpc.port: 6123 # The heap size for the JobManager JVM jobmanager.heap.size: 512m # The heap size for the TaskManager JVM taskmanager.heap.size: 512m # The number of task slots that each TaskManager offers. Each slot runs one parallel pipeline. taskmanager.numberOfTaskSlots: 3
其中:taskmanager.numberOfTaskSlot 参数默认值为 1,修改成 3。表示数每一个TaskManager 上有 3 个 Slot。
==踩坑:== jobmanager.heap.size和taskmanager.heap.size设置过小将无法启动。编辑 conf/slaves 配置文件
[root@flink01 conf]# vi slaves
# TaskManager三台节点机全部配置进slaves
flink01
flink02
flink03
2.3 分发程序
[root@flink01 local]# scp -r flink root@flink02:`pwd`
[root@flink01 local]# scp -r flink root@flink03:`pwd`
2.4 启动集群
[root@flink01 flink]# ./bin/start-cluster.sh
Starting cluster.
Starting standalonesession daemon on host flink01.
Starting taskexecutor daemon on host flink01.
Starting taskexecutor daemon on host flink02.
Starting taskexecutor daemon on host flink03.
2.5 验证
[root@flink01 flink]# jps
4050 Jps
4028 TaskManagerRunner
1759 StandaloneSessionClusterEntrypoint
[root@flink02 ~]# jps
2537 Jps
2492 TaskManagerRunner
[root@flink03 ~]# jps
2537 Jps
2492 TaskManagerRunner
也可访问 WebUI进行查看:http://flink01:8081/#/overview
总结
Flink 和 Spark 一样,开发的时候并不需要部署运行环境,开发完成后打包测试或应用部署时才需要。