Flink1.7从安装到体验

本文实战Flink1.7的安装和Demo运行过程;

步骤介绍

  1. 准备工作;
  2. 下载Flink1.7;
  3. 安装Flink1.7;
  4. 启动Flink1.7;
  5. 体验Flink1.7;

准备工作

以下是本次实战的环境信息:

  1. 操作系统:CentOS Linux release 7.5.1804
  2. JDK:1.8.0_191
  3. nc工具:7.50(安装命令是yum install nmap-ncat.x86_64)

注意:

  1. 我在vmware的ubuntu16上试过,启动后Managers、Slots、Available Task Slots的数量都为零,但在实体机器上是没有问题的;
  2. CentOS请注意关闭防火墙;

下载Flink1.7

  1. 在Flink官网下载,地址是:https://flink.apache.org/downloads.html
  2. 如下图,选择红框中的版本:
    Flink1.7从安装到体验_第1张图片

安装Flink1.7

Flink1.7的安装很简单,解压即可,如下所示:

  1. 下载的Flink安装包文件是flink-1.7.0-bin-hadoop28-scala_2.11.tgz,放在此位置:/usr/local/work;
  2. 在/usr/local/work目录下执行命令tar -zxvf flink-1.7.0-bin-hadoop28-scala_2.11.tgz解压,会生成一个文件夹:flink-1.7.0

启动Flink1.7

  1. 在文件夹flink-1.7.0下执行命令./bin/start-cluster.sh即可启动Flink,启动信息如下:
[root@vostro flink-1.7.0]# ./bin/start-cluster.sh 
Starting cluster.
Starting standalonesession daemon on host vostro.
Starting taskexecutor daemon on host vostro.
  1. 在flink-1.7.0/log目录下可以看到名为flink-root-standalonesession-0-vostro.log的日志文件(您的文件名和我这里略有不同,vostro是我的主机名,root是当前账号),内容如下:
2018-12-16 16:51:00,658 INFO  org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint    - Rest endpoint listening at localhost:8081
2018-12-16 16:51:00,658 INFO  org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint    - http://localhost:8081 was granted leadership with leaderSessionID=00000000-0000-0000-0000-000000000000
2018-12-16 16:51:00,658 INFO  org.apache.flink.runtime.dispatcher.DispatcherRestEndpoint    - Web frontend listening at http://localhost:8081.
2018-12-16 16:51:00,760 INFO  org.apache.flink.runtime.rpc.akka.AkkaRpcService              - Starting RPC endpoint for org.apache.flink.runtime.resourcemanager.StandaloneResourceManager at akka://flink/user/resourcemanager .
2018-12-16 16:51:00,777 INFO  org.apache.flink.runtime.rpc.akka.AkkaRpcService              - Starting RPC endpoint for org.apache.flink.runtime.dispatcher.StandaloneDispatcher at akka://flink/user/dispatcher .
2018-12-16 16:51:00,803 INFO  org.apache.flink.runtime.resourcemanager.StandaloneResourceManager  - ResourceManager akka.tcp://flink@localhost:6123/user/resourcemanager was granted leadership with fencing token 00000000000000000000000000000000
2018-12-16 16:51:00,804 INFO  org.apache.flink.runtime.resourcemanager.slotmanager.SlotManager  - Starting the SlotManager.
2018-12-16 16:51:00,847 INFO  org.apache.flink.runtime.dispatcher.StandaloneDispatcher      - Dispatcher akka.tcp://flink@localhost:6123/user/dispatcher was granted leadership with fencing token 00000000-0000-0000-0000-000000000000
2018-12-16 16:51:00,849 INFO  org.apache.flink.runtime.dispatcher.StandaloneDispatcher      - Recovering all persisted jobs.
2018-12-16 16:51:01,601 INFO  org.apache.flink.runtime.resourcemanager.StandaloneResourceManager  - Registering TaskManager with ResourceID a0692f62811e0452256484a5e46ec5ed (akka.tcp://flink@vostro:40228/user/taskmanager_0) at ResourceManager
2018-12-16 17:19:09,663 INFO  org.apache.flink.runtime.entrypoint.ClusterEntrypoint         - RECEIVED SIGNAL 15: SIGTERM. Shutting down as requested.
2018-12-16 17:19:09,663 INFO  org.apache.flink.runtime.blob.TransientBlobCache              - Shutting down BLOB cache
2018-12-16 17:19:09,668 INFO  org.apache.flink.runtime.blob.BlobServer                      - Stopped BLOB server at 0.0.0.0:35234
  1. 我的机器IP地址为192.168.1.103,因此在浏览器访问http://192.168.1.103:8081,可以见到如下信息:
    Flink1.7从安装到体验_第2张图片

至此,Flink1.7安装、部署、启动完成;

体验Flink1.7

  1. 在机器上执行以下命令连接本机9000端口:
nc -l 9000
  1. 在文件夹flink-1.7.0下执行以下命令,即可监听本机9000端口,等待该端口的数据:
./bin/flink run examples/streaming/SocketWindowWordCount.jar --port 9000
  1. 此时再去刷新web页面,可见如下信息,新增了一个Job:
    Flink1.7从安装到体验_第3张图片
  2. 在执行了nc -l 9000命令的窗口,输入一些句子,每输完一个就按下回车键,如下:
[root@vostro work]# nc -l 9000
hello flink world
aaa bbb ccc
flink start
start flink study, flink go

这样就将上述字符串发送到本机9000端口;
5. 在flink-1.7.0/log目录下,会有flink-root-taskexecutor-0-vostro.out文件出现,您的文件名可能略有不同,其中vostro是我这边的主机名,root是当前账号,打开这个文件看看,出现以下内容:

[root@vostro work]# nc -l 9000
hello flink world
aaa bbb ccc
flink start
start flink study, flink go

可见任务已正常执行,每个句子中的单词数量都被统计出来了;

至此,我们完成了Flink的初体验,在后续的实战中咱们再一起逐渐深入的体验Flink这个强大的框架;

欢迎关注我的公众号:程序员欣宸

Flink1.7从安装到体验_第4张图片

你可能感兴趣的:(Flink,Flink)