Flume 深入理解02 案例 串联 可靠性 拦截器 avro taildir kafka Interceptor timestamp static Host UUID 拦截器加密 多路选择案例

Flume串联方案
串联
上游:
source : exec source
channel : memory channel
sink : avro sink --<其实就是一个socket客户端,只不过它会把event对象用avro序列化后发送出去>
|
|
下游:
source : avro source --<其实就是一个socket服务端,只不过它会把收到的数据按avro机制反序列化后得到Event>
channel
sink
avro 可跨平台
配置文件:
/**
agent1:
a1.channels.c1.capacity 容量 一千条
a1.channels.c1.transactionCapacity = 100 事务容量100条

a1.sources = r1
a1.channels = c1
a1.sinks = k1

a1.sources.r1.channels = c1
a1.sources.r1.type = exec
a1.sources.r1.command = tail -f /doit15/flume.log

a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sinks.k1.channel = c1
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = linux202
a1.sinks.k1.port = 44444

a2.sources = r1
a2.channels = c1
a2.sinks = k1

a2.sources.r1.channels = c1
a2.sources.r1.type = avrochannels
a2.sources.r1.bind = 0.0.0.0
a2.sources.r1.port = 44444

a2.channels.c1.type = memory
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100

a2.sinks.k1.channel = c1
a2.sinks.k1.type = logger

**/

– 启动

while true; do echo i love you forever >> flume.log; sleep 0.3; done

– 先启动第2级,在linux201上
./bin/flume-ng agent -c ./conf/ -f ./democonf/agen-properties -n a2 -Dflume.root.logger=INFO,console
– 然后启动第1级,在linux202上
./bin/flume-ng agent -c conf/ -f democonf/agen-properties -n a1 -Dflume.root.logger=INFO,console
即可查看LOG输出日志

可靠的source:taildir source
taildir source 在读取数据的过程中,会不断的更新记录所读到的偏移量,以便于奔溃后重启,能够从上次的位置开始继续读取保证source-channel之间不会有数据丢失

监视指定目录下的一批文件,只要某个文件中有新写入的行,则会被tail到

它会记录每一个文件所tail到的位置,记录到一个指定的positionfile保存目录中,格式为json
(如果需要的时候,可以人为修改,就可以让source从任意指定的位置开始读取数据)
它对采集完成的文件,不会做任何修改(比如重命名,删除……)

flume的可靠性问题:端到端可靠
source的可靠性
channel的可靠性
sink的可靠性

/**
kafka
ack=0
ack=1 保证leader把消息持久化成功才响应生产者客户端
ack=-1或者all 所有ISR列表中的follower都同步到了消息,才响应
/**
同时监视二个文件组
读取多个类型日志文件:
使用taildir监控文件,及时文件重命名,也能继续监视到
access.app.log
access.wx.log
event.app.log
event.wx.log
产生数据
while true; do echo access app access app >> access.app.log; echo access wx access wx >> access.wx.log; echo event app event app >> event.app.log; echo event wx event wx >> event.wx.log; sleep 0.2; done

a1.sources.r1.filegroups.g1 = /doit15/access.* (*前面必须是. 不能是-否则无法判别)
Failed loading positionFile: /root/.flume/taildir_position.json
java.io.EOFException: End of input at line 1 column 1
**/

配置文件
/**
a1.sources = r1
a1.channels = c1
a1.sinks =k1

a1.sources.r1.channels = c1
a1.sources.r1.type = TAILDIR
a1.sources.r1.filegroups = g1 g2
a1.sources.r1.filegroups.g1 = /doit15/access.*
a1.sources.r1.filegroups.g2 = /doit15/event.*

a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity =100

a1.sinks.k1.channel = c1
a1.sinks.k1.type = logger
**/
taildir将数据的inode,pos,file偏移量等信息存储在 /root/.flume/taildir_position.json 这样保证数据的可靠性
taildir source会把读到的数据成功写入channel后,再更新记录偏移量
这种机制,能保证数据不会漏采(丢失),但是有可能会产生数据重复!

[root@linux201 .flume]# cat taildir_position.json
[{
“inode”: 651644,
“pos”: 1650,
“file”: “/doit15/access-app.log”
}, {
“inode”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值