Elastic BeanStalk EC2实例的日志用完了整个磁盘空间 [英] Elastic BeanStalk EC2 instance's log uses up whole disk space

查看:77
本文介绍了Elastic BeanStalk EC2实例的日志用完了整个磁盘空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Elastic BeanStalk环境,在其中我的应用程序在1个EC2实例上运行.最初配置环境时,我已经添加了负载均衡器,但是从那时起,我仅使用1个实例进行设置.

I have an Elastic BeanStalk environment where I run my application on 1 EC2 instance. I've added load balancer, when I configured the environment initially, but since then I set it only use 1 instance.

在容器中运行的应用程序显然会产生大量日志-几天后,它们耗尽了整个磁盘空间,然后应用程序崩溃.健康检查下降到严重程度.

Application run within container apparently produces quite a lot of logs - after several days they use up whole disk space and then application crash. Health check drops to severe.

我看到手动终止实例会有所帮助-环境会删除旧实例并创建一个可以正常工作的新实例(直到它再次填满整个磁盘为止).

I see that terminating instance manually helps - environment removes old instance and creates a new one that works (until it fills up the whole disk again).

我有什么选择?定期清理日志的脚本?一些日志轮换?磁盘快满时触发重新启动实例吗?

What are my options? A script that regularly cleans up logs? Some log rotation? Trigger that reboots instance when disk is nearly full?

我自己不写任何文件-我的应用程序仅登录到std和std err,因此对文件的写入由EC2/EBS包装器完成. (我将应用程序部署为ZIP格式,其中包含JAR,bash脚本和Procfile(如果相关).

I do not write anything to file myself - my application only log to std out and std err, so writing to file is done by EC2/EBS wrapper. (I deploy the application as a ZIP containing a JAR, a bash script and Procfile if that is relevant).

推荐答案

Logrotation是前进的方向.您可以在"/etc/logrotate.d/"中创建配置文件,并在其中声明您的选项,以避免使用大型日志文件.

Logrotation is the way forward. You can create a configuration file in `/etc/logrotate.d/' where you state your options in order to avoid having large log files.

您可以在此处阅读有关配置的更多信息 https://linuxconfig.org/setting-up-logrotate-on-redhat-linux

You can read more about the configurations here https://linuxconfig.org/setting-up-logrotate-on-redhat-linux

示例配置文件如下所示:

A sample configuration file would look something like this:

/var/log/your-large-log.log {
    missingok
    notifempty
    compress
    size 20k
    daily
    create 0600 root root
}

您还可以通过运行以下命令从cli中测试新的配置文件:

You can also test the new configuration file from the cli by running the follow:

logrotate -d [your_config_file]

这将测试日志轮转是否成功,而仅在调试模式下进行,因此日志文件实际上不会轮转.

This will test if the log rotation will be successful or not but only in debugging mode, therefore the log file will not be actually rotated.

这篇关于Elastic BeanStalk EC2实例的日志用完了整个磁盘空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆