[英]How to handle ECS container agent docker container logs?
I am using aws batch with ECS. 我正在将AWS Batch与ECS一起使用。
ECS tasks can be configured in task definition to use awslogs logDriver and send the logs to cloudwatch, which prevent them taking up space in EC2 instance. 可以在任务定义中将ECS任务配置为使用awslogs logDriver并将日志发送到cloudwatch,这可以防止它们占用EC2实例中的空间。 But the ECS container agent itself also lives in a docker container and all the docker container logs for it are store in EC2 instance, which fill up the memory very quickly.
但是ECS容器代理本身也存在于docker容器中,并且其所有docker容器日志都存储在EC2实例中,这会很快填满内存。 Is there anyway to set up logDriver for ECS container agent itself?
无论如何,是否需要为ECS容器代理本身设置logDriver?
Also ECS agent stores logs in /var/log/ecs/ecs-agent.log.timestamp, which also take up a lot of space. 此外,ECS代理会将日志存储在/var/log/ecs/ecs-agent.log.timestamp中,这也会占用大量空间。 Any idea how to redirect them to cloudwatch?
任何想法如何将它们重定向到cloudwatch?
You can have small script in UserData
(as part of LaunchConfiguration) to install awslogs
and configure for the same. 您可以在
UserData
有小脚本(作为LaunchConfiguration的一部分)来安装awslogs
并对其进行配置。 Please find below the sample snippet. 请在下面的示例代码段中找到。
# Install awslogs and the jq JSON parser
yum install -y awslogs jq
# Inject the CloudWatch Logs configuration file contents
cat > /etc/awslogs/awslogs.conf <<- ''EOF''
[general]
state_file = /var/lib/awslogs/agent-state
[/var/log/dmesg]
file = /var/log/dmesg
log_group_name = ${EnvName}-${EnvNumber}#ecs#dmesg
log_stream_name = {cluster}/{container_instance_id}
[/var/log/messages]
file = /var/log/messages
log_group_name = ${EnvName}-${EnvNumber}#ecs#messages
log_stream_name = {cluster}/{container_instance_id}
datetime_format = %b %d %H:%M:%S
[/var/log/docker]
file = /var/log/docker
log_group_name = ${EnvName}-${EnvNumber}#ecs#docker
log_stream_name = {cluster}/{container_instance_id}
datetime_format = %Y-%m-%dT%H:%M:%S.%f
[/var/log/ecs/ecs-init.log]
file = /var/log/ecs/ecs-init.log.*
log_group_name = ${EnvName}-${EnvNumber}#ecs#ecs-init.log
log_stream_name = {cluster}/{container_instance_id}
datetime_format = %Y-%m-%dT%H:%M:%SZ
[/var/log/ecs/ecs-agent.log]
file = /var/log/ecs/ecs-agent.log.*
log_group_name = ${EnvName}-${EnvNumber}#ecs#ecs-agent.log
log_stream_name = {cluster}/{container_instance_id}
datetime_format = %Y-%m-%dT%H:%M:%SZ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.