一:确保以下配置正常
依赖包引入
<dependency>
<groupId>org.apache.flume.flume-ng-clients</groupId>
<artifactId>flume-ng-log4jappender</artifactId>
<version>1.6.0</version>
</dependency>
java产生日志代码
import org.apache.log4j.Logger;
/**
* 模拟日志产生
*/
public class LoggerGenerator {
private static Logger logger = Logger.getLogger(LoggerGenerator.class.getName());
public static void main(String[] args) throws Exception{
int index = 0;
while(true) {
Thread.sleep(1000);
logger.info("value : " + index++);
}
}
}
创建log4j.properties
log4j.rootLogger=INFO,stdout,flume
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target = System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n
log4j.appender.flume = org.apache.flume.clients.log4jappender.Log4jAppender
log4j.appender.flume.Hostname = 你的服务器ip
log4j.appender.flume.Port = 端口
log4j.appender.flume.UnsafeMode = true
在conf下创建streaming.conf
agent1.sources = avro-sources
agent1.sinks = log-sink
agent1.channels = logger-channel
agent1.sources.avro-sources.type = avro
agent1.sources.avro-sources.bind = 服务器ip
agent1.sources.avro-sources.port = 端口(随便写 但不能已经被占用)
agent1.channels.logger-channel.type = memory
agent1.sinks.log-sink.type =logger
agent1.sources.avro-sources.channels = logger-channel
agent1.sinks.log-sink.channel = logger-channel
启动flume
flume-ng agent \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/streaming.conf \
--name agent1 -Dflume.root.logger=INFO,console
二:问题解决
如以上没问题 启动没报错,并且能够产生日日志,可以查看java日志产生的引入包是否正确。正确应该是引入import org.apache.log4j.Logger;,但是idea自动帮我引入import java.util.logging.Logger;,导致无法正常产生日志到flume