在使用 Apache Flume 时,可能会遇到启动报错的情况,其中一个常见问题就是 log4j 错误。本文将结合三个实际案例来分析这个问题,并提供相应的解决方法。
一、问题现象
案例一
执行命令 flume-ng agent -n a1 -c ../conf/ -f ./flume_info.conf -Dflume.root.logger=INFO,console
后,出现以下错误信息:
Info: Including Hive libraries found via () for Hive access
+ exec /service/storm/jdk1.8.0_111/bin/java -Xmx20m -Dflume.root.logger=INFO,console -cp 'conf:/service/storm/flume/lib/*:/lib/*' -Djava.library.path= org.apache.flume.node.Application --conf-file flume.conf --name a1
log4j:WARN No appenders could be found for logger (org.apache.flume.lifecycle.LifecycleSupervisor).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
案例二
执行命令 flume-ng agent -n a1 -c ../ -f ./flume_info.conf -Dflume.root.logger=INFO,console
后,出现以下错误信息:
Info: Including Hive libraries found via () for Hive access
+ exec /service/storm/jdk1.8.0_111/bin/java -Xmx20m -Dflume.root.logger=INFO,console -cp 'conf:/service/storm/flume/lib/*:/lib/*' -Djava.library.path= org.apache.flume.node.Application --conf-file flume.conf --name a1
log4j:WARN No appenders could be found for logger (org.apache.flume.lifecycle.LifecycleSupervisor).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
案例三
执行命令flume-ng agent -c ../ -f flume_info.conf
-n a1 -Dflume.root.logger=INFO,console后,控制台打印如下错误信息:
Info: Including Hive libraries found via () for Hive access
+ exec /root/apps/jdk1.8.0_181/bin/java -Xmx20m -Dflume.root.logger=INFO,console -cp 'c:/root/apps/apache-flume-1.6.0-bin/lib/*:/lib/*' -Djava.library.path= org.apache.flume.node.Application /root/apps/apache-flume-1.6.0-bin/conf -f./avro-hdfs.conf -n al
log4j:WARN No appenders could be found for logger (org.apache.flume.lifecycle.LifecycleSupervisor).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
二、解决方法
将命令改为
flume-ng agent --conf /opt/installs/flume/conf --conf-file flume_into.conf --name a1 -Dflume.root.logger=INFO,console
通过指定绝对路径来确保 Flume 能够正确找到配置文件并初始化 log4j 系统。
总结
在使用 Apache Flume 时,如果遇到 log4j 错误,首先要检查启动命令中的参数配置是否正确。特别是对于涉及到配置文件路径的参数,一定要确保指定的是绝对路径,以避免出现找不到配置文件或无法正确初始化 log4j 系统的问题。通过正确配置启动参数,可以确保 Flume 能够顺利启动并正常运行。