参考
官方 Docker Setup
安装Docker
请参考安装docker
拉取镜像
docker search flink:scala
docker pull flink:1.15.2-scala_2.12-java8
docker pull flink:scala_2.12-java8
暂时不清楚flink:1.15.2-scala_2.12-java8和flink:scala_2.12-java8有什么区别,我选择了flink:1.15.2-scala_2.12-java8
docker方式运行容器(没成功)
一个 Flink 会话集群可用于运行多个作业。部署群集后,需要将每个作业提交到群集。要使用 Docker 部署 Flink 会话集群,您需要启动一个 JobManager 容器。为了启用容器之间的通信,我们首先设置一个必需的 Flink 配置属性并创建一个网络:
创建docker网络
docker network create flink-network
docker-compose方式运行容器
mkdir /usr/local/flink/flink-docker/jobmanager
mkdir D:/data/flink/flink-docker/taskmanager
docker-compose.yml
在上述目录创建文件 docker-compose.yml
version: "2.2"
services:
jobmanager:
image: flink:1.15.2-scala_2.12-java8
container_name: jobmanager-1
expose:
- "6123"
ports:
- "8081:8081"
command: jobmanager
volumes:
- D:/data/flink/jobmanager/conf:/opt/flink/conf
- D:/data/flink/jobmanager/lib:/opt/flink/lib
- D:/data/flink/jobmanager/log:/opt/flink/log
environment:
- |
FLINK_PROPERTIES=
jobmanager.rpc.address: jobmanager
parallelism.default: 2
web.upload.dir: /opt/flink/target
taskmanager:
image: flink:1.15.2-scala_2.12-java8
container_name: taskmanager-1
depends_on:
- jobmanager
command: taskmanager
scale: 1
volumes:
- D:/data/flink/taskmanager/conf:/opt/flink/conf
- D:/data/flink/taskmanager/lib:/opt/flink/lib
- D:/data/flink/taskmanager/log:/opt/flink/log
environment:
- |
FLINK_PROPERTIES=
jobmanager.rpc.address: jobmanager
taskmanager.numberOfTaskSlots: 2
parallelism.default: 2
:::warning /opt/flink/lib : 如果配置了这个必须要实现把flink原本来lib中的jar放一份,要不然启动会失败 :::
cd D:/data/flink/flink-docker
docker-compose up -d
配置映射
docker-compose.yml执行后,如果提示错误或者运行不正常,需先启动以下测试容器并将相应的目录文件从docker[容器里拷贝出到宿主机后再执行重新docker-compose.yml
作业管理器
docker run --name=jobmanager2 --network flink-network --publish 8082:8081 -d -it flink:1.15.2-scala_2.12-java8
启动容器jobmanager2成功后,将容器jobmanager2的对应文件考到主机上,如
docker cp jobmanager2:/opt/flink/conf D:/data/flink/jobmanager/conf
docker cp jobmanager2:/opt/flink/lib D:/data/flink/jobmanager/lib
docker cp jobmanager2:/opt/flink/log D:/data/flink/taskmanager/log
任务管理器容器
启动任务管理器容器
docker run --name=taskmanager2 --network flink-network --env FLINK_PROPERTIES="JOB_MANAGER_RPC_ADDRESS=jobmanager" -d -it flink:1.15.2-scala_2.12-java8
docker cp taskmanager2:/opt/flink/conf D:/data/flink/taskmanager/conf
docker cp taskmanager2:/opt/flink/lib D:/data/flink/taskmanager/lib
docker cp taskmanager2:/opt/flink/log D:/data/flink/taskmanager/log
启动flink集群
cd D:/data/flink/flink-docker
docker-compose up -d
docker-compose -f docker-compose.yml stop
docker-compose -f docker-compose.yml down
进入容器
cd D:\data\flink\flink-docker
# jobmanager
docker-compose exec jobmanager /bin/bash
# taskmanager
docker-compose exec taskmanager /bin/bash
或者
docker exec -it flink-docker-taskmanager-1 /bin/bash
docker exec -it flink-docker-jobmanager-1 /bin/bash
验证flink
cd /usr/local/flink/flink-docker
# 查看进程
sudo docker-compose -f docker-compose.yml ps
# jobmanager
sudo docker-compose exec jobmanager /bin/bash
# taskmanager
sudo docker-compose exec taskmanager /bin/bash
# 查看日志
sudo docker logs flink_jobmanager_1
sudo docker logs -f -t --tail=50 flink_jobmanager_1
# 查看网络
sudo docker network ls
sudo docker inspect flink_jobmanager_1
Flink CDC的lib依赖
下载下面列出的依赖包,并将它们放到目录 flink容器的/lib/ 下:
下载地址
选择对应的版本下载,如flink-connector-jdbc-1.15.2.jar,将下载的数据库连接驱动包的jar放到 flink的lib目录下
任务管理器容器
docker cp D:/data/flink/lib/flink-sql-connector-mysql-cdc-2.2.1.jar flink-docker-taskmanager-1
:/opt/flink/lib/flink-sql-connector-mysql-cdc-2.2.1.jar
docker cp D:/data/flink/lib/flink-connector-jdbc-1.15.2.jar flink-docker-taskmanager-1
:/opt/flink/lib/flink-connector-jdbc-1.15.2.jar
作业管理器容器
docker cp D:/data/flink/lib/flink-sql-connector-mysql-cdc-2.2.1.jar flink-docker-jobmanager-1
:/opt/flink/lib/flink-sql-connector-mysql-cdc-2.2.1.jar
docker cp D:/data/flink/lib/flink-connector-jdbc-1.15.2.jar flink-docker-jobmanager-1
:/opt/flink/lib/flink-connector-jdbc-1.15.2.jar
到任务管理器容器查看是否拷贝成功
cd D:\data\flink\flink-docker
docker-compose exec taskmanager /bin/bash
cd ./lib/
ll
通过Web查看集群
官方镜像暴露了8081端口,由于是在虚拟机上运行的。所以在浏览器上通过虚拟机IP:端口
的方式访问,如果docker是直接装在机器上的,没有装在虚拟机上,那么可以直接通过[http://localhost:8081/](http://localhost:8081/)
访问