如何在Elastic Beanstalk Multicontainer docker上使用流畅的日志驱动程序

时间:2016-03-04 06:07:16

标签: amazon-web-services docker elastic-beanstalk

我尝试使用以下Dockerrun.aws.json,

的流畅日志驱动程序
    {
      "AWSEBDockerrunVersion": 2,
      "containerDefinitions": [
        {
          "name": "apache",
          "image": "php:5.6-apache",
          "essential": true,
          "memory": 128,
          "portMappings": [
            {
              "hostPort": 80,
              "containerPort": 80
            }
          ],
          "logConfiguration": {
            "logDriver": "fluentd",
            "options": {
              "fluentd-address": "127.0.0.1:24224"
            }
          }
        }
      ]
    }

但发生了以下错误。

ERROR: Encountered error starting new ECS task: {cancel the command.
    "failures": [
        {
            "reason": "ATTRIBUTE",
            "arn": "arn:aws:ecs:ap-northeast-1:000000000000:container-instance/00000000-0000-0000-0000-000000000000"
        }
    ],
    "tasks": []
}
ERROR: Failed to start ECS task after retrying 2 times.
ERROR: [Instance: i-00000000] Command failed on instance. Return code: 1 Output: beanstalk/hooks/appdeploy/enact/03start-task.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.

我可以配置什么?

3 个答案:

答案 0 :(得分:5)

似乎您也可以使用以下内容在应用程序环境目录中使用.ebextensions/01-fluentd.config文件来完成它:

files:
  "/home/ec2-user/setup-available-log-dirvers.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/sh
      set -e
      if ! grep fluentd /etc/ecs/ecs.config &> /dev/null
      then
        echo 'ECS_AVAILABLE_LOGGING_DRIVERS=["json-file","syslog","fluentd"]' >> /etc/ecs/ecs.config
      fi

container_commands:
  01-configure-fluentd:
    command: /home/ec2-user/setup-available-log-dirvers.sh

现在你必须部署一个新的应用程序版本(还没有流畅的配置),重建你的环境,添加流畅的配置:

  logConfiguration:
    logDriver: fluentd
    options:
      fluentd-address: localhost:24224
      fluentd-tag: docker.myapp

现在部署更新的应用程序,现在一切都应该正常工作。

答案 1 :(得分:1)

我自己解决了这个问题。

首先,我准备一个具有以下用户数据的自定义ami。

#cloud-config
repo_releasever: 2015.09
repo_upgrade: none
runcmd:
  - echo 'ECS_AVAILABLE_LOGGING_DRIVERS=["json-file","syslog","fluentd"]' >> /etc/ecs/ecs.config

其次,我定义了在我的环境EC2设置中创建自定义ami的ami id。最后,我将我的应用程序部署到Elastic Beanstalk。在此之后,我环境中流畅的日志驱动程序正常工作。

为了在Elastic Beanstalk Multicontainer Docker中使用流畅的日志驱动程序,它需要在ECS_AVAILABLE_LOGGING_DRIVERS中定义/etc/ecs/ecs.config变量。 Elastic Beanstalk Multicontainer Docker正在内部使用ECS,因此相关设置在ECS文档中。 请阅读以下文档中的logConfiguration部分: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_definition_parameters.html

答案 2 :(得分:1)

我已经在已接受的答案中添加了评论,只是添加了我用来使其适用的完整ebextension文件

files:
"/home/ec2-user/setup-available-log-dirvers.sh":
mode: "000755"
owner: root
group: root
content: |
  #!/bin/sh
  set -e
  if ! grep fluentd /etc/ecs/ecs.config &> /dev/null
  then
    echo 'ECS_AVAILABLE_LOGGING_DRIVERS=["json-file","syslog","fluentd"]' >> /etc/ecs/ecs.config
  fi

container_commands:
 00-configure-fluentd:
  command: /home/ec2-user/setup-available-log-dirvers.sh
 01-stop-ecs:
  command: stop ecs
 02-stop-ecs:
  command: start ecs

我们只是在设置日志记录驱动程序后重新设置ecs

相关问题