Elastic Beanstalk单容器Docker-使用awslogs日志记录驱动程序 [英] Elastic Beanstalk Single Container Docker - use awslogs logging driver

查看:151
本文介绍了Elastic Beanstalk单容器Docker-使用awslogs日志记录驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用单容器Docker配置,并尝试使用 awslogs将应用程序标准输出发送到CloudWatch日志记录驱动程序.

I'm running a single Docker container on Elastic Beanstalk using its Single Container Docker Configuration, and trying to send the application stdout to CloudWatch using the awslogs logging driver.

EB寻找用于容器配置的Dockerrun.aws.json文件,但据我所知,没有选择将awslogs用作容器的日志记录驱动程序(或将其他任何标志添加到docker run来解决此问题).

EB looks for a Dockerrun.aws.json file for the configuration of the container, but as far as I can see doesn't have an option to use awslogs as the container's logging driver (or add any other flags to the docker run command for that matter).

我尝试使用提供的答案侵入docker run命令

I've tried hacking into the docker run command using the answer provided here, by adding a file .ebextensions/01-commands.config with content:

commands:
  add_awslogs:
    command: 'sudo sed -i "s/docker run -d/docker run --log-driver=awslogs --log-opt awslogs-region=eu-west-2 --log-opt awslogs-group=dockerContainerLogs -d/" /opt/elasticbeanstalk/hooks/appdeploy/enact/00run.sh'

在修改运行脚本和在CloudWatch中显示日志的意义上,此方法有效.

This works, in the sense that it modifies the run script, and logs show up in CloudWatch.

但是EB申请死了.容器已启动,但未响应请求.

But the EB application dies. The container is up, but does not respond to requests.

我在容器日志中发现以下错误:

I find the following error in the container logs:

"logs"命令仅支持"json-file"和"journald"日志记录 驱动程序(获取:awslogs)

"logs" command is supported only for "json-file" and "journald" logging drivers (got: awslogs)

我找到了与ECS(而非EB)相关的类似问题的答案,建议在ECS_AVAILABLE_LOGGING_DRIVERS后面附加awslogs.但是我在EB中找不到此配置设置.

I find answers to similar questions relating to ECS (not EB) suggesting to append ECS_AVAILABLE_LOGGING_DRIVERS with awslogs. But I don't find this configuration setting in EB.

有什么想法吗?

推荐答案

我在这里发布从AWS支持部门收到的答案:

I'm posting here the answer I received from AWS support:

由于Elastic Beanstalk单个容器环境将保存标准输出 和stderr在/var/log/eb-docker/containers/eb-current-app/上 默认,并且作为新的解决方案堆栈,您可以选择流式传输 登录到cloudwatch,自动执行AWSLogs代理的配置 在实例上,我建议做的是在 将stdout和stderr日志文件添加到cloudwatch配置 并使用已配置的代理将这些文件流式传输到 cloudwatch日志.而不是触摸预先挂钩,这也不是 受AWS支持,因为挂钩可能从解决方案堆栈版本更改为 另一个.

As Elastic Beanstalk Single Container environment will save the stdout and stderr on /var/log/eb-docker/containers/eb-current-app/ by default, and as the new solution stack allows you the option to stream log to cloudwatch, automating the configuration of the AWSLogs agent on the instances, what I recommend to do is to add an ebextension to add the stdout and stderr logs files to the cloudwatch configuration and use the already configured agent to stream those files to cloudwatch logs. instead of touching the pre-hooks , which is nor supported by AWS as hooks may change from solution stack version to another.

关于错误,您仅看到"logs"命令 对于"json文件"和"journald"日志记录驱动程序(获取:awslogs) 错误是由于docker的工作方式(配置为将日志发送到docker时) 除了json-file或已记录日记的其他驱动程序,它将无法 在本地显示日志,因为它没有本地副本.

Regarding the error you are seeing "logs" command is supported only for "json-file" and "journald" logging drivers (got: awslogs)" this error is from how docker works, when it is configured to send logs to other driver beside json-file or journald it will not be able to display logs locally as it does not have a local copy of them.

### BEGIN .ebextensions/logs.config
option_settings:
  - namespace: aws:elasticbeanstalk:cloudwatch:logs
    option_name: StreamLogs
    value: true
  - namespace: aws:elasticbeanstalk:cloudwatch:logs
    option_name: DeleteOnTerminate
    value: false
  - namespace: aws:elasticbeanstalk:cloudwatch:logs
    option_name: RetentionInDays
    value: 7

files:
  "/etc/awslogs/config/stdout.conf":
    mode: "000755"
    owner: root
    group: root
    content: |
      [docker-stdout]
      log_group_name=/aws/elasticbeanstalk/environment_name/docker-stdout
      log_stream_name={instance_id}
      file=/var/log/eb-docker/containers/eb-current-app/*-stdouterr.log

commands:
  "00_restart_awslogs":
    command: service awslogs restart

### END .ebextensions/logs.config

这篇关于Elastic Beanstalk单容器Docker-使用awslogs日志记录驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆