loh4j整合flume的方法是什么
这篇文章主要讲解了“loh4j整合flume的方法是什么”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“loh4j整合flume的方法是什么”吧!
一、配置启动flume
①flume的配置文件 conf/flume-conf.properties(这个文件一般是flume-conf.properties.default),复制修改后缀即可;
配置文件如下:
agent1.channels = ch2
agent1.sources = avro-source1
agent1.sinks = log-sink1
# 定义channel
agent1.channels.ch2.type = memory #mem channel
# 定义source
agent1.sources.avro-source1.channels = ch2
agent1.sources.avro-source1.type = avro #avro source
agent1.sources.avro-source1.bind = 0.0.0.0
agent1.sources.avro-source1.port = 41414
# 定义sink
agent1.sinks.log-sink1.channel = ch2
agent1.sinks.log-sink1.type = logger #logger sink
启动flume
bin/flume-ng agent --conf conf --conf-file conf/flume-conf.properties --name agent1 -Dflume.root.logger=INFO,console
二、log4j的配置
①在log4j.properties文件中添加flume appender
log4j.rootLogger=INFO,flume #日志级别,info和flume
log4j.appender.flume = org.apache.flume.clients.log4jappender.Log4jAppender
log4j.appender.flume.Hostname = 192.168.57.133 #flume地址
log4j.appender.flume.Port = 41414 #flume source监听的端口
log4j.appender.flume.UnsafeMode = true
log4j.appender.flume.layout=org.apache.log4j.PatternLayout
log4j.appender.flume.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n
三、测试
在maven中添加flume appender依赖
<dependency><groupId>org.apache.flume.flume-ng-clients</groupId><artifactId>flume-ng-log4jappender</artifactId><version>1.6.0</version></dependency>
编写简单的测试类:
publicclassLog4jTest{Loggerlogger=LoggerFactory.getLogger(Log4jTest.class);/***测试flume*@Title:flumeTest*@Description:TODO*@param@throwsException*@returnvoid*@throws*/@TestpublicvoidflumeTest()throwsException{while(true){logger.info("spider",System.currentTimeMillis());try{Thread.sleep(1000);}catch(Exceptione){//TODO:handleexceptione.printStackTrace();}}}
运行测试类,可以看到flume在控制台的输出
感谢各位的阅读,以上就是“loh4j整合flume的方法是什么”的内容了,经过本文的学习后,相信大家对loh4j整合flume的方法是什么这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是恰卡编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!