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 了,不过得先安装好它.有许多种安装方式,主要分为两种,一种是通过编译源代码来安装:另一种是使用为特定平台预编译好的安装包. 从源代码安装 若是条件允许,从源代码 ...
随机推荐
- 爬虫之Scrapy和分页
下一页和详情页的处理 xpath提取时 注意: 结合网页源代码一起查找 不用框架的爬取 获取下一页 自带href属性 1)首页有下一页 next_url = element.xpath('.//a[t ...
- 记一次虚拟机无法挂载volume的怪异问题排查
故障现象 使用nova volume-attach <server> <volume>命令挂载卷,命令没有返回错误,但是查看虚拟机状态,卷并没有挂载上. 故障原因 疑似虚拟机长 ...
- P2014 选课(树形背包)
P2014 选课 题目描述 在大学里每个学生,为了达到一定的学分,必须从很多课程里选择一些课程来学习,在课程里有些课程必须在某些课程之前学习,如高等数学总是在其它课程之前学习.现在有N门功课,每门课有 ...
- Centos 7下利用crontab定时执行任务详解
一 cron服务 cron服务是Linux的内置服务,但它不会开机自动启动.可以用以下命令启动和停止服务: /sbin/service crond start /sbin/service crond ...
- Leetcode27--->Remove Element(移除数组中给定元素)
题目:给定一个数组array和一个值value,移除掉数组中所有与value值相等的元素,返回新的数组的长度:要求:不能分配额外的数组空间,且必须使用原地排序的思想,空间复杂度O(1); 举例: Gi ...
- 国际化多语言(本地化)缩写 NLS API
NLS Information for Windows 7 LCID Culture Identifier Culture Name Locale Language Country/Region La ...
- BIT+DP
2018CCPC网络赛 J - YJJ's Salesman HDU - 6447 YJJ is a salesman who has traveled through western country ...
- 2018"百度之星"程序设计大赛 - 资格赛
调查问卷 Accepts: 1546 Submissions: 6596 Time Limit: 6500/6000 MS (Java/Others) Memory Limit: 262144 ...
- php rabbitmq操作类及生产者和消费者实例代码 转
注意事项: 1.accept.php消费者代码需要在命令行执行 2.'username'=>'asdf','password'=>'123456' 改成自己的帐号和密码 RabbitMQC ...
- scrapy的调试方法
Parse命令,Scrapy shell,logging 一 Parse命令 检查spider输出的最基本方法是使用Parse命令.这能让你在函数层上检查spider哥哥部分的效果,其十分灵活并且已用 ...