从网络端口采集数据输出到控制台
vi conf/example.conf
# example.conf: A single-node Flume configuration
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
flume-ng agent --name a1 --conf $FLUME_HOME/conf --conf-file $FLUME_HOME/conf/example.conf -Dflume.root.logger=INFO,console
监控一个文件实时采集新增的数据输出到控制台
vi conf/example2.conf
# exec-memory-log
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /usr/data/data.log
a1.sources.r1.shell = /bin/sh -c
# Describe the sink
a1.sinks.k1.type = logger
# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
flume-ng agent --name a1 --conf $FLUME_HOME/conf --conf-file $FLUME_HOME/conf/example2.conf -Dflume.root.logger=INFO,console
将a服务器日志实时采集到b服务器
vi conf/example3a.conf
# exec source + memory channel +avro sink
# Name the components on this agent
a1.sources = exec-source
a1.sinks = avro-sink
a1.channels = memory-channel
# Describe/configure the source
a1.sources.exec-source.type = exec
a1.sources.exec-source.command = tail -F /usr/data/data.log
a1.sources.exec-source.shell = /bin/sh -c
# Describe the sink
a1.sinks.avro-sink.type = avro
a1.sinks.avro-sink.hostname = localhost
a1.sinks.avro-sink.port = 44444
# Use a channel which buffers events in memory
a1.channels.memory-channel.type = memory
# Bind the source and sink to the channel
a1.sources.exec-source.channels = memory-channel
a1.sinks.avro-sink.channel = memory-channel
vi conf/example3b.conf
# avro source + memory channel + logger sink
# Name the components on this agent
b1.sources = avro-source
b1.sinks = logger-sink
b1.channels = memory-channel
# Describe/configure the source
b1.sources.avro-source.type = avro
b1.sources.avro-source.bind = localhost
b1.sources.avro-source.port = 44444
# Describe the sink
b1.sinks.logger-sink.type = logger
# Use a channel which buffers events in memory
b1.channels.memory-channel.type = memory
# Bind the source and sink to the channel
b1.sources.avro-source.channels = memory-channel
b1.sinks.logger-sink.channel = memory-channel
flume-ng agent --name b1 --conf $FLUME_HOME/conf --conf-file $FLUME_HOME/conf/example3b.conf -Dflume.root.logger=INFO,console
flume-ng agent --name a1 --conf $FLUME_HOME/conf --conf-file $FLUME_HOME/conf/example3a.conf -Dflume.root.logger=INFO,console
日志收集过程:
- a监控一个文件,有用户行为日志记录到data.log中
- avro sink -> avro source -> b的控制台