使用 Docker 部署
本指南将介绍如何使用 Docker 运行 Fluss 集群。 我们将介绍 Docker 环境的前提条件,以及如何使用 docker run 命令 或 docker compose 文件 快速创建一个 Fluss 集群。
环境要求
硬件
推荐配置:4 核,16GB 内存。
软件
Docker 及 Docker Compose 插件。所有命令均在 Docker 27.4.0 与 Docker Compose v2.30.3 版本下测试通过。
使用 Docker 部署
下面简要介绍如何使用 docker run 命令快速创建一个完整的 Fluss 测试集群。
创建共享 tmpfs 卷
创建一个共享 tmpfs 卷:
docker volume create shared-tmpfs创建网络
在 Docker 中创建一个隔离的桥接网络
docker network create fluss-demo启动 ZooKeeper
以守护进程模式启动 ZooKeeper。这是一个单节点 ZooKeeper 配置。ZooKeeper 是 Fluss 的中央元数据存储, 在生产环境中应配置为带复制的集群。更多信息请参阅 Running zookeeper cluster。
docker run \
--name zookeeper \
--network=fluss-demo \
--restart always \
-p 2181:2181 \
-d zookeeper:3.9.2启动 Fluss CoordinatorServer
你可以根据需要启动一个或多个 CoordinatorServer。在生产环境中, 请确保你配置了多个 CoordinatorServer 以实现高可用(HA)。
启动单个 CoordinatorServer
如果你只是想启动一个示例测试,可以只在守护进程模式下启动一个 CoordinatorServer 并连接到 ZooKeeper。 命令如下:
docker run \
--name coordinator-server \
--network=fluss-demo \
--env FLUSS_PROPERTIES="zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://coordinator-server:0, CLIENT://coordinator-server:9123
advertised.listeners: CLIENT://localhost:9123
internal.listener.name: INTERNAL
" \
-p 9123:9123 \
-d apache/fluss:1.1-SNAPSHOT coordinatorServer启动 CoordinatorServer HA
要启用 CoordinatorServer HA,需在守护进程模式下启动第二个 CoordinatorServer 并连接到同一个 ZooKeeper。 这些 CoordinatorServer 通过 ZooKeeper 参与 leader 选举:恰好一个被选举为 leader,另一个作为 standby 运行。命令如下:
docker run \
--name coordinator-server-1 \
--network=fluss-demo \
--env FLUSS_PROPERTIES="zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://coordinator-server-1:0, CLIENT://coordinator-server-1:9123
advertised.listeners: CLIENT://localhost:9127
internal.listener.name: INTERNAL
" \
-p 9127:9123 \
-d apache/fluss:1.1-SNAPSHOT coordinatorServer启用 CoordinatorServer HA 后,请在 bootstrap.servers 中列出所有 CoordinatorServer 实例的地址, 这样即使某个 CoordinatorServer 宕机,客户端也能连接到存活的 coordinator,例如 'bootstrap.servers' = 'localhost:9123,localhost:9127'。
启动 Fluss TabletServer
你可以根据需要启动一个或多个 TabletServer。在生产环境中, 请确保你配置了多个 TabletServer。
启动单个 TabletServer
如果你只是想启动一个示例测试,可以只在守护进程模式下启动一个 TabletServer 并连接到 ZooKeeper。 命令如下:
docker run \
--name tablet-server \
--network=fluss-demo \
--env FLUSS_PROPERTIES="zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://tablet-server:0, CLIENT://tablet-server:9123
advertised.listeners: CLIENT://localhost:9124
internal.listener.name: INTERNAL
tablet-server.id: 0
kv.snapshot.interval: 0s
data.dir: /tmp/fluss/data
remote.data.dir: /tmp/fluss/remote-data" \
-p 9124:9123 \
--volume shared-tmpfs:/tmp/fluss \
-d apache/fluss:1.1-SNAPSHOT tabletServer启动多个 TabletServer
在生产环境中,你需要启动多个 Fluss TabletServer 节点。 这里我们以守护进程模式启动 3 个 Fluss TabletServer 节点并连接到 ZooKeeper。命令如下:
- 启动 tablet-server-0
docker run \
--name tablet-server-0 \
--network=fluss-demo \
--env FLUSS_PROPERTIES="zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://tablet-server-0:0, CLIENT://tablet-server-0:9123
advertised.listeners: CLIENT://localhost:9124
internal.listener.name: INTERNAL
tablet-server.id: 0
kv.snapshot.interval: 0s
data.dir: /tmp/fluss/data/tablet-server-0
remote.data.dir: /tmp/fluss/remote-data" \
-p 9124:9123 \
--volume shared-tmpfs:/tmp/fluss \
-d apache/fluss:1.1-SNAPSHOT tabletServer- 启动 tablet-server-1
docker run \
--name tablet-server-1 \
--network=fluss-demo \
--env FLUSS_PROPERTIES="zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://tablet-server-1:0, CLIENT://tablet-server-1:9123
advertised.listeners: CLIENT://localhost:9125
internal.listener.name: INTERNAL
tablet-server.id: 1
kv.snapshot.interval: 0s
data.dir: /tmp/fluss/data/tablet-server-1
remote.data.dir: /tmp/fluss/remote-data" \
-p 9125:9123 \
--volume shared-tmpfs:/tmp/fluss \
-d apache/fluss:1.1-SNAPSHOT tabletServer- 启动 tablet-server-2
docker run \
--name tablet-server-2 \
--network=fluss-demo \
--env FLUSS_PROPERTIES="zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://tablet-server-2:0, CLIENT://tablet-server-2:9123
advertised.listeners: CLIENT://localhost:9126
internal.listener.name: INTERNAL
tablet-server.id: 2
kv.snapshot.interval: 0s
data.dir: /tmp/fluss/data/tablet-server-2
remote.data.dir: /tmp/fluss/remote-data" \
-p 9126:9123 \
--volume shared-tmpfs:/tmp/fluss \
-d apache/fluss:1.1-SNAPSHOT tabletServer现在所有 Fluss 相关组件都已运行。
运行以下命令检查 Fluss 集群状态:
docker container ls -a使用 Docker Compose 部署
下面简要介绍如何使用 docker compose up -d 命令以分离模式快速创建一个完整的 Fluss 测试集群。
创建 docker-compose.yml 文件
启动含单个 TabletServer 的 Fluss 集群的 Compose 文件
你可以使用以下 docker-compose.yml 文件启动一个包含 CoordinatorServer 和 TabletServer 各一个的 Fluss 集群。
services:
coordinator-server:
image: apache/fluss:1.1-SNAPSHOT
command: coordinatorServer
depends_on:
- zookeeper
environment:
- |
FLUSS_PROPERTIES=
zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://coordinator-server:0, CLIENT://coordinator-server:9123
advertised.listeners: CLIENT://localhost:9123
internal.listener.name: INTERNAL
remote.data.dir: /tmp/fluss/remote-data
ports:
- "9123:9123"
tablet-server:
image: apache/fluss:1.1-SNAPSHOT
command: tabletServer
depends_on:
- coordinator-server
environment:
- |
FLUSS_PROPERTIES=
zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://tablet-server:0, CLIENT://tablet-server:9123
advertised.listeners: CLIENT://localhost:9124
internal.listener.name: INTERNAL
tablet-server.id: 0
kv.snapshot.interval: 0s
data.dir: /tmp/fluss/data
remote.data.dir: /tmp/fluss/remote-data
ports:
- "9124:9123"
volumes:
- shared-tmpfs:/tmp/fluss
zookeeper:
restart: always
image: zookeeper:3.9.2
volumes:
shared-tmpfs:
driver: local
driver_opts:
type: "tmpfs"
device: "tmpfs"启动含多个 CoordinatorServer 与 TabletServer 的 Fluss 集群的 Compose 文件
你可以使用以下 docker-compose.yml 文件启动一个包含两 CoordinatorServer(HA)和三个 TabletServer 的 Fluss 集群。
services:
coordinator-server-0:
image: apache/fluss:1.1-SNAPSHOT
command: coordinatorServer
depends_on:
- zookeeper
environment:
- |
FLUSS_PROPERTIES=
zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://coordinator-server-0:0, CLIENT://coordinator-server-0:9123
advertised.listeners: CLIENT://localhost:9123
internal.listener.name: INTERNAL
remote.data.dir: /tmp/fluss/remote-data
ports:
- "9123:9123"
coordinator-server-1:
image: apache/fluss:1.1-SNAPSHOT
command: coordinatorServer
depends_on:
- zookeeper
environment:
- |
FLUSS_PROPERTIES=
zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://coordinator-server-1:0, CLIENT://coordinator-server-1:9123
advertised.listeners: CLIENT://localhost:9127
internal.listener.name: INTERNAL
remote.data.dir: /tmp/fluss/remote-data
ports:
- "9127:9123"
tablet-server-0:
image: apache/fluss:1.1-SNAPSHOT
command: tabletServer
depends_on:
- coordinator-server-0
environment:
- |
FLUSS_PROPERTIES=
zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://tablet-server-0:0, CLIENT://tablet-server-0:9123
advertised.listeners: CLIENT://localhost:9124
internal.listener.name: INTERNAL
tablet-server.id: 0
kv.snapshot.interval: 0s
data.dir: /tmp/fluss/data/tablet-server-0
remote.data.dir: /tmp/fluss/remote-data
ports:
- "9124:9123"
volumes:
- shared-tmpfs:/tmp/fluss
tablet-server-1:
image: apache/fluss:1.1-SNAPSHOT
command: tabletServer
depends_on:
- coordinator-server-0
environment:
- |
FLUSS_PROPERTIES=
zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://tablet-server-1:0, CLIENT://tablet-server-1:9123
advertised.listeners: CLIENT://localhost:9125
internal.listener.name: INTERNAL
tablet-server.id: 1
kv.snapshot.interval: 0s
data.dir: /tmp/fluss/data/tablet-server-1
remote.data.dir: /tmp/fluss/remote-data
ports:
- "9125:9123"
volumes:
- shared-tmpfs:/tmp/fluss
tablet-server-2:
image: apache/fluss:1.1-SNAPSHOT
command: tabletServer
depends_on:
- coordinator-server-0
environment:
- |
FLUSS_PROPERTIES=
zookeeper.address: zookeeper:2181
bind.listeners: INTERNAL://tablet-server-2:0, CLIENT://tablet-server-2:9123
advertised.listeners: CLIENT://localhost:9126
internal.listener.name: INTERNAL
tablet-server.id: 2
kv.snapshot.interval: 0s
data.dir: /tmp/fluss/data/tablet-server-2
remote.data.dir: /tmp/fluss/remote-data
ports:
- "9126:9123"
volumes:
- shared-tmpfs:/tmp/fluss
zookeeper:
restart: always
image: zookeeper:3.9.2
volumes:
shared-tmpfs:
driver: local
driver_opts:
type: "tmpfs"
device: "tmpfs"启动各组件
保存 docker-compose.yml 脚本,并在同一目录下执行 docker compose up -d 命令来创建集群。
运行以下命令检查容器状态:
docker container ls -a与 Fluss 交互
Fluss 集群启动后,你可以使用 Fluss Client(例如 Flink SQL Client)与 Fluss 交互。 以下小节将介绍如何使用 'Docker' 搭建 Flink 集群,并使用 Flink SQL Client 与 Fluss 交互。
启动 Flink 集群
你可以参考 Flink 环境准备 启动一个 Flink standalone 集群。
注意:请确保 Fluss Flink connector jar 已拷贝到 Flink home 的 lib 目录下。
bin/start-cluster.sh进入 SQL-Client
使用以下命令进入 Flink SQL CLI 容器:
bin/sql-client.sh创建 Fluss Catalog
使用以下 SQL 创建 Fluss catalog:
- 单个 CoordinatorServer:
CREATE CATALOG fluss_catalog WITH (
'type' = 'fluss',
'bootstrap.servers' = 'localhost:9123'
);- CoordinatorServer HA:
CREATE CATALOG fluss_catalog WITH (
'type' = 'fluss',
'bootstrap.servers' = 'localhost:9123,localhost:9127'
);USE CATALOG fluss_catalog;使用 Fluss 做更多事情
创建 catalog 后,你可以使用 Flink SQL Client 对 Fluss 做更多操作,例如建表、插入数据、查询数据等。 更多详情请参阅 Flink 快速入门。