安装

环境

  • Ubuntu 18
  • jdk8
  • flink-1.8.1

安装步骤

  1. 安装jdk(略)

  2. 下载flink-1.8.1-bin-scala_2.12.tgz,解压到指定目录

    wget http://mirror.bit.edu.cn/apache/flink/flink-1.8.1/flink-1.8.1-bin-scala_2.12.tgz

    sudo mkdir /opt/flink

    sudo chown test flink

    sudo chgrp test flink

    tar -zxvf flink-1.8.1-bin-scala_2.12.tgz -C /opt/flink

  3. 单机资源有限,修改配置文件flink-conf.yaml

    The heap size for the JobManager JVM

    jobmanager.heap.size: 256m

    The heap size for the TaskManager JVM

    taskmanager.heap.size: 256m

standalone模式启动

启动

bin目录下执行./start-cluster.sh

jps进程查看

3857 TaskManagerRunner
3411 StandaloneSessionClusterEntrypoint
3914 Jps

查看web页面

运行example

查看结果文件

IDEA中编写flink项目

在idea中会启动一个本地的flink,适合作为开发环境

maven中添加依赖

<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-streaming-java -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.12</artifactId>
<version>1.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-java -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>1.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-clients -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.12</artifactId>
<version>1.8.1</version>
</dependency>
</dependencies>

example代码

package test;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.functions.ReduceFunction;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.windowing.time.Time;
import org.apache.flink.util.Collector; public class StreamingWindowWordCountJava { public static void main(String[] args) throws Exception { // the port to connect to
final int port = 9000; // get the execution environment
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // get input data by connecting to the socket
DataStream<String> text = env.socketTextStream("192.168.29.129", port, "\n"); // parse the data, group it, window it, and aggregate the counts
DataStream<WordWithCount> windowCounts = text
.flatMap(new FlatMapFunction<String, WordWithCount>() {
//@Override
public void flatMap(String value, Collector<WordWithCount> out) {
for (String word : value.split("\\s")) {
out.collect(new WordWithCount(word, 1L));
}
}
})
.keyBy("word")
.timeWindow(Time.seconds(5), Time.seconds(1))
.reduce(new ReduceFunction<WordWithCount>() {
//@Override
public WordWithCount reduce(WordWithCount a, WordWithCount b) {
return new WordWithCount(a.word, a.count + b.count);
}
}); // print the results with a single thread, rather than in parallel
windowCounts.print().setParallelism(1); env.execute("Socket Window WordCount");
} // Data type for words with count
public static class WordWithCount { public String word;
public long count; public WordWithCount() {} public WordWithCount(String word, long count) {
this.word = word;
this.count = count;
} @Override
public String toString() {
return word + " : " + count;
}
}
}

IDEA中运行结果

代码打包运行

上述代码,打包成simple-flink-code.jar

在flink的bin目录下执行:

./flink run -c test.StreamingWindowWordCountJava /home/test/Desktop/simple-flink-code.jar(注意运行类前面写上package名,-c参数顺序在jar包前面,否则报错)

参考

FLINK实例-WORDCOUNT详细步骤

flink安装及standalone模式启动、idea中项目开发的更多相关文章

  1. 深入理解 JBoss 7/WildFly Standalone 模式启动过程

    概述 JBoss 7/WildFly Standalone 模式启动过程大致例如以下: 启动脚本 standalone.sh 启动 JBoss Modules,JBoss Modules 启动 JBo ...

  2. SpringMVC内容略多 有用 熟悉基于JSP和Servlet的Java Web开发,对Servlet和JSP的工作原理和生命周期有深入了解,熟练的使用JSTL和EL编写无脚本动态页面,有使用监听器、过滤器等Web组件以及MVC架构模式进行Java Web项目开发的经验。

    熟悉基于JSP和Servlet的Java Web开发,对Servlet和JSP的工作原理和生命周期有深入了解,熟练的使用JSTL和EL编写无脚本动态页面,有使用监听器.过滤器等Web组件以及MVC架构 ...

  3. Flink架构分析之Standalone模式启动流程

    概述 FLIP6 对Flink架构进行了改进,引入了Dispatcher组件集成了所有任务共享的一些组件:SubmittedJobGraphStore,LibraryCacheManager等,为了保 ...

  4. Spark2.1集群安装(standalone模式)

    机器部署 准备三台Linux服务器,安装好JDK1.7 下载Spark安装包 上传spark-2.1.0-bin-hadoop2.6.tgz安装包到Linux(intsmaze-131)上 解压安装包 ...

  5. MVC模式学习--雇员管理系统项目开发

    1, 项目开发,使用原型开发, ① 开发流程: 需求分析->设计阶段->编码阶段->测试阶段->发布阶段/维护阶段 需求阶段:PM/项目经理 对客户 设计阶段:技术人员(架构师 ...

  6. Spark环境搭建(七)-----------spark的Local和standalone模式启动

    spark的启动方式有两种,一种单机模式(Local),另一种是多机器的集群模式(Standalone) Standalone 搭建: 准备:hadoop001,hadoop002两台安装spark的 ...

  7. Spark2.2.0分布式集群安装(StandAlone模式)

    一.依赖文件安装 1.1 JDK 参见博文:http://www.cnblogs.com/liugh/p/6623530.html 1.2 Scala 参见博文:http://www.cnblogs. ...

  8. 开发工具IntelliJ IDEA的安装步骤及首次启动和创建项目

    开发工具IDEA概述 DEA是一个专门针对Java的集成开发工具(IDE),由Java语言编写.所以,需要有JRE运行环境并配置好环境变量.它可以极大地提升我们的开发效率.可以自动编译,检查错误.在公 ...

  9. iOS中 项目开发易错知识点总结

    点击return取消textView 的响应者 - (BOOL)textFieldShouldReturn:(UITextField *)textField { [_contactTextFiled  ...

随机推荐

  1. 图创图书管理SQL注入漏洞

    payload root@kali:~# sqlmap -u http://2*0.*6.***.3:8080/opac/recommend/recommendBookList/list --data ...

  2. bugkuCTFWEB部分WP

    前言 之前做的今天整理下 这个有点乱不建议大家参考我的wp 这个主要是自己看的.部分的我做的时候打不开就没写. 练手地址:https://ctf.bugku.com 矛盾 矛盾考察的是PHP弱类型首先 ...

  3. CTF-流量分析笔记

    ---恢复内容开始--- 前言 做流量分析很长时间了但是一直没有系统的去总结过这类题目的做法和思路以及wireshark的使用方法,这次做题的时候突然发现了一个总结的特别好的博客,因此想趁机做个笔记总 ...

  4. Mac插件太多太乱怎么办?CleanMyMac直接帮你搞定!

    电脑应用插件在一定程度上便利了大家的生活,保障了用户的使用安全,比如Flash插件.浏览器翻译插件.银行安全登录插件等等.但是许多的插件并不能定位安装的位置,同时部分插件,大部分时候都是只使用一次的, ...

  5. Meetings S 题解

    题目描述 题目链接 有两个牛棚位于一维数轴上的点 \(0\) 和 \(L\) 处.同时有 \(N\) 头奶牛位于数轴上不同的位置(将牛棚和奶牛看作点).每头奶牛 \(i\) 初始时位于某个位置 \(x ...

  6. C语言讲义——字符串

    字符数组 C语言字符串就是字符数组. 单写字符,用单引号.如:'A'. 字符串用双引号.如:"A"."ABC". #include <stdio.h> ...

  7. 基础知识redis详解--【Foam番茄】

    Redis 学习方式: 上手就用 基本的理论先学习,然后将知识融汇贯通 nosql讲解 为什么要用Nosql 现在都是大数据时代 大数据一般的数据库无法进行分析处理了 至少要会Springboot+S ...

  8. ios真机使用fixed定位页面滚动时fixed定位的元素也会跟着滚动

    到了ios真机APP中,页面向下滚动,fixed的元素也跟着滚,虽然最后它还是到了它该在的地方,但是它跟着滚动也很影响页面的流畅性和交互性好伐.

  9. 20190705_关于winform程序修改程序名后, 报未将对象引用设置到对象的实例

    winform做了一个小项目, 其中要用到数据库连接, 字符串, private string ConnStringSource = System.Configuration.Configuratio ...

  10. 第8.7节 Python类__new__方法和构造方法关系深入剖析:__new__方法执行结果对__init__的影响案例详解

    一. 引言 前面章节介绍了类中的构造方法和__new__方法,并分析了二者执行的先后顺序关系.__new__方法在__init__方法前执行,__new__方法执行后才返回实例对象,也就是说__new ...