【Flink】Flink环境搭建

2022-09-02 13:16:28 浏览数 (1)

本篇文章以最简单的方式快速搭建Flink 1.12.0环境,供开发学习使用。

1. Flink安装

1.1 下载地址

Flink版本列表:

https://archive.apache.org/dist/flink/

最新版1.12.0下载地址:

https://archive.apache.org/dist/flink/flink-1.12.0/flink-1.12.0-bin-scala_2.12.tgz

1.2 安装Flink

下载1.12.0版本:

wget https://archive.apache.org/dist/flink/flink-1.12.0/flink-1.12.0-bin-scala_2.12.tgz

1

解压下载下来的压缩包:

tar -xzf flink-1.12.0-bin-scala_2.12.tgz

1

启动:

./bin/start-cluster.sh

1

检查是否启动成功:

[root@localhost flink-1.12.0]# jps -l | grep flink

3922 org.apache.flink.runtime.taskexecutor.TaskManagerRunne

3615 org.apache.flink.runtime.entrypoint.StandaloneSessionClusterEntrypoint

1

2

3

检查web ui是否启动成功:

http://ip:port:8081

1

2. Flink示例运行

2.1 批处理例子

使用flink自带的word count程序实现单词计数,如果不输入任何参数(输入文件路径和输出文件路径),则使用程序内置的数据:

[root@localhost flink-1.12.0]# ./bin/flink run ./examples/batch/WordCount.jar --output /home/happy/flink/output/wordcount-result

Executing WordCount example with default input data set.

Use --input to specify file input.

Job has been submitted with JobID d1e96fab40dec4fffefa8b96674bd0ea

Program execution finished

Job with JobID d1e96fab40dec4fffefa8b96674bd0ea has finished.

Job Runtime: 168 ms

1

2

3

4

5

6

7

查看结果:

more ../output/wordcount-result

1

a 5

action 1

after 1

against 1

all 2

and 12

arms 1

arrows 1

......

1

2

3

4

5

6

7

8

9

2.2 流处理例子

安装netcat:

yum install -y nc

1

监听tcp端口,发送数据:

nc -l 8881

1

启动流处理示例程序:

[root@localhost flink-1.12.0]# ./bin/flink run ./examples/streaming/SocketWindowWordCount.jar --port 8881

Job has been submitted with JobID 41831fee1253dc7cd4a1e4dfee357916

1

2

3

发送数据:

aa bb bb cc

1

控制台输出结果::

cc : 1

aa : 1

cc : 1

bb : 2

1

2

3

4

2.3 Flink UI

内置的web-ui,默认端口为8081:

http://ip:port:8081

1

我们可以通过这也界面来提交和监控Flink程序,以及查看运行日志等等。

0 人点赞