1、配置啓動flume java
①flume的配置文件 conf/flume-conf.properties(這個文件通常是flume-conf.properties.default),複製修改後綴便可; apache
配置文件以下: app
agent1.channels = ch1
agent1.sources = avro-source1
agent1.sinks = log-sink1
# 定義channel
agent1.channels.ch1.type = memory #mem channel
# 定義source
agent1.sources.avro-source1.channels = ch1
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 = ch1
agent1.sinks.log-sink1.type = logger #logger sink maven
啓動flume ide
bin/flume-ng agent --conf conf --conf-file conf/flume-conf.properties --name agent1 -Dflume.root.logger=INFO,console 測試
2、log4j的配置 spa
①在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
3、測試
code
在maven中添加flume appender依賴 ip
<dependency> <groupId>org.apache.flume.flume-ng-clients</groupId> <artifactId>flume-ng-log4jappender</artifactId> <version>1.6.0</version> </dependency>
編寫簡單的測試類:
public class Log4jTest { Logger logger = LoggerFactory.getLogger(Log4jTest.class); /** * 測試flume * @Title: flumeTest * @Description: TODO * @param @throws Exception * @return void * @throws */ @Test public void flumeTest() throws Exception { while(true){ logger.info("spider", System.currentTimeMillis()); try { Thread.sleep(1000); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } }