我正在运行 ECS 任务,最近服务 cpu 达到 100% 然后宕机。
我等待实例稳定下来并进入。 我正在寻找日志,但似乎 docker 容器重新启动并且日志都消失了(cpu 高时的日志)
下次,我如何确保至少可以看到日志来诊断问题?
我有以下内容,希望能在某处看到一些日志(安装在主机中)
"mountPoints": [
{
"readOnly": null,
"containerPath": "/var/log/uwsgi",
"sourceVolume": "logs"
}
],
但是主机中没有/var/log/uwsgi
。
我可能需要 syslog
和东西..
最佳答案
就您当前的配置而言,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"
}
}
]
来自文档
In the task definition volumes section, define a bind mount with name and sourcePath values.
"volumes": [
{
"name": "webdata",
"host": {
"sourcePath": "/ecs/webdata"
}
}
]
In the containerDefinitions section, define a container with mountPoints values that reference the name of the defined bind mount and the containerPath value to mount the bind mount at on the container.
"containerDefinitions": [
{
"name": "web",
"image": "nginx",
"cpu": 99,
"memory": 100,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80
}
],
"essential": true,
"mountPoints": [
{
"sourceVolume": "webdata",
"containerPath": "/usr/share/nginx/html"
}
]
}
]
现在,如果我接受我的建议,我会选择 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"
}
}
关于docker - ECS容器如何保存日志?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59062484/