简体   繁体   English

如何处理ECS容器代理docker容器日志?

[英]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.

相关问题 ECS 优化实例中没有 ECS 代理 docker 容器 - No ECS agent docker container in ECS optimised instance 如何在Debian中安装Amazon ECS容器代理? (ECS-INIT) - How install the Amazon ECS Container Agent in Debian? (ecs-init) 如何在ECS上自动启动我的docker容器? - How to launch my docker container automatically on ECS? 如何将ECS Docker Container ID放入Container内部的环境变量中 - How to put ECS Docker Container ID into a Environmental Variable inside the Container 如何在Fargate启动类型实例上更新AWS ECS容器代理 - how to update AWS ECS Container Agent on Fargate launch type instances 如何在扩展ECS实例时自动运行consul代理和registrator容器 - How to automatically run consul agent and registrator container on scaling ECS instance 如何从一个 ECS 容器访问客户端内容到另一个托管 docker 应用程序的 ECS 容器 - How to access client side content from one ECS container to another ECS container where the docker application is hosted AWS ECS 容器日志设计模式 - AWS ECS container logs design pattern 使用 AWS ECS 时如何轻松访问 docker 容器? - How to easily access docker container when using AWS ECS? 如何向 ECS 上运行的 docker 容器添加文件夹和文件? - How can I add folders and files to a docker container running on ECS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM