我想在Cloudera集群中的audit-hdfs日志中添加一个Kafka附加器。
我已经使用Kafka附加程序成功配置了log4j2.xml文件,我需要将该log4j2.xml转换为log4j2.properties文件,以便能够将其与HDFS日志log4j2.properties文件合并。我无法执行此操作,因为当我使用log4j2.properties而不是XML启动虚拟进程时,出现错误。
我尝试用几种不同的方式编写属性文件,总是导致bootstrap.servers属性出现问题
这是我的属性文件
filters = threshold
filter.threshold.type = ThresholdFilter
filter.threshold.level = ALL
appenders = console,kafka
appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %m%n
appender.kafka.type = Kafka
appender.kafka.name = kafka
appender.kafka.layout.type = PatternLayout
appender.kafka.layout.pattern =%m%n
appender.kafka.property.type = Property
appender.kafka.property.bootstrap.servers = ip:port
appender.kafka.topic = cdh-audit-hdfs
这里是问题所在: appender.kafka.property.bootstrap.servers = ip:port
我尝试了以下操作,但无济于事:
appender.kafka.property.bootstrap.servers = ip:port
appender.kafka.property.bootstrap\.servers = ip:port
appender.kafka.property.name = "bootstrap.servers"
appender.kafka.property.bootstrap.servers = ip:port
appender.kafka.property.key = "bootstrap.servers"
appender.kafka.property.value = ip:port
等...
这是我的虚拟流程:
package com.pragsis.audit.logs.cloudera.appenderCompanions
import org.apache.logging.log4j.LogManager
object dummy extends App{
val logger = LogManager.getLogger
val record = "2019-05-22 10:22:02,744 INFO FSNamesystem.audit: allowed=true ugi=enrique.castilla@PRAGSIS.LOCAL (auth:KERBEROS) ip=/172.22.1.161 cmd=listStatus src=/ dst=null perm=null proto=rpc"
while(true){
logger.info(record)
Thread.sleep(5000)
}
}
我如何配置我的log4j2.properties才能定义此属性?
我希望此过程将记录写到我的Kafka主题中,但是却出现如下错误:
Exception in thread "main" org.apache.logging.log4j.core.config.ConfigurationException: No type attribute provided for component bootstrap
Exception in thread "main" org.apache.kafka.common.config.ConfigException: Missing required configuration "bootstrap.servers" which has no default value.
答案 0 :(得分:1)
尝试此解决方案,它对我有用:
appender.kafka.property.type=Property
appender.kafka.property.name=bootstrap.servers
appender.kafka.property.value=host:port