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”