通过 docker-compose 部署 Flink

概要

通过 docker-compose 以 Session Mode 部署 flink

前置依赖

  • Docker、docker-compose
  • flink 客户端
  • docker-compose.yml
yaml 复制代码
version: "2.2"
services:
  jobmanager:
    image: flink:1.17.2
    ports:
      - "8081:8081"
    command: jobmanager
    volumes:
      - ${PWD}/checkpoint:/opt/flink/checkpoint
      - ${PWD}/savepoint:/opt/flink/savepoint
    environment:
      - |
        FLINK_PROPERTIES=
        jobmanager.rpc.address: jobmanager

  taskmanager:
    image: flink:1.17.2
    depends_on:
      - jobmanager
    command: taskmanager
    scale: 1
    volumes:
      - ${PWD}/checkpoint:/opt/flink/checkpoint
      - ${PWD}/savepoint:/opt/flink/savepoint
    environment:
      - |
        FLINK_PROPERTIES=
        jobmanager.rpc.address: jobmanager
        taskmanager.numberOfTaskSlots: 3

部署

shell 复制代码
# 下载 docker、docker-compose

# docker-compose 部署
# 复制上述 docker-compose.yml 内容
$ vim docker-compose.yml

# 创建 savepoint、checkpoint 目录用于保存状态数据
$ mkdir savepoint checkpoint

$ docker-compose up -d

提交任务

shell 复制代码
# 下载 flink 客户端
$ wget https://archive.apache.org/dist/flink/flink-1.17.0/flink-1.17.0-bin-scala_2.12.tgz
$ tar xvf flink-1.17.0-bin-scala_2.12.tgz
$ cd flink-1.17.0-bin-scala_2.12

# 提交任务
$ bin/flink run -d -m 192.168.56.103:8081 -c com.xchenhao.Demo flink-cdc-1.0-SNAPSHOT-jar-with-dependencies.jar

# 查看任务列表
$ bin/flink list -m 192.168.56.103:8081
Waiting for response...
------------------ Running/Restarting Jobs -------------------
02.02.2024 16:45:01 : 9f70a7c1430d609eaa3434c4f30d1e93 : Flink-CDC (RUNNING)
--------------------------------------------------------------
No scheduled jobs

Web UI 查看

浏览器访问目标端口 192.168.56.103:8081

其它常用命令

  • 从指定 checkpoint 恢复任务
shell 复制代码
bin/flink run -d -m 192.168.56.103:8081 -s file:///opt/flink/checkpoint/47bea16a8ffcb51beff21ed1c7297dc1/chk-129773 -c com.xchenhao.Demo flink-cdc-1.0-SNAPSHOT-jar-with-dependencies.jar
  • 从指定 savepoint 恢复任务
shell 复制代码
bin/flink run -d -m 192.168.56.103:8081 -s file:///opt/flink/savepoint/savepoint-63712d-d7cbfee1ede9  -c com.xchenhao.Demo flink-cdc-1.0-SNAPSHOT-jar-with-dependencies.jar
  • 保存 savepoint
shell 复制代码
bin/flink savepoint 9f70a7c1430d609eaa3434c4f30d1e93 file:///opt/flink/savepoint -m 192.168.56.103:8081
  • 取消任务
shell 复制代码
bin/flink cancel 9f70a7c1430d609eaa3434c4f30d1e93 -m 192.168.56.103:8081
  • 停止任务并保存 savepoint
shell 复制代码
bin/flink stop 9f70a7c1430d609eaa3434c4f30d1e93 -p file:///opt/flink/savepoint -m 192.168.56.103:8081

参考

相关推荐
宝哥大数据7 小时前
Flink Joins
flink
wuxingge7 小时前
k8s1.30.0高可用集群部署
云原生·容器·kubernetes
志凌海纳SmartX8 小时前
趋势洞察|AI 能否带动裸金属 K8s 强势崛起?
云原生·容器·kubernetes
锅总8 小时前
nacos与k8s service健康检查详解
云原生·容器·kubernetes
BUG弄潮儿8 小时前
k8s 集群安装
云原生·容器·kubernetes
意疏9 小时前
【Linux 篇】Docker 的容器之海与镜像之岛:于 Linux 系统内探索容器化的奇妙航行
linux·docker
墨鸦_Cormorant9 小时前
使用docker快速部署Nginx、Redis、MySQL、Tomcat以及制作镜像
redis·nginx·docker
Code_Artist9 小时前
Docker镜像加速解决方案:配置HTTP代理,让Docker学会科学上网!
docker·云原生·容器
Java 第一深情10 小时前
零基础入门Flink,掌握基本使用方法
大数据·flink·实时计算
我的K840910 小时前
Flink整合Hudi及使用
linux·服务器·flink