1.有jdk6以上环境
2.安装flumeNG
wget http://mirrors.cnnic.cn/apache/flume/stable/apache-flume-1.5.0-bin.tar.gz tar zxvf apache-flume-1.5.0-bin.tar.gz
3.启动
[conf/example.conf]
# 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 = x.x.x.x 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
bin/flume-ng agent -c conf -f conf/example.conf -n a1 -Dflume.root.logger=INFO,console
4. 其它配置
[conf/avrobase.conf]
# Name the components on this agent
a1.sources = r2 r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r2.type = avro
a1.sources.r2.bind = x.x.x.x
a1.sources.r2.port = 44443
a1.sources.r1.type = netcat
a1.sources.r1.bind = x.x.x.x
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.sources.r2.channels = c1
a1.sinks.k1.channel = c1
[conf/fileavro.conf]
# Name the components on this agent a1.sources = r2 r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source a1.sources.r2.type = avro a1.sources.r2.bind = x.x.x.x a1.sources.r2.port = 44443 a1.sources.r1.type = netcat a1.sources.r1.bind = x.x.x.x a1.sources.r1.port = 44444 # Describe the sink #a1.sinks.k1.type = logger a1.sinks.k1.type=file_roll a1.sinks.k1.sink.directory=/home/yxt/soft/flume/test a1.sinks.k1.sink.rollInterval=0 # 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.sources.r2.channels = c1 a1.sinks.k1.channel = c1
5.log4j配置
由于此日志是集群环境使用,所以加上了日志所在机器ip,方便定位问题
log4j.rootLogger=INFO,flume,stdout log4j.appender.flume=org.apache.flume.clients.log4jappender.Log4jAppender log4j.appender.flume.Hostname=x.x.x.x log4j.appender.flume.Port=44443 log4j.appender.flume.encoding=UTF8 log4j.appender.flume.layout=org.apache.log4j.PatternLayout log4j.appender.flume.layout.ConversionPattern=[%X{ip}][%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} [%C : %M : %L]:%m%n
6. 代码[转]&[加]
[pom.xml]
<dependency> <groupId>org.apache.flume.flume-ng-clients</groupId> <artifactId>flume-ng-log4jappender</artifactId> <version>1.5.0</version> <type>jar</type> <scope>compile</scope> </dependency>
[LogTestApp.java]
package flume.log4j.test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; import org.apache.log4j.Logger; import org.apache.log4j.MDC; public class LogTestApp { static{ MDC.put("ip", "test127.0.0.1"); } public static void main(String[] args) throws IOException { Logger logger = Logger.getLogger(LogTestApp.class); BufferedReader in = new BufferedReader( new InputStreamReader(System.in, Charset.forName("UTF-8"))); String line; System.out.println("Initializing Flume log4j appender test."); System.out.println("Each line entered will be sent to Flume."); // send this line to Flume logger.info("LogTestApp initialized"); while ((line = in.readLine()) != null) { System.out.println("Sending to log4j: " + line); logger.info("ok国这e"+line); } } }
相关推荐
Flume-ng在windows环境搭建并测试+log4j日志通过Flume输出到HDFS 11111
Flume + kafka + log4j构建日志采集系统,附实例及文档。
log4j-flume-ng-2.0.2-sources.jar, log4j-flume-ng-2.0.2.jar, log4j-java1.1.jar, log4j-jcl-2.0.2-javadoc.jar, log4j-jcl-2.0.2-sources.jar, log4j-jcl-2.0.2.jar, log4j-jmx-gui-2.0.2-javadoc.jar, log4j-jmx...
log4j输出日志到flume例子,包含log4j配置,flume配置,测试类
log4j使用详解log4j使用详解log4j使用详解log4j使用详解log4j使用详解log4j使用详解log4j使用详解log4j使用详解log4j使用详解log4j使用详解log4j使用详解
log4j使用教程 log4j使用教程 log4j使用教程
针对Log4j 2 远程代码执行漏洞,需要用到的升级资源包,适用于maven资源库,包括log4j,log4j-core,log4j-api,log4j-1.2-api,log4j-jpa等全套2.15.0 maven资源库jar包。如果是maven本地仓库使用,需要将zip包解压...
若依框架使用的log4j2.16.0,修复log4j漏洞log4j2下载最新log4j2.16.0下载
Log4j2学习笔记,引入log4j2的依赖-log4j2.xml配置模板-application.properties文件配置-使用
Apache log4j2零日漏洞,根据 log4j-2.15.0-rc2 版本编译生成log4j-api-2.15.0.jar 1.解压你的jar jar xvf XXX.jar 2. 删除旧版本jar cd ./BOOT-INF/lib rm -rf log4j-api-*.jar 3. 上传新版本log4j-api-2.15.0....
Log4j 是一个日志记录框架,Log4j 2 是对 Log4j 的升级,提供了重大改进,超越其前身 Log4j 1.x,并提供许多其它现代功能 ,例如对标记的支持、使用查找的属性替换、lambda 表达式与日志记录时无垃圾等。 Apache ...
1.该笔记中详细的介绍了log4j的作用和优势、具体地讲解了log4j的使用步骤和详细配置。 2.深入的说明了log4j在项目中的重要地位以及给项目带来的影响,同时说明了log4j的优化。 3.该笔记从log4j的简介/入门开始介绍,到...
Apache log4j2零日漏洞,根据 log4j-2.15.0-rc2 版本编译生成log4j-api-2.15.0.jar 1.解压你的jar jar xvf XXX.jar 2. 删除旧版本jar cd ./BOOT-INF/lib rm -rf log4j-api-*.jar 3. 上传新版本log4j-api-...
log4j+slf4j实现 log4j测试代码,log4j+slf4j实现 log4j测试代码,
此文件教你一步一步教你如何使用Log4j此文件教你一步一步教你如何使用Log4j此文件教你一步一步教你如何使用Log4j此文件教你一步一步教你如何使用Log4j此文件教你一步一步教你如何使用Log4j
下面小编就为大家带来老生常谈Log4j和Log4j2的区别(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
描述Log4j2的配置详情及相对Log4j的优点,包括效率测试程序
log4j.rootLogger=debug,CONSOLE,testfile,A1,MAIL ################### # Console Appender ################### log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.Target=...
apache log4j使用大全 log4j使用
赠送jar包:log4j-to-slf4j-2.17.1.jar; 赠送原API文档:log4j-to-slf4j-2.17.1-javadoc.jar; 赠送源代码:log4j-to-slf4j-2.17.1-sources.jar; 赠送Maven依赖信息文件:log4j-to-slf4j-2.17.1.pom; 包含翻译后...