1、下载

http://mirror.bit.edu.cn/apache/flink/

2、安装

确保已经安装java8以上

解压flink
tar zxvf flink-1.8.0-bin-scala_2.11.tgz 启动本地模式
$ ./bin/start-cluster.sh # Start Flink
[hadoop@bigdata-senior01 flink-1.8.0]$ ./bin/start-cluster.sh
Starting cluster.
Starting standalonesession daemon on host bigdata-senior01.home.com.
Starting taskexecutor daemon on host bigdata-senior01.home.com.
[hadoop@bigdata-senior01 flink-1.8.0]$ jps
1995 StandaloneSessionClusterEntrypoint
2443 TaskManagerRunner
2526 Jps

3、访问flink

http://localhost:8081

4、第一个程序wordcount,从一个socket流中读出字符串,计算10秒内的词频

4.1 引入依赖

    <dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-clients_2.12</artifactId>
<version>1.8.0</version>
</dependency> <dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.12</artifactId>
<version>1.8.0</version>
<scope>provided</scope>
</dependency> </dependencies>

4.2 代码

public class SocketWindowWordCount {

    public static void main(String args[]) throws Exception {

        // the host and the port to connect to
final String hostname;
final int port;
try {
final ParameterTool params = ParameterTool.fromArgs(args);
hostname = params.has("hostname") ? params.get("hostname") : "localhost";
port = params.getInt("port");
} catch (Exception e) {
e.printStackTrace();
System.err.println(e.getMessage());
System.err.println("No port specified. Please run 'SocketWindowWordCount " +
"--hostname <hostname> --port <port>', where hostname (localhost by default) " +
"and port is the address of the text server");
System.err.println("To start a simple text server, run 'netcat -l <port>' and " +
"type the input text into the command line");
return;
} // get the execution environment
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); // get input data by connecting to the socket
DataStream<String> text = env.socketTextStream(hostname, 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) throws Exception {
for (String word : value.split("\\s")) {
out.collect(new WordWithCount(word,1L));
}
}
})
.keyBy("word")
.timeWindow(Time.seconds(10))
.reduce(new ReduceFunction<WordWithCount>() {
@Override
public WordWithCount reduce(WordWithCount value1, WordWithCount value2) throws Exception {
return new WordWithCount(value1.word,value1.count+value2.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;
}
}
}

4.4 编译成jar包上传

先用nc启动侦听并接受连接

nc -lk 9000

启动SocketWindowWordCount
[hadoop@bigdata-senior01 bin]$ ./flink run /home/hadoop/SocketWindowWordCount.jar --port 9000 查看输出
[root@bigdata-senior01 log]# tail -f flink-hadoop-taskexecutor-0-bigdata-senior01.home.com.out
在nc端输入字符串,在日志监控端10秒为一个周期就可以看到输出合计。

flink 安装及wordcount的更多相关文章

  1. Flink单机版安装与wordCount

    Flink为大数据处理工具,类似hadoop,spark.但它能够在大规模分布式系统中快速处理,与spark相似也是基于内存运算,并以低延迟性和高容错性主城,其核心特性是实时的处理流数据.从此大数据生 ...

  2. 第02讲:Flink 入门程序 WordCount 和 SQL 实现

    我们右键运行时相当于在本地启动了一个单机版本.生产中都是集群环境,并且是高可用的,生产上提交任务需要用到flink run 命令,指定必要的参数. 本课时我们主要介绍 Flink 的入门程序以及 SQ ...

  3. Eclipse的下载、安装和WordCount的初步使用(本地模式和集群模式)

    包括:    Eclipse的下载 Eclipse的安装 Eclipse的使用 本地模式或集群模式 Scala IDE for Eclipse的下载.安装和WordCount的初步使用(本地模式和集群 ...

  4. IntelliJ IDEA的下载、安装和WordCount的初步使用(本地模式和集群模式)

    包括: IntelliJ IDEA的下载  IntelliJ IDEA的安装 IntelliJ IDEA中的scala插件安装 用SBT方式来创建工程 或 选择Scala方式来创建工程 本地模式或集群 ...

  5. Hadoop-2.4.0安装和wordcount执行验证

    Hadoop-2.4.0安装和wordcount执行验证 下面描写叙述了64位centos6.5机器下,安装32位hadoop-2.4.0,并通过执行 系统自带的WordCount样例来验证服务正确性 ...

  6. IntelliJ IDEA(Ultimate版本)的下载、安装和WordCount的初步使用(本地模式和集群模式)

    不多说,直接上干货! IntelliJ IDEA号称当前Java开发效率最高的IDE工具.IntelliJ IDEA有两个版本:社区版(Community)和旗舰版(Ultimate).社区版时免费的 ...

  7. IntelliJ IDEA(Community版本)的下载、安装和WordCount的初步使用(本地模式和集群模式)

    不多说,直接上干货! 对于初学者来说,建议你先玩玩这个免费的社区版,但是,一段时间,还是去玩专业版吧,这个很简单哈,学聪明点,去搞到途径激活!可以看我的博客. 包括: IntelliJ IDEA(Co ...

  8. 从flink-example分析flink组件(3)WordCount 流式实战及源码分析

    前面介绍了批量处理的WorkCount是如何执行的 <从flink-example分析flink组件(1)WordCount batch实战及源码分析> <从flink-exampl ...

  9. 2、flink入门程序Wordcount和sql实现

    一.DataStream Wordcount 代码地址:https://gitee.com/nltxwz_xxd/abc_bigdata 基于scala实现 maven依赖如下: <depend ...

随机推荐

  1. Provider和Consumer的搭建(六)

    创建三个Maven Project: dubbo-service:公共模块,包括服务接口(packaging:jar) dubbo-service-impl:服务提供方,提供服务接口的具体实现,需要依 ...

  2. NOIP 2004 合并果子

    洛谷P1090 https://www.luogu.org/problemnew/show/P1090 JDOJ 1270 题目描述 在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分 ...

  3. Associatively Segmenting Instances and Semantics in Point Clouds

    论文引入一个简单且灵活的框架同时分割点云中的实例和语义,进一步提出两种方法让两个任务从彼此受益. 代码: https://github.com/WXinlong/ASIS 论文: https://ar ...

  4. node fs相对路径

    如果在js里面使用了node.js的fs,在传入path参数时,如果使用相对路径,按照根目录的层级就是用就好. 比如:目录结构为: a -b -c -c1.js d 在c1.js中调用时,如果需要使用 ...

  5. Excel-统计函数

    1.Count系列函数 COUNT 数字个数----下面结果为 4 counta 非空的字数 ----下面为6 COUNTBLANK ------非空个数  ---- 下面为9 如何将字符串形式的数字 ...

  6. 使用jattach 在host 节点查看容器jvm信息

    jattach是基于hostspot attach api 指南编写的轻量all in one(jmap,jstack,jcmd,jinfo) 的工具 包含了以下命令 load 家在agent lib ...

  7. Codeforces Round #549 (Div. 2) E 倍增处理按排列顺序的上一个位置

    https://codeforces.com/contest/1143/problem/E 题意 p为n的一个排列,给出有m个数字的数组a,q次询问,每次询问a数组区间[l,r]中是否存在子序列为p的 ...

  8. 日常歌颂zyj

    今年的中秋节... 我貌似遇到了一个灰常 灰常灰常优秀的 大哥哥~~ (貌似是条高二狗) 最开始在贴吧颓废... 然后... 开始逐条的回复... 开始去,,, 逐步查看,,, 发现这个优秀的楼主会 ...

  9. 【CF438D】The Child and Sequence(线段树)

    点此看题面 大致题意: 给你一个序列,让你支持区间求和.区间取模.单点修改操作. 区间取模 区间求和和单点修改显然都很好维护吧,难的主要是区间取模. 取模标记无法叠加,因此似乎只能暴力搞? 实际上,我 ...

  10. machine_math2

    1. 2. 3.拉格朗日对偶??? 弱对偶 强对偶: <1>slater条件(强对偶的充分条件): 1.凸函数. 2.存在一个可行解满足不等式成立. 4.KKT条件