首页 文章

对log4j2.properties文件的更改导致elasticsearch失败

提问于
浏览
1

我已经安装了elasticsearch(6.6.0)和CentOS 7.我想为旋转日志添加更多属性,比如大小是50MB旋转和压缩 . 但是,如果我将更多配置添加到/etc/elasticsearch/log4j2.properties文件并重新启动elasticsearch服务器,则会失败 .

My current log4j2.properties file:

status = error

# log action execution errors for easier debugging
logger.action.name = org.elasticsearch.action
logger.action.level = debug

appender.console.type = Console
appender.console.name = console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n

appender.rolling.type = RollingFile
appender.rolling.name = rolling
appender.rolling.fileName = 
${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] 
%marker%.-10000m%n
appender.rolling.filePattern = 
${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-
%d{yyyy-MM-dd}-%i.log.gz    
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true

rootLogger.level = info
rootLogger.appenderRef.console.ref = console
rootLogger.appenderRef.rolling.ref = rolling

当我尝试添加时,就像在弹性搜索文档中给出的那样,这是如何添加配置,

appender.rolling.policies.size.size = 2MB
appender.rolling.strategy.action.condition.age = 3D
appender.rolling.strategy.action.type = Delete
appender.rolling.strategy.action.condition.type = IfFileName

失败的是 error

Exception in thread "main" org.apache.logging.log4j.core.config.ConfigurationException: No type attribute provided for component size
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createComponent(PropertiesConfigurationBuilder.java:333)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.processRemainingProperties(PropertiesConfigurationBuilder.java:347)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createComponent(PropertiesConfigurationBuilder.java:336)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.processRemainingProperties(PropertiesConfigurationBuilder.java:347)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createAppender(PropertiesConfigurationBuilder.java:224)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.build(PropertiesConfigurationBuilder.java:157)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:56)
    at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:35)
    at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:244)
    at org.elasticsearch.common.logging.LogConfigurator$1.visitFile(LogConfigurator.java:105)
    at org.elasticsearch.common.logging.LogConfigurator$1.visitFile(LogConfigurator.java:101)
    at java.nio.file.Files.walkFileTree(Files.java:2670)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:101)
    at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:84)
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:316)
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123)
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114)
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67)
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122)
    at org.elasticsearch.cli.Command.main(Command.java:88)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91)
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84)

我在/var/log/elasticsearch/elasticsearch_deprecation.log中有 warning

[2018-02-20T02:09:32,694][WARN ][o.e.d.e.NodeEnvironment  ] ES has detected the [path.data] folder using the cluster name as a folder [/data/es], Elasticsearch 6.0 will not allow the cluster name as a folder within the data path

任何人都可以解释如何将配置添加到log4j2.properties文件?

1 回答

  • 0

    由于日志表明您缺少大小配置的 type 属性 . 您还缺少 RolloverStrategytype 属性 .

    尝试以下配置 -

    appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
    appender.rolling.policies.size.size = 2 MB
    
    appender.rolling.strategy.type = DefaultRolloverStrategy
    appender.rolling.strategy.action.type = Delete
    appender.rolling.strategy.action.basePath = ${sys:es.logs.base_path}${sys:file.separator}
    appender.rolling.strategy.action.maxDepth = 1
    appender.rolling.strategy.action.ifLastModified.type = IfLastModified
    appender.rolling.strategy.action.ifLastModified.age = 3d
    

相关问题