什么是Flume
- 采集日志,存在HDFS上
- 分布式、高可用、高可靠的海量日志采集、聚合和传输系统
- 支持在日志系统中定制各类数据发送方,用于收集数据
- 支持对数据进行简单处理,写到数据接收方
组件
- source:数据的来源
- channel:数据传输通道
- sink:数据落盘处
配置
- 配置文件
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #bin/flume-ng agent -n a4 -f myagent/a4.conf -c conf -Dflume.root.logger=INFO,console 2 #定义agent名, source、channel、sink的名称 3 a4.sources = r1 4 a4.channels = c1 5 a4.sinks = k1 6 7 #具体定义source 8 a4.sources.r1.type = spooldir 9 a4.sources.r1.spoolDir = /root/training/logs 10 11 #具体定义channel 12 a4.channels.c1.type = memory 13 a4.channels.c1.capacity = 10000 14 a4.channels.c1.transactionCapacity = 100 15 16 #定义拦截器,为消息添加时间戳 17 a4.sources.r1.interceptors = i1 18 a4.sources.r1.interceptors.i1.type = org.apache.flume.interceptor.TimestampInterceptor$Builder 19 20 21 #具体定义sink 22 a4.sinks.k1.type = hdfs 23 a4.sinks.k1.hdfs.path = hdfs://192.168.56.111:9000/flume/%Y%m%d 24 a4.sinks.k1.hdfs.filePrefix = events- 25 a4.sinks.k1.hdfs.fileType = DataStream 26 27 #不按照条数生成文件 28 a4.sinks.k1.hdfs.rollCount = 0 29 #HDFS上的文件达到128M时生成一个文件 30 a4.sinks.k1.hdfs.rollSize = 134217728 31 #HDFS上的文件达到60秒生成一个文件 32 a4.sinks.k1.hdfs.rollInterval = 60 33 34 #组装source、channel、sink 35 a4.sources.r1.channels = c1 36 a4.sinks.k1.channel = c1
命令
- 启动:bin/flume-ng agent -n a4 -f myagent/a4.conf -c conf -Dflume.root.logger=INFO,console
应用
- 采集网络传输信息
- node01安装flume,写配置文件,开启flume
- node02中telnet给node01发送信息
- 采集特定目录下新文件内容到HDFS
- 高可用(failover)
- agent1.sinkgroups.g1.processor.type = failover
- 停掉node02的agent,自动切换到node03上的agent
- 启动node02的agent,由于node02优先级高,自动切换回node02上的agent
- 负载均衡(load balancer)
- a1.sinkgroups.g1.processor.type = load_balance
- 静态拦截器
- 将不同数据源的数据放在不同目录
- 自定义拦截器
- 数据采集后,将不需要的数据过滤掉,并将指定的第一个字段进行加密,再存到hdfs上
- a1.sources.r1.interceptors.i1.type =com.kkb.flume.interceptor.MyInterceptor$MyBuilder
- a1.sources.r1.interceptors.i1.encrypted_field_index=0
- a1.sources.r1.interceptors.i1.out_index=3
- 自定义source
- MySql数据采集到HDFS
参考
官方文档
http://flume.apache.org/releases/content/1.9.0/FlumeUserGuide.html
快速入门
https://www.iteye.com/blog/manzhizhen-2298394
flume插件
https://www.cnblogs.com/mingfengshan/p/6853777.html
flume监控spoolDir日志到HDFS