<Spark Streaming><Flume><Integration>
Overview
- Flume:一个分布式的,可靠的,可用的服务,用于有效地收集、聚合、移动大规模日志数据
- 我们搭建一个flume + Spark Streaming的平台来从Flume获取数据,并处理它。
- 有两种方法实现:使用flume-style的push-based方法,或者使用自定义的sink来实现pull-based方法。
Approach 1: Flume-style Push-based Approach
- flume被设计用来在Flume agents之间推信息,在这种方式下,Spark Streaming安装一个receiver that acts like an Avro agent for Flume, to which Flume can push the data.
General Requirement
- 当你启动flume + spark streaming应用时,该机器上必须运行一个Spark workers。
- flume可以向该机器的某一个port push数据。
- 基于这种push机制,streaming应用必须有一个receiver scheduled and listening on the chosen port.
Configuring Flume
- 配置flume以向Avro sink发送数据
agent.sinks = avroSink
agent.sinks.avroSink.type = avro
agent.sinks.avroSink.channel = memoryChannel
agent.sinks.avroSink.hostname = <chosen machine's hostname>
agent.sinks.avroSink.port = <chosen port on the machine>
Configuring Spark Streaming Application
- Linking: 在maven项目中配置依赖
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming-flume-sink_2.10</artifactId>
<version>2.1.0</version>
</dependency>
2. Programming:import FlumeUtils, 创建input DStream
import org.apache.spark.streaming.flume._ val flumeStream = FlumeUtils.createStream(streamingContext, [chosen machine's hostname], [chosen port])
- 注意:应该与cluster中的resourceManager使用同一个hostname,这样的话资源分配可以匹配names,并在正确的机器上launch receiver
- 一个简单的Spark Streaming统计Flume event个数的demo代码:
object FlumeEventCount {
def main(args: Array[String]) {
if (args.length < 2) {
System.err.println(
"Usage: FlumeEventCount <host> <port>")
System.exit(1)
} StreamingExamples.setStreamingLogLevels() val Array(host, IntParam(port)) = args val batchInterval = Milliseconds(2000) // Create the context and set the batch size
val sparkConf = new SparkConf().setAppName("FlumeEventCount")
val ssc = new StreamingContext(sparkConf, batchInterval) // Create a flume stream
val stream = FlumeUtils.createStream(ssc, host, port, StorageLevel.MEMORY_ONLY_SER_2) // Print out the count of events received from this server in each batch
stream.count().map(cnt => "Received " + cnt + " flume events." ).print() ssc.start()
ssc.awaitTermination()
}
}
<Spark Streaming><Flume><Integration>的更多相关文章
- 简单物联网:外网访问内网路由器下树莓派Flask服务器
最近做一个小东西,大概过程就是想在教室,宿舍控制实验室的一些设备. 已经在树莓上搭了一个轻量的flask服务器,在实验室的路由器下,任何设备都是可以访问的:但是有一些限制条件,比如我想在宿舍控制我种花 ...
- 利用ssh反向代理以及autossh实现从外网连接内网服务器
前言 最近遇到这样一个问题,我在实验室架设了一台服务器,给师弟或者小伙伴练习Linux用,然后平时在实验室这边直接连接是没有问题的,都是内网嘛.但是回到宿舍问题出来了,使用校园网的童鞋还是能连接上,使 ...
- 外网访问内网Docker容器
外网访问内网Docker容器 本地安装了Docker容器,只能在局域网内访问,怎样从外网也能访问本地Docker容器? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Docker容器 ...
- 外网访问内网SpringBoot
外网访问内网SpringBoot 本地安装了SpringBoot,只能在局域网内访问,怎样从外网也能访问本地SpringBoot? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装Java 1 ...
- 外网访问内网Elasticsearch WEB
外网访问内网Elasticsearch WEB 本地安装了Elasticsearch,只能在局域网内访问其WEB,怎样从外网也能访问本地Elasticsearch? 本文将介绍具体的实现步骤. 1. ...
- 怎样从外网访问内网Rails
外网访问内网Rails 本地安装了Rails,只能在局域网内访问,怎样从外网也能访问本地Rails? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Rails 默认安装的Rails端口 ...
- 怎样从外网访问内网Memcached数据库
外网访问内网Memcached数据库 本地安装了Memcached数据库,只能在局域网内访问,怎样从外网也能访问本地Memcached数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装 ...
- 怎样从外网访问内网CouchDB数据库
外网访问内网CouchDB数据库 本地安装了CouchDB数据库,只能在局域网内访问,怎样从外网也能访问本地CouchDB数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动Cou ...
- 怎样从外网访问内网DB2数据库
外网访问内网DB2数据库 本地安装了DB2数据库,只能在局域网内访问,怎样从外网也能访问本地DB2数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动DB2数据库 默认安装的DB2 ...
- 怎样从外网访问内网OpenLDAP数据库
外网访问内网OpenLDAP数据库 本地安装了OpenLDAP数据库,只能在局域网内访问,怎样从外网也能访问本地OpenLDAP数据库? 本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动 ...
随机推荐
- How-to: Use HBase Bulk Loading, and Why
How-to: Use HBase Bulk Loading, and Why http://blog.cloudera.com/blog/2013/09/how-to-use-hbase-bulk- ...
- 删除gitlab 上的文件
- pycharm配置appium 提示unsrsloved reference
1.如:进入C:\Users\Administrator\PycharmProjects\project\venv 输入:在cmd 下进入 venv 输入 Scripts\activate 回车 ...
- grep 和curl -d等命令 单引号里面既使用正则,又使用变量的方法
a='{"type":"d_log", "log_format":"d_log", "exclude" ...
- js javascript 容错处理代码屏蔽js错误
加入到head <SCRIPT language=javascript> window.onerror=function(){return true;} </SCRIPT> o ...
- Utils--前台调用后台接口工具类
Utils--前台调用后台接口工具类 package com.taotao.manage.httpclient; import java.io.IOException; import java.net ...
- 使用AJAX报406错误
使用AJAX报406错误,基本有一下两种情况: (1)90%的可能是没有添加jackson包: (2)10%的可能是请求的url后缀是*.html 在springmvc里面,如果请求的是*.html, ...
- WannaCry(永恒之蓝)病毒处理方法
1.直接关闭server服务 打开cmd执行关闭server服务即可: net stop server 控制面板--管理工具--服务里手动关掉 2.防火墙限制445端口 3.打补丁 [KB401259 ...
- CAS5.3-搭建https服务器
在上一篇文章中https://www.cnblogs.com/zhi-leaf/p/10417627.html.我们使用http://127.0.0.1:8080/cas/登录发现页面显示如下警告.该 ...
- python ctrl+c
#!/usr/bin/env pythonimport signalimport sysimport osdef signal_handler(signal, frame): print('You p ...