ElasticSearch集群日志限制问题

本文是基于CentOS7的环境下使用rpm包安装进行说明。ELK的默认日志记录会增长很多,除ElasticSearch外,都会无限增长,长时间运行可能带来灾难性的后果(如:节点宕机)。这就是我们今天要面对的主要问题。主要策略为限制日志总量:时间+size,每天rotate一个日志文件或者每当日志文件大小超过256M,rotate一个新的日志文件,并且最多保留7天之内的日志文件。

ElasticSearch

默认配置问题

ElasticSearch默认情况下会每天rolling一个文件,当到达2G的时候,才开始清除超出的部分,当一个文件只有几十K的时候,文件会一直累计下来。

解决方案

通过修改log4j2.properties文件来解决。该文件在/etc/elasticsesarch目录下,默认配置有如下设置

...
appender.rolling.strategy.action.condition.nested_condition.type = IfAccumulatedFileSize
appender.rolling.strategy.action.condition.nested_condition.exceeds = 2GB 
...

该配置,会保存2GB的日志,只有累计的日志大小超过2GB的时候,才会删除旧的日志文件。建议更改为

...
appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified
appender.rolling.strategy.action.condition.nested_condition.age = 7D 
...

仅保留最近7天的日志。

Logstash

默认配置问题

Logstash会一直增长gc文件和不停增多的rolling日志文件,并且不会删除。

解决方案

通过修改log4j2.properties文件(/etc/logstash目录下),增加配置:

...
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.action.type = Delete
appender.rolling.strategy.action.basepath = ${sys:ls.logs}
appender.rolling.strategy.action.condition.type = IfFileName
appender.rolling.strategy.action.condition.glob = ${sys:ls.logs}/logstash-${sys:ls.log.format}
appender.rolling.strategy.action.condition.nested_condition.type = IfLastModified
appender.rolling.strategy.action.condition.nested_condition.age = 7D 
...

Kibana

默认配置问题

日志输出到kibana.out文件当中,这个文件会变得越来越大。

解决方案

在kibana的配置文件中,只有以下几个选项:

logging.dest:
Default: stdout Enables you specify a file where Kibana stores log output.

logging.quiet:
Default: false Set the value of this setting to true to suppress all logging output other than error messages.

logging.silent:
Default: false Set the value of this setting to true to suppress all logging output.

logging.verbose:
Default: false Set the value of this setting to true to log all events, including system usage information and all requests. Supported on Elastic Cloud Enterprise.

logging.timezone
Default: UTC Set to the canonical timezone id (e.g. US/Pacific) to log events using that timezone. A list of timezones can be referenced at https://en.wikipedia.org/wiki/List_of_tz_database_time_zones.

我们可以指定输出的日志文件与日志内容,但是却不可以配置日志的rotate。这时,我们需要使用logrotate,这个linux默认安装的工具。
首先,我们要在配置文件里面指定生成pid文件:

pid.file: "pid.log"

然后,修改/etc/logrotate.conf:

/var/log/kibana {
    missingok
    notifempty
    shareds
    daily
    rotate 7
    copytruncate
    /bin/kill -HUP $(cat /usr/share/kibana/pid.log 2>/dev/null) 2>/dev/null
    end
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值