2

我正在尝试使用 Log4J Flume appender 通过 Flume 将 Log4J 1x 中的事件导入 HDFS。创建了两个附加程序文件和水槽。它适用于 FILE 附加程序,但使用水槽附加程序,程序只会挂在 Eclipse 中。Flume 工作正常,我可以使用 avro 客户端向 avro 源发送消息,并在 HDFS 中查看消息。但是,它没有与 Log4J 1x 集成。

我没有看到任何异常,除了 log.out 中的以下内容。

Batch size string = null
Using Netty bootstrap options: {tcpNoDelay=true, connectTimeoutMillis=20000}
Connecting to localhost/127.0.0.1:41414
[id: 0x52a00770] OPEN

并从 Flume 控制台

2013-10-23 14:32:32,145 (pool-5-thread-1) [INFO - org.apache.avro.ipc.NettyServer$NettyServerAvroHandler.handleUpstream(NettyServer.java:171)] [id: 0x577cf6e4, /127.0.0.1:46037 => /127.0.0.1:41414] OPEN
2013-10-23 14:32:32,148 (pool-6-thread-1) [INFO - org.apache.avro.ipc.NettyServer$NettyServerAvroHandler.handleUpstream(NettyServer.java:171)] [id: 0x577cf6e4, /127.0.0.1:46037 => /127.0.0.1:41414] BOUND: /127.0.0.1:41414
2013-10-23 14:32:32,148 (pool-6-thread-1) [INFO - org.apache.avro.ipc.NettyServer$NettyServerAvroHandler.handleUpstream(NettyServer.java:171)] [id: 0x577cf6e4, /127.0.0.1:46037 => /127.0.0.1:41414] CONNECTED: /127.0.0.1:46037
2013-10-23 14:32:43,086 (pool-6-thread-1) [INFO - org.apache.avro.ipc.NettyServer$NettyServerAvroHandler.handleUpstream(NettyServer.java:171)] [id: 0x577cf6e4, /127.0.0.1:46037 :> /127.0.0.1:41414] DISCONNECTED
2013-10-23 14:32:43,096 (pool-6-thread-1) [INFO - org.apache.avro.ipc.NettyServer$NettyServerAvroHandler.handleUpstream(NettyServer.java:171)] [id: 0x577cf6e4, /127.0.0.1:46037 :> /127.0.0.1:41414] UNBOUND
2013-10-23 14:32:43,096 (pool-6-thread-1) [INFO - org.apache.avro.ipc.NettyServer$NettyServerAvroHandler.handleUpstream(NettyServer.java:171)] [id: 0x577cf6e4, /127.0.0.1:46037 :> /127.0.0.1:41414] CLOSED
2013-10-23 14:32:43,097 (pool-6-thread-1) [INFO - org.apache.avro.ipc.NettyServer$NettyServerAvroHandler.channelClosed(NettyServer.java:209)] Connection to /127.0.0.1:46037 disconnected.

如果它有帮助,我确实在调试模式下运行了程序,当它挂起时,我做了一个挂起并获取堆栈跟踪。试图查看代码,但不确定为什么程序与水槽附加程序一起挂起。

Daemon Thread [Avro NettyTransceiver I/O Worker 1] (Suspended)  
Logger(Category).callAppenders(LoggingEvent) line: 205  
Logger(Category).forcedLog(String, Priority, Object, Throwable) line: 391  
Logger(Category).log(String, Priority, Object, Throwable) line: 856  
Log4jLoggerAdapter.debug(String) line: 209  
NettyTransceiver$NettyClientAvroHandler.handleUpstream(ChannelHandlerContext, ChannelEvent) line: 491  
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564  
DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(ChannelEvent) line: 792  
NettyTransportCodec$NettyFrameDecoder(SimpleChannelUpstreamHandler).channelBound(ChannelHandlerContext, ChannelStateEvent) line: 166  
NettyTransportCodec$NettyFrameDecoder(SimpleChannelUpstreamHandler).handleUpstream(ChannelHandlerContext, ChannelEvent) line: 98  
DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline$DefaultChannelHandlerContext, ChannelEvent) line: 564  
DefaultChannelPipeline.sendUpstream(ChannelEvent) line: 559  
Channels.fireChannelBound(Channel, SocketAddress) line: 199  
NioWorker$RegisterTask.run() line: 191  
NioWorker(AbstractNioWorker).processRegisterTaskQueue() line: 329  
NioWorker(AbstractNioWorker).run() line: 235  
NioWorker.run() line: 38  
DeadLockProofWorker$1.run() line: 42  
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1145  
ThreadPoolExecutor$Worker.run() line: 615  
Thread.run() line: 744

这是Java程序

import java.io.IOException;
import java.sql.SQLException;
import org.apache.log4j.Logger;
public class log4jExample {
    static Logger log = Logger.getRootLogger();
    public static void main(String[] args) throws IOException, SQLException {
       log.debug("Hello this is an debug message");
    }
}

这是 log4j.properties

# Define the root logger with appender file
log = /home/vm4learning/WorkSpace/BigData/Log4J-Example/log
log4j.rootLogger = DEBUG, FILE, flume

# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n

# Define the flume appender
log4j.appender.flume = org.apache.flume.clients.log4jappender.Log4jAppender
log4j.appender.flume.Hostname = localhost
log4j.appender.flume.Port = 41414
log4j.appender.flume.UnsafeMode = false
log4j.appender.flume.layout=org.apache.log4j.PatternLayout
log4j.appender.flume.layout.ConversionPattern=%m%n

这是Eclipse中的依赖项

flume-ng-log4jappender-1.4.0.jar
log4j-1.2.17.jar
flume-ng-sdk-1.4.0.jar
avro-1.7.3.jar
netty-3.4.0.Final.jar
avro-ipc-1.7.3.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar

这是flume.conf的内容

# Tell agent1 which ones we want to activate.
agent1.channels = ch1
agent1.sources = avro-source1
agent1.sinks = hdfs-sink1

# Define a memory channel called ch1 on agent1
agent1.channels.ch1.type = memory

# Define an Avro source called avro-source1 on agent1 and tell it
# to bind to 0.0.0.0:41414. Connect it to channel ch1.
agent1.sources.avro-source1.type = avro
agent1.sources.avro-source1.bind = 0.0.0.0
agent1.sources.avro-source1.port = 41414

# Define a logger sink that simply logs all events it receives
# and connect it to the other end of the same channel.
agent1.sinks.hdfs-sink1.type = hdfs
agent1.sinks.hdfs-sink1.hdfs.path = hdfs://localhost:9000/flume/events/

agent1.sinks.hdfs-sink1.channel = ch1
agent1.sources.avro-source1.channels = ch1

如何解决这个问题?

4

3 回答 3

1

我的猜测是您正试图通过 Flume 记录 Flume 的事件。我已经在其他附加程序中看到了这个问题,但在 Log4j1 中没有。

我会考虑修改 log4j.properties 以排除 Flume、Netty 和 Avro 事件,看看是否可以修复它。

于 2013-10-24T04:35:33.577 回答
1

我有一个类似的问题,解决方案是:

  • 将 log4j.properties 根记录器从调试更改为信息级别。

但我不知道flume-ng内部发生了什么。我正在尝试调试它。有知道的告诉我一下thx~~

于 2013-12-17T11:03:43.447 回答
1

我曾经在 log4j 中使用 Flume appender 时遇到过类似的问题。每当我尝试实例化 Logger 对象时,程序就会挂起。我记得问题是我在类路径中没有所有必需的库,一旦添加它们,它就可以正常工作。

我建议您首先让Mike Percy 的简单示例开始工作。尽管那里的 pom.xml 创建了一个包含所有依赖项的单个 JAR,但编辑它以将依赖的 jar 文件复制到另一个目录会给我这个列表:

avro-1.7.4.jar
avro-ipc-1.7.4.jar
commons-codec-1.3.jar
commons-collections-3.2.1.jar
commons-compress-1.4.1.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
flume-ng-log4jappender-1.4.0-cdh4.5.0.jar
flume-ng-sdk-1.4.0-cdh4.5.0.jar
hamcrest-core-1.1.jar
httpclient-4.0.1.jar
httpcore-4.0.1.jar
jackson-core-asl-1.8.8.jar
jackson-mapper-asl-1.8.8.jar
jetty-6.1.26.jar
jetty-util-6.1.26.jar
junit-4.10.jar
libthrift-0.7.0.jar
log4j-1.2.16.jar
netty-3.5.0.Final.jar
paranamer-2.3.jar
slf4j-api-1.7.2.jar
slf4j-jdk14-1.7.2.jar
snappy-java-1.0.4.1.jar
velocity-1.7.jar
xz-1.0.jar

其中一些库(如 junit)可能并不是真正需要的,但我建议首先使用所有这些库,看看您是否可以让您的示例正常工作,然后尝试确定所需的最小集。

于 2013-12-09T16:16:31.260 回答