实验课程

THIS NAME

实验课程

当前位置: 首页 >> 实验课程 >> 正文

Storm流式计算-Flink的安装和使用​‍

发布日期:2024-03-05    作者:王树芬     来源:     点击:

实验一:Flink的安装和使用


一、实验目的

通过本关卡学习,你将了解到:安装Flink

二、实验设备与器件

PC

三、实验内容

Flink是一种具有代表性的开源流处理架构,具有十分强大的功能,它实现了Google Dataflow流计算模型,是一种兼具高吞吐、低延迟和高性能的实时流计算框架,并且同时支持批处理流处理
Flink的主要功能特性包括批流一体化、精密的状态管理、事件时间支持以及精确一次的状态一致性保障等Flink不仅可以运行在包括YARN、Mesos、Kuernetes等在内的多种资源管理框架上,还支持在裸机集群上独立部署。

1、安装Flink

Flink的运行需要Java环境的支持,因此,在安装Flink之前,请先参照相关资料安装Java环境(比如Java8)。

相关JDK安装细节可选择对应元子课程自行学习。本课程已经为你安装好了JDK1.8

然后,到Flink官网下载安装包flink-1.9.1-bin-scala_2.11.tgz。假设下载后的安装文件被保存在Linux系统的/opt目录下,然后,使用如下命令对安装文件进行解压缩:

   

   

修改目录名称,并设置权限,命令如下:

   

Flink对于本地模式是开箱即用的,如果要修改Java运行环境,可以修改/usr/local/flink/conf/flink-conf.yaml文件中的env.java.home参数,设置为本地Java的绝对路径
使用如下命令添加环境变量:

   

.bashrc文件中添加如下内容:

   

保存并退出.bashrc文件,然后执行如下命令让配置文件生效:

   

使用如下命令启动Flink

   

使用jps命令查看进程:

   

如果能够看到TaskManagerRunnerStandaloneSessionClusterEntrypoint这两个进程,就说明启动成功

FlinkJobManager同时会在8081端口上启动一个Web前端,可以在浏览器中输入http://localhost:8081来访问,如图所示:

   

Flink安装包中自带了测试样例,这里可以运行WordCount样例程序来测试Flink的运行效果,具体命令如下:

   

编程要求

根据以下要求,完成对应操作:

完成Flink安装

测试说明

编程要求完成操作后,请点击评测按钮,系统会自动对你的操作进行评测。
当你的结果与预期输出一致时,即为通过。

实验二:Flink初级编程实践

一、实验目的

通过本关卡的练习,您将掌握以下内容:

基本的Flink编程方法;

用Eclipse工具编写Flink程序的方法。

二、实验设备与器件

PC机、流式计算开发环境

三、实验内容

基本的Flink编程方法;

用Eclipse工具编写Flink程序的方法。

(一)设计题目

1.     Maven安装包路径:/opt/apache-maven-3.6.3-bin.zip

注意:
建议Maven安装完成后设置为阿里云镜像仓库:
https://maven.aliyun.com/repository/public

2.       使用Eclipse工具开发WordCount程序,并打包成JAR文件,提交到Flink中运行,Jar上传路径:/usr/local/hadoop/FlinkWordCount-0.0.1-SNAPSHOT.jar,需要统计的原始数据如下:

(1)public static final String[] WORDS=new String[]{"To be, or not to be,--that is the question:--", "Whether \'tis nobler in the mind to suffer", "The slings and arrows of outrageous fortune", "Or to take arms against a sea of troubles,", "And by opposing end them?--To die,--to sleep,--", "No more; and by a sleep to say we end", "The heartache, and the thousand natural shocks", "That flesh is heir to,--\'tis a consummation", "Devoutly to be wish\'d. To die,--to sleep;--", "To sleep! perchance to dream:--ay, there\'s the rub;", "For in that sleep of death what dreams may come,", "When we have shuffled off this mortal coil,", "Must give us pause: there\'s the respect", "That makes calamity of so long life;", "For who would bear the whips and scorns of time,", "The oppressor\'s wrong, the proud man\'s contumely,", "The pangs of despis\'d love, the law\'s delay,", "The insolence of office, and the spurns", "That patient merit of the unworthy takes,", "When he himself might his quietus make", "With a bare bodkin? who would these fardels bear,", "To grunt and sweat under a weary life,", "But that the dread of something after death,--", "The undiscover\'d country, from whose bourn", "No traveller returns,--puzzles the will,", "And makes us rather bear those ills we have", "Than fly to others that we know not of?", "Thus conscience does make cowards of us all;", "And thus the native hue of resolution", "Is sicklied o\'er with the pale cast of thought;", "And enterprises of great pith and moment,", "With this regard, their currents turn awry,", "And lose the name of action.--Soft you now!", "The fair Ophelia!--Nymph, in thy orisons", "Be all my sins remember\'d."};

注意:
Maven项目的依赖及版本请按照如下配置:

3.      

   

如果Maven设置了阿里云或其他外网镜像仓库,但无法下载依赖,很可能代表你处在内网环境下,无法访问到外网的镜像仓库,可以设置Maven为我们提前准备好的私有镜像仓库:http://nexus3.plugins.svc/repository/maven-public/,然后再尝试下载所需依赖。数据流词频统计
使用Linux系统自带的NC程序模拟生成数据流,不断产生单词并发送出去。编写Flink程序对NC程序发来的单词进行实时处理,计算词频,并把词频统计结果输出。要求打成JAR包部署到Flink中运行,Jar上传路径:
/usr/local/hadoop/FlinkWordCount2-0.0.1-SNAPSHOT.jar

测试说明

在按编程要求完成操作后,请点击评测按钮,系统会自动对你的操作进行评测。
当你的结果与预期输出一致时,即为通过。
预期输出:

   

上一条:Storm流式计算-Flink初级编程实践 下一条:R语言多元数据分析-R语言数据结构—数据框

关闭