如何保存ECS容器的日志?

时间:2019-11-27 03:16:59

标签: docker amazon-ecs

我正在运行ECS任务,最近服务cpu命中率100%下降了。

我等待实例安定下来并埋入。 我一直在寻找日志,但是似乎docker容器重新启动并且日志都消失了(CPU较高时的日志)

下次,如何确保至少可以查看日志以诊断问题?

我有以下内容,希望在某些地方(安装在主机中)看到一些日志

     "mountPoints": [
            {
                "readOnly": null,
                "containerPath": "/var/log/uwsgi",
                "sourceVolume": "logs"
            }
        ],

但是主机中没有/var/log/uwsgi。 我可能需要syslog和其他东西。

1 个答案:

答案 0 :(得分:2)

到目前为止,您当前的配置logs完全取决于您在“卷”部分中定义的路径。

     "mountPoints": [
            {
                "readOnly": null,
                "containerPath": "/var/log/uwsgi",
                "sourceVolume": "logs"
            }
        ],

在卷日志logs中定义的源路径,而不是/var/log/uwsgi,因此您正在安装

/var/log/uwsgi(容器路径)-> logs卷(主机路径)。您可以在logs卷中的路径定义中找到这些日志。但最好设置

            {
                "readOnly": null,
                "containerPath": "/var/log/uwsgi",
                "sourceVolume": "volume_name"
            }

然后配置音量

"volumes": [
    {
      "name": "logs",
      "host": {
        "sourcePath": "/home/ec2-user/logs"
      }
    }
]

来自文档

  

在“任务定义卷”部分中,使用名称定义绑定安装   和sourcePath值。

  "volumes": [
    {
      "name": "webdata",
      "host": {
        "sourcePath": "/ecs/webdata"
      }
    }
  ]
  

在containerDefinitions部分中,使用   mountPoints引用已定义绑定安装名称的值   和containerPath值来将绑定安装在   容器。

  "containerDefinitions": [
    {
      "name": "web",
      "image": "nginx",
      "cpu": 99,
      "memory": 100,
      "portMappings": [
        {
          "containerPort": 80,
          "hostPort": 80
        }
      ],
      "essential": true,
      "mountPoints": [
        {
          "sourceVolume": "webdata",
          "containerPath": "/usr/share/nginx/html"
        }
      ]
    }
  ]

bind-mounts-ECS

现在,如果我提出建议,我将使用AWS日志驱动程序。

在AWS中工作,最好的方法是将所有日志推送到CW,但是AWS日志驱动程序仅将容器stdout和stderr日志推送到CW。

使用AWS日志驱动程序,您无需担心实例和容器,您将登录CW,还可以流式传输这些logs to ELK

          "logConfiguration": {
                "logDriver": "awslogs",
                "options": {
                    "awslogs-group": "awslogs-wordpress",
                    "awslogs-region": "us-west-2",
                    "awslogs-stream-prefix": "awslogs-example"
                }
            }

enter image description here

using_awslogs

相关问题