Flume使用(案例分析)
Flume官方文档
Usage: bin/flume-ng <command> [options]...
commands:
help display this help text
agent run a Flume agent
global options:
--conf,-c <conf> use configs in <conf> directory
-Dproperty=value sets a Java system property value
agent options:
--name,-n <name> the name of this agent (required)
--conf-file,-f <file> specify a config file (required if -z missing)
eg:
bin/flume-ng agent --conf conf --name agent-test --conf-file test.conf -Dflume.root.logger=DEBUG,console
bin/flume-ng agent -c conf -n agent-test -f test.conf -Dflume.root.logger=DEBUG,console
一个不能再简单的例子
1.编辑 Conf 范例 (官网和 conf 目录下都有)
# example.conf: A single-node Flume configuration
# 1.定义三个组件的名称
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# 2.配置Source(从哪里连接Sources)
# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = cen-ubuntu
a1.sources.r1.port = 44444
# 3.配置Sink(主要用于输出日志信息)
# Describe the sink
a1.sinks.k1.type = logger
a1.sinks.k1.maxBytesToLog = 1024
# 4.配置Channel(使用存储当做管道)
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# 5.绑定三个组件
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
2.安装 netcat (一个可以传输文件,信息的网络工具)来发送接收信息
$ sudo apt-get install netcat
3.运行实时 flume 实时抓取数据(监控 端口 )
bin/flume-ng agent --conf conf --name a1 --conf-file conf/a1.conf -Dflume.root.logger=DEBUG,console
4.通过 shell 查看端口是否开启成功
netstat -tnlp
5.通过 telnet 向该端口发送数据
telnet cen-ubuntu 44444
6.若Flume接收到数据则表示成功
Event: { headers:{} body: 6E 69 68 61 6F 20 08 0D nihao .. }
各种各样的 Sources
Exec Source 通过执行命令行
a1.sources = r1
a1.channels = c1
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /var/log/secure
Spooling Directory Source 监控一个目录的文件变化
Kafka Source
Syslog Sources 收集系统日志
HTTP Source 通过HTTP协议供互联网下载服务器的数据
NetCat Source
各种各样的Channels
Memory Channel
Kafka Channel
File Channel 存在文件中
各种各样的Sinks
HDFS Sink
Hive Sink
HBase Siinks(HBase Sink ; AsyncHBaseSink)
MorphlineSolrSink 一个ELT工具(Extract, transform, load)
ElasticSearchSink 一个基于Lucene的搜索服务器
案例1:
收集Hive运行的目录到hdfs文件系统
分析:使用 Exec 来监控文件实时性较高,但可靠性较差,当系统命令中断后,数据丢失,或重新读取,数据安全性无法得到保障,生产环境中不能使用;使用文件缓存比内存来得更安全
- Source: Exec Source
tail -f /opt/cdh5.3.6/hive-0.13.1-cdh5.3.6/logs/hive.log - Channel: Memory Channel
- Sink: HDFS Sink
/user/cen/flume/hive-log
1.编写 agent 程序
# example.conf: A single-node Flume configuration
# 1.定义三个组件的名称
# Name the components on this agent
a2.sources = r2
a2.sinks = k2
a2.channels = c2
# 2.配置Source(从哪里连接Sources)
# Describe/configure the source
a2.sources.r2.type = exec
a2.sources.r2.command = tail -F /opt/cdh5.3.6/hive-0.13.1-cdh5.3.6/logs/hive.log
# 3.配置Sink(主要用于输出日志信息)
# Describe the sink
a2.sinks.k2.type = hdfs
# 非高可用的 namenode 指定 host (注1,注2)
a2.sinks.k2.hdfs.path = hdfs://cen-ubuntu:8020/user/cen/flume/hive-log
# 设置前缀
a2.sinks.k2.hdfs.filePrefix = events-
# 数据格式(不压缩的文本数据)
a2.sinks.k2.hdfs.fileType = DataStream
# 存储格式
a2.sinks.k2.hdfs.writeFormat = Text
# 每次写的event数
a2.sinks.k2.hdfs.batchSize = 100
# 设置文件滚动的参数(配合下面一项使用)
a2.sinks.k2.hdfs.rollInterval = 0
a2.sinks.k2.hdfs.rollSize = 1024
a2.sinks.k2.hdfs.rollCount = 0
# 参考http://doc.okbase.net/chiweitree/archive/126197.html
a2.sinks.k2.hdfs.minBlockReplicas=1
# 4.配置Channel(使用存储当做管道)
# Use a channel which buffers events in memory
a2.channels.c2.type = memory
a2.channels.c2.capacity = 1000
a2.channels.c2.transactionCapacity = 100
# 5.绑定三个组件
# Bind the source and sink to the channel
a2.sources.r2.channels = c2
a2.sinks.k2.channel = c2
2.添加相应的jar依赖包(使用 find /dir/dir -name 'filename' 即可轻松找到)
commons-configuration-1.6.jar
hadoop-common-2.5.0-cdh5.3.6.jar
hadoop-auth-2.5.0-cdh5.3.6.jar
hadoop-hdfs-2.5.0-cdh5.3.6.jar
3.执行
bin/flume-ng agent --conf conf --name a2 --conf-file conf/flume-tail.conf -Dflume.root.logger=DEBUG,console
案例二:
收集Hive运行的目录到hdfs文件系统
- Source: Spooling Directory Source
/opt/cdh5.3.6/hive-0.13.1-cdh5.3.6/logs/ - Channel: File Channel
- Sink: HDFS Sink
/user/cen/flume/hive-log
分析:Spooling Directory Source 通过监控文件夹的新增文件来实现日志信息收集。实际生产环境结合 log4j 来使用,日志文件传输完成后会修改其后缀名,添加.COMPLETED 后缀
1.编写 agent 程序
# example.conf: A single-node Flume configuration
# Name the components on this agent
a3.sources = r3
a3.sinks = k3
a3.channels = c3
# Describe/configure the source
a3.sources.r3.type = spooldir
a3.sources.r3.spoolDir = /opt/datas/flume/
a3.sources.r3.ignorePattern = (.)*.log$
# 监控后的文件后缀
a3.sources.r3.fileSuffix = .deleteable
# Describe the sink
a3.sinks.k3.type = hdfs
a3.sinks.k3.hdfs.path = hdfs://cen-ubuntu:8020/user/cen/flume/spool-file-hdfs/%Y%m%d
a3.sinks.k3.hdfs.useLocalTimeStamp = true
a3.sinks.k3.hdfs.filePrefix = events-
a3.sinks.k3.hdfs.fileType = DataStream
a3.sinks.k3.hdfs.writeFormat = Text
a3.sinks.k3.hdfs.batchSize = 10
# Use a channel which buffers events in file
a3.channels.c3.type = file
# 临时文件存储目录(可选)
a3.channels.c3.checkpointDir = /opt/cdh5.3.6/flume-1.5.0-cdh5.3.6/data/filechanel/cheakpoint
a3.channels.c3.dataDirs = /opt/cdh5.3.6/flume-1.5.0-cdh5.3.6/data/filechanel/data
# Bind the source and sink to the channel
a3.sources.r3.channels = c3
a3.sinks.k3.channel = c3
2.执行
bin/flume-ng agent --conf conf --name a3 --conf-file conf/spooling-file-hdfs.conf -Dflume.root.logger=DEBUG,console
3.运行结果
- 被读取过的文件从背上了.delectable 的罪名
- .log 结尾的文件不会被读取
- HDFS文件系统如实出现了被读取的文件,且按日期分文件夹存储
注1:HDFS 的 HA 配置
1.添加配置文件 hdfs-site.xml core-site.xml 到目录 conf 下
2.修改 hdfs 的路径
# 若 namenode 为HA
# a2.sinks.k2.hdfs.path = hdfs://ns1/user/cen/flume/hive-log
注2:特别的,可以设置一定规则(如按时间%Y%m%d)来创建文件目录,详情见官方文档
# 如官方文档所说明,关于时间有关的参数需要在 events 的头中加入服务器的时间这个字段,添加参数如下
hdfs.useLocalTimeStamp = true
注3:使用文件
/bin/sqoop --options-file /opt/datas/filename
Flume使用(案例分析)的更多相关文章
- ENode框架Conference案例分析系列之 - 文章索引
ENode框架Conference案例分析系列之 - 业务简介 ENode框架Conference案例分析系列之 - 上下文划分和领域建模 ENode框架Conference案例分析系列之 - 架构设 ...
- SQL性能优化案例分析
这段时间做一个SQL性能优化的案例分析, 整理了一下过往的案例,发现一个比较有意思的,拿出来给大家分享. 这个项目是我在项目开展2期的时候才加入的, 之前一期是个金融内部信息门户, 里面有个功能是收集 ...
- CSS3-3D制作案例分析实战
一.前言 上一节,介绍了基础的CSS3 3D动画原理实现,也举了一个小小的例子来演示,但是有朋友跟我私信说想看看一些关于CSS3 3D的实例,所以在这里为了满足一下大家的需求,同时也为了以后能够更好的 ...
- 实时控制软件设计第一周作业-汽车ABS软件系统案例分析
汽车ABS软件系统案例分析 ABS 通过控制作用于车轮制动分泵上的制动管路压力,使汽车在紧急刹车时车轮不会抱死,这样就能使汽车在紧急制动时仍能保持较好的方向稳定性. ABS系统一般是在普通制动系统基础 ...
- 个人作业-Week2 案例分析
微软必应词典客户端的案例分析 第一部分 调研,评测 1)bug: 运行平台:iOS 10.0.2 必应词典版本:4.2.2 1. bug标题:词库加载错误 bug详细描述:学习界面中的经典词库出国考试 ...
- 【MySQL】排序原理与案例分析
前言 排序是数据库中的一个基本功能,MySQL也不例外.用户通过Order by语句即能达到将指定的结果集排序的目的,其实不仅仅是Order by语句,Group by语句,Distinct语句都会隐 ...
- 个人作业-Week2:案例分析
截止时间:2016年9月25日24:00. 很多同学有误解,软件工程课是否就是理论课?或者是几个牛人拼命写代码,其他人打酱油的课?要不然就是学习一个程序语言,搞一个职业培训的课? 都不对, 软件工程有 ...
- ORA-04031错误导致宕机案例分析
今天遇到一起ORACLE数据库宕机案例,下面是对这起数据库宕机案例的原因进行分析.解读.分析过程中顺便记录一下这个案例的前因后果,攒点经验值,培养一下分析.解决问题的能力. 案例环境: 操作系统 ...
- 利用windbg查找dictionary导致IIS占CPU100%案例分析(一)
一.背景 先说下windbg使用场景.各位coder在工作中或多或少都会遇到下面四种情况 1.本地代码好好的,放服务器上运行一段时间后,IIS服务突然占用 w3wp.exe CPU突然100% ,不得 ...
- K米APP案例分析
关于 K米 -- 的案例分析 产品 K米的APP (全国KTV点歌,手机直播,互动,交友,预订)的Android客户端 第一部分 调研,评测 评测: 软件的bug,功能评测,黑箱测试 • 下载并使用, ...
随机推荐
- JS的定时到底有多不准
博客逐步迁移到,独立博客,原文地址,http://www.woniubi.cn/js_hide_tab_setinterval/ 我们一直都在说,JS的定时非常的不准确,但是很少有人去验证他,今天我就 ...
- Struts2_默认Action
配置Struts2默认跳转的Action <package name="default" namespace="/" extends="stru ...
- Java—常量和变量
关键字 Java中有特殊用途的词被称为关键字,关键字服务大小写. 标识符 标识符是用于给java程序中的变量.类.方法等命名的符号. 标识符的几条规则: 由字母.数字.下划线(_).美元符号($)组成 ...
- java:图片压缩
java使用google开源工具实现图片压缩 :http://www.cnblogs.com/linkstar/p/7412012.html
- Windows server R2 2008上部署gogs git
所需的环境 1. 安装mysql 安装路径:F:\MySQL Server 5.7 2. 安装gogs ...
- Python基础学习之变量赋值
1.赋值操作符 Python语言中,等号(=)是主要的赋值操作符: >>> aInt=-100 >>> aString='this is a string' > ...
- 获取url中的某个字段的值
function getUrl(name, url) { url = url || window.location.search; var reg = new RegExp("(^|& ...
- 类型构造器--高阶类型(构造器):Kind (type theory)--类型的元
元类型(0阶类型):nullary type, data types 一元类型(一阶类型):unary adj. [数] 一元的 二元类型: is the kind of a binary ty ...
- CUDA Texture纹理存储器 示例程序
原文链接 /* * Copyright 徐洪志(西北农林科技大学.信息工程学院). All rights reserved. * Data: 2012-4-20 */ // // 此程序是演示了1D和 ...
- CentOS6.5 配置IP的两种方式
1.dhcp动态获取ip 编辑配置文件 /etc/sysconfig/network-scripts/ifcfg-eth0 ,配置如下: [root@localhost ~]# vi /etc/sys ...