是否有任何方法可以在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
找到!
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>