gpt4 book ai didi

amazon-web-services - 如何将我自己的日志添加到 Amazon Elastic Beanstalk 上的日志轮换/S3 备份?

转载 作者:行者123 更新时间:2023-12-04 08:06:24 24 4
gpt4 key购买 nike

我们有一个位于 Amazon Elastic Beanstalk 上的 PHP 应用程序。该应用程序已启用日志轮换和备份到 S3。 Apache 访问和错误日​​志每小时都会正确轮换和备份。

但是,应用程序也会创建自己的日志文件。我想用它做同样的事情——它应该每小时轮换一次并备份到 S3。按照说明操作 here我创建了以下文件:

.ebextensions/publish-logs.config

files: 
"/opt/elasticbeanstalk/tasks/publishlogs.d/cloud-init.conf" :
mode: "000755"
owner: root
group: root
content: |
/var/app/current/log/*.log

然后我将新版本上传到亚马逊。

结果 - 我看到日志文件在第一次轮换时备份到 S3 ONCE。它没有被压缩,只是复制。在那之后,什么都没有。没有新的 S3 备份。没有轮换。下载捆绑日志时,该文件就在那里,现在大约有 80MB(在几天内累积)。

亚马逊的文档非常稀少。但它确实说:

When you configure your application's log files for log rotation, the application doesn't need to create copies of log files. Elastic Beanstalk configures logrotate to make a copy of your application's log files for each rotation.



我做错了什么?

最佳答案

为此,您需要配置 logrotate,这有点棘手。因为在很大程度上取决于您使用的实例。但让我试试。加这两个files到您的配置。首先为 logrotate 创建配置,然后配置 cron 以使用该配置运行 logrotate。

files:
"/etc/logrotate.d/logrotate.elasticbeanstalk.php.conf":
mode: "000655"
owner: root
group: root
content: |
/var/app/current/log/*.log {
rotate 14
size 100M
daily
compress
delaycompress
}
"/etc/cron.daily/cron.logrotate.elasticbeanstalk.php.conf":
mode: "000655"
owner: root
group: root
content: |
#!/bin/sh
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.d/logrotate.elasticbeanstalk.php.conf
/sbin/service awslogs restart

试一试。如果失败 - 请提供您正在使用的 AMI ID

关于amazon-web-services - 如何将我自己的日志添加到 Amazon Elastic Beanstalk 上的日志轮换/S3 备份?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47454520/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com