Apache Download Mirrors
2、解压安装包。不才载目录中解压下载的Flink安装包,例如利用命令` tar -zxvf flink-1.16.3-bin-scala_2.12.tgz`。
3、启动Flink集群。利用`./bin/start-cluster.sh`命令启动Flink集群。
a123456@luludeMacBook-Pro-2 bin % ./start-cluster.sh Starting cluster.Starting standalonesession daemon on host luludeMacBook-Pro-2.local.Starting taskexecutor daemon on host luludeMacBook-Pro-2.local.a123456@luludeMacBook-Pro-2 bin %
4、jsp 命令查看启动进程
a123456 bin % jps7440 Launcher10006 StandaloneSessionClusterEntrypoint10631 Jps362 Main10255 TaskManagerRunner
Flink 启动的进程:TaskManagerRunner,StandaloneSessionClusterEntrypoint。
5、可以通过访问`http://localhost:8081`来查看Web UI,确认集群是否正常运行。
6、提交任务。在Web UI中提交任务,例如运行官方自带的SocketWindowWordCount例子,利用命令`./bin/flink run examples/streaming/SocketWindowWordCount.jar --hostname 127.0.0.1 --port 9090`。
a123456@luludeMacBook-Pro-2 flink-1.16.3 % ./bin/flink run examples/streaming/SocketWindowWordCount.jar --hostname 127.0.0.1 --port 9090Job has been submitted with JobID 5f7272f71c736331f5b36bc84f3337cd
7、在掌握台输入单词,查看每个单词的词频统计。
a123456@luludeMacBook-Pro-2 ~ % nc -l 9090helloworld111112222helloworld
9、停滞集群
a123456@luludeMacBook-Pro-2 flink-1.16.3 % ./bin/stop-cluster.shStopping taskexecutor daemon (pid: 10255) on host luludeMacBook-Pro-2.local.Stopping standalonesession daemon (pid: 10006) on host luludeMacBook-Pro-2.local.
栗子需求: 统计单词个数
1、准备数据
vi words.txt
hello world
hello yangyang
hello
hello me
hello me you
2、实行./flink run 命令
输入=words.txt
输出=word_out
a123456 bin % ./flink run ../examples/batch/WordCount.jar --input words.txt --output word_out Job has been submitted with JobID 3f36fbc75f36021b2cb84ba9861c8fdeProgram execution finishedJob with JobID 3f36fbc75f36021b2cb84ba9861c8fde has finished.Job Runtime: 1190 ms
3、通过 Web UI 查看任务
4、查看输出内容 vi word_out
hello 5
me 2
world 1
yangyang 1
you 1
好了,Flink 入门就先容到这里!
本地模式事理
感激1、Flink 程序由JobClient 进行提交
2、JobClient将作业提交给 JobManager。
3、JobManager卖力资源折衷分配和作业实行,资源分配完成后,任务将提交相应的TaskManager。
4、TaskManager启动一个线程以开始实行,TaskManager会向JobManager报告状态,如开始实行,正在实行或已完成。
5、作业完成后,结果将发送回客户端JobClient。