Flink起步安装和使用
下载安装
下载对应操作系统和版本的flink
# 首先确认下Java环境
$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
# Linux安装
$ wget https://www.apache.org/dyn/closer.lua/flink/flink-1.7.2/flink-1.7.2-bin-scala_2.11.tgz # 下载二进制安装包
$ tar xzf flink-*.tgz # 解压安装包
$ cd flink-1.7.1 # 切到安装包目录
# Mac安装
$ brew install apache-flink
...
# 查看版本
$ flink --version
Version: 1.2.0, Commit ID: 1c659cf
# 查看安装位置
$ brew info apache-flink
https://flink.apache.org/
/usr/local/Cellar/apache-flink/1.7.1 (170 files, 321.1MB) *
Built from source on 2019-02-14 at 09:32:35
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/apache-flink.rb
==> Requirements
Required: java = 1.8 ✔
==> Options
--HEAD
Install HEAD version
==> Analytics
install: 915 (30 days), 3,279 (90 days), 9,094 (365 days)
install_on_request: 899 (30 days), 3,226 (90 days), 8,878 (365 days)
build_error: 0 (30 days)
# Mac上注意事项
# Mac上对应Linux的bin目录在/usr/local/Cellar/apache-flink/1.7.1/libexec
配置运行
$ cd flink-1.7.1
$ ./bin/start-cluster.sh
# 端口运行在localhost:8081
创建IDEA Maven工程 -> Add Archetype
GroupId: org.apache.flink
ArtifactId: flink-quickstart-java
Version: 1.7.1

添加代码
public class SocketWindowWordCount {
public static void main(String[] args) throws Exception {
// the port to connect to
final int port;
try {
final ParameterTool params = ParameterTool.fromArgs(args);
port = params.getInt("port");
} catch (Exception e) {
System.err.println("No port specified. Please run 'SocketWindowWordCount --port <port>'");
return;
}
// get the execution environment
final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
// get input data by connecting to the socket
DataStream<String> text = env.socketTextStream("localhost", 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;
}
}
}
打包运行
$ maven clean package -Dmaven.test.skip=true
开启监听端口
$ nc -l 9000
运行上方代码
# 连接到上方端口, 切到上方打好的jar包路径
$ flink run -c 包路径.SocketWindowWordCount jar包路径 --port 9000 # 包路径指的是当前的java类的package
我们可以在nc中输入数据
$ nc -l 9000
hello hello hello
hehe
your world
查看结果
$ tail -f log/flink-*-taskexecutor-*.out
停止flink
$ ./bin/stop-cluster.sh
Flink起步安装和使用的更多相关文章
- Mac 上flink的安装与启动
在Mac 上安装flink,需要通过Homebrew安装的 1.howmebrew的安装方式,在终端粘贴以下命令,或者去官网https://brew.sh/index_zh-cn 找到此代码复制粘贴到 ...
- Flink本地安装和创建Flink应用
本篇文章首发于头条号Flink本地安装和创建Flink应用,欢迎关注我的头条号和微信公众号"大数据技术和人工智能"(微信搜索bigdata_ai_tech)获取更多干货,也欢迎关注 ...
- Apache Flink教程----安装初体验
1.window 版本安装 https://flink.apache.org/downloads.html#apache-flink-164 D:\flink-1.6.2-bin-scala_2\fl ...
- webpack学习(一)起步安装
起步 webpack 用于编译 JavaScript 模块.一旦完成安装,你就可以通过 webpack 的 CLI 或 API 与其配合交互.如果你还不熟悉 webpack,请阅读核心概念和打包器 ...
- Flink单机版安装与wordCount
Flink为大数据处理工具,类似hadoop,spark.但它能够在大规模分布式系统中快速处理,与spark相似也是基于内存运算,并以低延迟性和高容错性主城,其核心特性是实时的处理流数据.从此大数据生 ...
- Apache Flink 简单安装
流计算这两年很火了,可能对数据的实时性要求高.现在用的hadoop框架,对流计算的支持,主要还是微批(spark),也不支持“Exactly Once”语义(可以使用外接的数据库解决),公司项目可能会 ...
- Flink的安装配置
一. Flink的下载 安装包下载地址:http://flink.apache.org/downloads.html ,选择对应Hadoop的Flink版本下载 [admin@node21 soft ...
- flink linux安装 单机版
1.下载二进制的Flink,根据你喜欢的Hadoop/Scala版本选择对应的Flink版本. https://flink.apache.org/downloads.html2.选择存放目录 解压 f ...
- 起步 - 安装 Git
安装 Git 是时候动手尝试下 Git 了,不过得先安装好它.有许多种安装方式,主要分为两种,一种是通过编译源代码来安装:另一种是使用为特定平台预编译好的安装包. 从源代码安装 若是条件允许,从源代码 ...
随机推荐
- 汇编语言 Part 1——简介、基本语法、内存分段与内存地址
简介 什么是汇编语言? 汇编语言是一种低级的编程语言,在程序的语句和体系结构的机器代码指令之间有很强的对应关系. 每种汇编语言都特定于特定的计算机体系结构,但需要解释或编译.汇编语言也可以称为符号机器 ...
- STM32的IAP方案
from: http://bbs.eeworld.com.cn/thread-294115-1-1.html 几乎所有的同类书籍都介绍综合性的应用示例如“万年历 + 温度显示 + 闹钟响铃 + 计 ...
- Linux学习-SELinux 初探
什么是 SELinux 什么是 SELinux 呢?其实他是『 Security Enhanced Linux 』的缩写,字面上的意义就是安全强化的 Linux 之意! 当初设计的目标:避免资源的误用 ...
- LayoutInflater的用法
Instantiates a layout XML file into its corresponding View objects. It is never used directly. Inste ...
- Selenium WebDriver- 指定页面加载时间
#encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...
- Cookie和Session的作用和工作原理
一.Cookie详解 (1)简介 因为HTTP协议是无状态的,即服务器不知道用户上一次做了什么,这严重阻碍了交互式Web应用程序的实现.在典型的网上购物场景中,用户浏览了几个页面,买了一盒饼干和两饮料 ...
- 【Luogu】P3332K大数查询(树套树)
题目链接 这题我费尽心思不用标记永久化终于卡过去了qwq 权值线段树下面套一个区间线段树.然后乱搞搞即可. // luogu-judger-enable-o2 #include<cstdio&g ...
- [LOJ#531]「LibreOJ β Round #5」游戏
[LOJ#531]「LibreOJ β Round #5」游戏 试题描述 LCR 三分钟就解决了问题,她自信地输入了结果-- > -- 正在检查程序 -- > -- 检查通过,正在评估智商 ...
- Resource 定位、BeanDefinition 的载入和解析,BeanDefinition 注册。
在前文提过,IOC 容器的初始化过程分为三步骤:Resource 定位.BeanDefinition 的载入和解析,BeanDefinition 注册. Resource 定位.我们一般用外部资源来描 ...
- [SDOI2013]直径 (树的直径,贪心)
题目链接 Solution 我们直接找到一条直径 \(s\),起点为 \(begin\),终点为 \(end\). 从前往后遍历点 \(u\) ,若子树中最大的距离与 \(dis(u,begin)\) ...