1.技术选型
A服务器:
exec source + memory channel + avro sink
B服务器:
avro source + memory channel + logger sink
2.日志采集过程
1) 服务器A上监控一个文件,当我们访问主站时会有用户行为日志记录到xx.log中
2) avro sink把新产生的日志输出到对应的avro source指定的hostname和port上
3) 通过avro source对应的agent将我们的日志输出到控制台。
3.配置文件
A服务器:
#example.conf: A single-node Flume configuration
# Name the components on this agent
exec-memory-avro.sources = exec-source
exec-memory-avro.sinks = avro-sink
exec-memory-avro.channels = memory-channel
# Describe/configure the source
exec-memory-avro.sources.exec-source.type = exec
exec-memory-avro.sources.exec-source.command = tail -F /home/hadoop/empcl/test.txt
# Describe the sink
exec-memory-avro.sinks.avro-sink.type = avro
exec-memory-avro.sinks.avro-sink.hostname = slave1
exec-memory-avro.sinks.avro-sink.port = 12364
# Use a channel which buffers events in memory
exec-memory-avro.channels.memory-channel.type = memory
#exec-memory-avro.channels.memory-channel.capacity = 1000
#exec-memory-avro.channels.memory-channel.transactionCapacity = 100
# Bind the source and sink to the channel
exec-memory-avro.sources.exec-source.channels = memory-channel
exec-memory-avro.sinks.avro-sink.channel = memory-channel
B服务器:
#example.conf: A single-node Flume configuration
# Name the components on this agent
avro-memory-logger.sources = avro-source
avro-memory-logger.sinks = logger-sink
avro-memory-logger.channels = memory-channel
# Describe/configure the source
avro-memory-logger.sources.avro-source.type = avro
avro-memory-logger.sources.avro-source.bind = slave1
avro-memory-logger.sources.avro-source.port = 12364
# Describe the sink
avro-memory-logger.sinks.logger-sink.type = logger
# Use a channel which buffers events in memory
avro-memory-logger.channels.memory-channel.type = memory
#avro-memory-logger.channels.memory-channel.capacity = 1000
#avro-memory-logger.channels.memory-channel.transactionCapacity = 100
# Bind the source and sink to the channel
avro-memory-logger.sources.avro-source.channels = memory-channel
avro-memory-logger.sinks.logger-sink.channel = memory-channel
4.启动语句
A服务器:
flume-ng agent
--name exec-memory-avro \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/exec-memory-avro.conf \
-Dflume.root.logger=INFO,console
B服务器:
flume-ng agent \
--name avro-memory-logger \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/avro-memory-logger.conf \
-Dflume.root.logger=INFO,console
5.注意事项
对于A服务器上面的配置我们要注意,我们要将数据sink到另一台服务器上,所以设置的hostname必须是B服务器的hostname。如:
exec-memory-avro.sinks.avro-sink.type = avro
exec-memory-avro.sinks.avro-sink.hostname = slave1
exec-memory-avro.sinks.avro-sink.port = 12364
对于B服务器上面的配置我们要注意,我们要监听是否有数据写到了B服务器上,所以flume要绑定B服务器,即source应该bind为B服务器的主机名。如:
avro-memory-logger.sources.avro-source.type = avro
avro-memory-logger.sources.avro-source.bind = slave1
avro-memory-logger.sources.avro-source.port = 12364