【问题标题】:Manual rotate cassandra system.log手动旋转 cassandra system.log
【发布时间】:2017-08-30 23:50:26
【问题描述】:

有没有办法在 cassandra system.log 中强制手动轮换? 我需要在每天 0:00(在 cron 中)创建一个新的 system.log。

最初我尝试了一个基本的 mv,但如果 cassandra 不重新启动服务,它就会停止写入日志文件

LOG_NAME="system.log.`date +"%Y%m%d_%H%M"`"
LOG_PATH="/var/log/cassandra"
mv ${LOG_PATH}/system.log ${LOG_PATH}/${LOG_NAME}  &&  '' > ${LOG_PATH}/system.log && chown cassandra:cassandra ${LOG_PATH}/system.log

【问题讨论】:

    标签: cassandra


    【解决方案1】:

    找到了!

    apt-get install -y logrotate
    

    编辑文件:/etc/cron.daily/logrotate

    添加行:

    /usr/sbin/logrotate -f /etc/cassandra/logrotate.conf
    

    创建文件:/etc/cassandra/logrotate.conf 并添加:

    /var/log/cassandra/system.log {
    rotate 365
    copytruncate
    compress
    }
    

    手动执行:

    /usr/sbin/logrotate -f /etc/cassandra/logrotate.conf
    

    此外,我可以在 logback.xml 中增加 cassandra system.log 的大小,只是为了不通过更改行每天进行多次轮换:

    <MaxFileSize> 100MB </ maxFileSize>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-17
      • 1970-01-01
      • 2018-10-27
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-01
      相关资源
      最近更新 更多