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使用(案例分析)的更多相关文章

  1. ENode框架Conference案例分析系列之 - 文章索引

    ENode框架Conference案例分析系列之 - 业务简介 ENode框架Conference案例分析系列之 - 上下文划分和领域建模 ENode框架Conference案例分析系列之 - 架构设 ...

  2. SQL性能优化案例分析

    这段时间做一个SQL性能优化的案例分析, 整理了一下过往的案例,发现一个比较有意思的,拿出来给大家分享. 这个项目是我在项目开展2期的时候才加入的, 之前一期是个金融内部信息门户, 里面有个功能是收集 ...

  3. CSS3-3D制作案例分析实战

    一.前言 上一节,介绍了基础的CSS3 3D动画原理实现,也举了一个小小的例子来演示,但是有朋友跟我私信说想看看一些关于CSS3 3D的实例,所以在这里为了满足一下大家的需求,同时也为了以后能够更好的 ...

  4. 实时控制软件设计第一周作业-汽车ABS软件系统案例分析

    汽车ABS软件系统案例分析 ABS 通过控制作用于车轮制动分泵上的制动管路压力,使汽车在紧急刹车时车轮不会抱死,这样就能使汽车在紧急制动时仍能保持较好的方向稳定性. ABS系统一般是在普通制动系统基础 ...

  5. 个人作业-Week2 案例分析

    微软必应词典客户端的案例分析 第一部分 调研,评测 1)bug: 运行平台:iOS 10.0.2 必应词典版本:4.2.2 1. bug标题:词库加载错误 bug详细描述:学习界面中的经典词库出国考试 ...

  6. 【MySQL】排序原理与案例分析

    前言 排序是数据库中的一个基本功能,MySQL也不例外.用户通过Order by语句即能达到将指定的结果集排序的目的,其实不仅仅是Order by语句,Group by语句,Distinct语句都会隐 ...

  7. 个人作业-Week2:案例分析

    截止时间:2016年9月25日24:00. 很多同学有误解,软件工程课是否就是理论课?或者是几个牛人拼命写代码,其他人打酱油的课?要不然就是学习一个程序语言,搞一个职业培训的课? 都不对, 软件工程有 ...

  8. ORA-04031错误导致宕机案例分析

    今天遇到一起ORACLE数据库宕机案例,下面是对这起数据库宕机案例的原因进行分析.解读.分析过程中顺便记录一下这个案例的前因后果,攒点经验值,培养一下分析.解决问题的能力. 案例环境:   操作系统 ...

  9. 利用windbg查找dictionary导致IIS占CPU100%案例分析(一)

    一.背景 先说下windbg使用场景.各位coder在工作中或多或少都会遇到下面四种情况 1.本地代码好好的,放服务器上运行一段时间后,IIS服务突然占用 w3wp.exe CPU突然100% ,不得 ...

  10. K米APP案例分析

    关于 K米 -- 的案例分析 产品 K米的APP (全国KTV点歌,手机直播,互动,交友,预订)的Android客户端 第一部分 调研,评测 评测: 软件的bug,功能评测,黑箱测试 • 下载并使用, ...

随机推荐

  1. Jetty服务器的使用

    Jetty 是一个开源的servlet容器,它为基于Java的web容器,例如JSP和servlet提供运行环境.Jetty是使用Java语言编写的,它的API以一组JAR包的形式发布.开发人员可以将 ...

  2. 初看Mybatis 源码 (二) Java动态代理类

    先抛出一个问题,用过Mybatis的都知道,我们只需要定义一个Dao的接口,在里面写上一些CRUD相关操作,然后配置一下sql映射文件,就可以达到调用接口中的方法,然后执行sql语句的效果,为什么呢? ...

  3. attachEvent方法的作用

    用于HTML内代码层和UI层分离.比如,你要给一个按钮增加一个单击事件,你会怎么做?<input type="button" id="theBtn" va ...

  4. Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.错误

    错误如图示: 1.在php的目录下建立个文件夹tmp,这个有权限的问题,如果是ntfs的分区,就一定要添加evryone的控制权限,否则是没用的.2.在php.ini找到session.save_pa ...

  5. bzoj2568 比特集合

    Description 比特集合是一种抽象数据类型(Abstract Data Type) ,其包含一个集合S,并支持如下几种操作: INS M : 将元素 M 插入到集合S中: DEL M : 将集 ...

  6. ABI 管理

    https://developer.android.google.cn/ndk/guides/abis.html 不同 Android 手机使用不同的 CPU,因此支持不同的指令集.CPU 与指令集的 ...

  7. Ubuntu搜狗输入法无法输入中文等问题

    Linux版本的搜狗输入法经常崩溃,无法输入中文,今天作下记录,环境:Ubuntu14.04 64位 1.安装和卸载 Linux搜狗是基于框架fcitx的,先得安装框架Ubunt安装搜狗方法 也可以直 ...

  8. Spring注解@Value数值取值转换字符串失败

    配置文件(yml)中,配置项如下: cebconfig: INST_CODE: 08801001 SFT_NOTIFY_CEB_CHANNEL: 123456 期望INST_CODE: 0880100 ...

  9. Android 最新学习资料收集

    收集这份资料的灵感来源于我的浏览器收藏夹快爆了,后来在github 上也看到了很优秀的开源库的收集资料,非常的好,但是太过于多,也不够新,所以决定自己来做一个.原始的markdowm文件已经放到git ...

  10. 知识总结和记录——Bootstrap

    官方地址:https://getbootstrap.com 中文地址:http://www.bootcss.com/ 使用V3版本的Bootstrap,下载的是用于生产环境的Bootstrap. 目录 ...