我正在将AWS Batch与ECS一起使用。
可以在任务定义中配置ECS任务以使用awslogs logDriver并将日志发送到cloudwatch,这可以防止它们占用EC2实例中的空间。但是ECS容器代理本身也存在于docker容器中,并且其所有docker容器日志都存储在EC2实例中,这会很快填满内存。无论如何,是否可以为ECS容器代理本身设置logDriver?
ECS代理还将日志存储在/var/log/ecs/ecs-agent.log.timestamp中,这也占用大量空间。知道如何将它们重定向到cloudwatch吗?
答案 0 :(得分:0)
您可以在UserData
中使用小脚本(作为LaunchConfiguration的一部分)来安装awslogs
并对其进行配置。请在下面的示例代码段中找到。
# 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