一、安装 Flink
方法一: 直接下载已编译版本
# 下载 wget https://www.apache.org/dyn/closer.lua/flink/flink-1.12.2/flink-1.12.2-bin-scala_2.11.tgz # 解压缩后即可使用 tar -zxvf flink-1.12.2-bin-scala_2.11.tgz
方法二:下载源码版本手动编译
# 源码编译 git clone https://github.com/apache/flink.git cd flink mvn clean package -DskipTests cd build-target
安装 Flink 需要 Java 8 或 11。
二、 本地模式启动 Flink
smqk@lenovo:/opt/flink$ ./bin/start-cluster.sh Starting cluster. Starting standalonesession daemon on host. Starting taskexecutor daemon on host.
三、提交任务
smqk@lenovo:/opt/flink$ ./bin/flink run examples/streaming/WordCount.jar Executing WordCount example with default input data set. Use --input to specify file input. Printing result to stdout. Use --output to specify output path. Job has been submitted with JobID cf07f1efe7a779364f3bcfa42be3ae37 Program execution finished Job with JobID cf07f1efe7a779364f3bcfa42be3ae37 has finished. Job Runtime: 698 ms smqk@lenovo:/opt/flink$ tail log/flink-*-taskexecutor-*.out (nymph,1) (in,3) (thy,1) (orisons,1) (be,4) (all,2) (my,1) (sins,1) (remember,1) (d,4) smqk@lenovo:/opt/flink$
可以使用 Web UI 查看任务的执行情况。
四、停止 Flink
smqk@lenovo:/opt/flink$ ./bin/stop-cluster.sh Stopping taskexecutor daemon (pid: 13411) on host lenovo. Stopping standalonesession daemon (pid: 13105) on host lenovo.