我一直在尝试使用logrotate实用程序并将压缩日志移动到s3,但是,只有在强行完成时它才会旋转

问题描述 投票:0回答:1

我已将其配置为每小时运行一次,它每小时轮换一次但不将其发送到s3,这可能是什么原因?

/ var / log / newlog {

rotate 5
hourly
missingok
notifempty
compress
dateext
    dateformat -%Y-%m-%d-%H%M%S
postrotate
    /usr/lib/newlog/new
endscript

/ usr / lib / newlog / new是一个脚本,使用s3cmd将.gz文件同步到s3

amazon-s3 logrotate s3cmd
1个回答
0
投票

从上面的代码可以看出,没有提到应该压缩日志文件的S3存储桶。您的脚本应添加以下行:


/ var / log / newlog {

   postrotate
    /usr/lib/newlog/new > /dev/null 2>&1 || true

    BUCKET=logging-bucket
    INSTANCE_ID=`curl --silent http://169.254.169.254/latest/meta-data/instance-id | sed -e "s/i-//"`
    /usr/bin/s3cmd -m text/plain sync /var/log/messages-* s3://${BUCKET}/${INSTANCE_ID}/var/log/

endscript

}


其中logging-bucket是将存储压缩文件的存储桶的名称。还要确保用户具有S3的权限。

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.