本文仅对MacOS下安装Apache Flink
做一个记录。
安装
按照官网介绍:
1 | brew install apache-flink |
但是安装的时候报错:
1 | brew install apache-flink |
没办法,只能尝试另一种方式安装,先看下信息:
1 | brew info apache-flink |
打开安装文件地址:https://github.com/Homebrew/homebrew-core/blob/master/Formula/apache-flink.rb,如果要切换版本安装,查看文件修改记录,找到对应版本的安装文件,如1.11.0,尝试安装:
1 | brew install https://github.com/Homebrew/homebrew-core/blob/fdf9f29591b9463ed62199d9a9f9865951a52cff/Formula/apache-flink.rb |
还是失败,那将文件下载到本地,然后再安装:
1 | brew install apache-flink.rb |
安装成功,查看版本信息:
1 | flink --version |
安装目录可以通过命令 brew info apache-flink
获得:
1 | brew info apache-flink |
启动
1 | cd /usr/local/Cellar/apache-flink/1.11.0/ |
测试
新建Maven
项目,加入依赖:
1 | <properties> |
复制官方示例:
1 | package org.example.flink; |
执行打包命令:
1 | mvn clean package -Dmaven.test.skip=true |
监听本地端口:
1 | nc -lk 9999 |
执行:
1 | ./libexec/bin/flink run ${yourPath}/flink-example-1.0-SNAPSHOT.jar |
同时查看日志:
1 | tail -100f libexec/log/flink-${yourName}-taskexecutor-0-${yourName}.out |
在nc中输入任意单词,可以在日志中看到单词的统计数据(出现次数):
Just type some words hitting return for a new word. These will be the input to the word count program. If you want to see counts greater than 1, type the same word again and again within 5 seconds (increase the window size from 5 seconds if you cannot type that fast ☺).
1 | # 在nc中输入 |
关闭
1 | ./libexec/bin/stop-cluster.sh |