使用Flume采集Log4j产生的日志

Posted 彪悍大蓝猫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Flume采集Log4j产生的日志相关的知识,希望对你有一定的参考价值。

版本:Flume1.6.0

1.首先加入log4j to flume appender

     <!-- log4j 与 flume-ng做通信 -->
<dependency>
<groupId>org.apache.flume.flume-ng-clients</groupId>
<artifactId>flume-ng-log4jappender</artifactId>
<version>1.6.0</version>
</dependency>

2.添加log4j配置文件

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1,flume

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.target=System.out
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] %x - %m%n

# 1.8以及以上版本与本配置略有不同,详情参照官方doc
log4j.appender.flume = org.apache.flume.clients.log4jappender.Log4jAppender
log4j.appender.flume.Hostname = 0.0.0.0
log4j.appender.flume.Port = 41414
log4j.appender.flume.UnsafeMode = true

3.新增flume配置文件

agent1.sources=avro-source
agent1.sinks=log-sink
agent1.channels=logger-channel

#Describe/configure the source
agent1.sources.avro-source.type=avro
agent1.sources.avro-source.bind=0.0.0.0
agent1.sources.avro-source.port=41414

# Use a channel which buffers events in memory
agent1.channels.logger-channel.type=memory
agent1.channels.logger-channel.capacity=1000
agent1.channels.logger-channel.transactionCapacity=100
# Bind the source and sink to the channel
agent1.sources.avro-source.channels=logger-channel
agent1.sinks.log-sink.channel=logger-channel
agent1.sinks.log-sink.type=logger

4.启动 Flume进行收集

flume-ng agent \
--name agent1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/streaming_my.conf \
-Dflume.root.logger=INFO,console


以上是关于使用Flume采集Log4j产生的日志的主要内容,如果未能解决你的问题,请参考以下文章

Flume案例——日志分析采集系统

如何利用flume从syslog获取日志?

Log4j整合Flume

Flume和Kafka完成实时数据的采集

Flume+Kafka双剑合璧玩转大数据平台日志采集

大数据运维之某银行大数据采集工具Flume性能优化案例