继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

使用Flume采集Log4j产生的日志

彪悍大蓝猫
关注TA
已关注
手记 4
粉丝 1
获赞 0

版本: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 
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP