如何在Elastic Beanstalk多容器docker上使用fluentd日志驱动程序

我试图用下面的Dockerrun.aws.json来使用fluentd日志驱动程序,

     {
       “AWSEBDockerrunVersion”:2,
       “containerDefinitions”:[
         {
           “name”:“apache”,
           “image”:“php:5.6-apache”,
           “必不可less”:真,
           “记忆”:128,
           “portMappings”:[
             {
               “hostPort”:80,
               “containerPort”:80
             }
           ]
           “logConfiguration”:{
             “logDriver”:“fluentd”,
             “选项”:{
               “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. 

我应该configuration什么?

似乎您也可以在您的应用程序环境目录中使用.ebextensions/01-fluentd.config文件来完成它, .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 

现在你必须部署一个新的应用程序版本(没有stream畅的configuration),重build你的环境,添加stream畅的configuration:

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

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

我自己解决了这个问题。

首先,我准备一个具有以下用户数据的自定义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设置中创build自定义ami的ami id。 最后,我将我的应用程序部署到Elastic Beanstalk。 在此之后,我的环境中stream利的日志驱动程序正常工作。

为了在Elastic Beanstalk多ECS_AVAILABLE_LOGGING_DRIVERS Docker中使用fluentd日志驱动程序,需要在/etc/ecs/ecs.config定义ECS_AVAILABLE_LOGGING_DRIVERSvariables。 Elastic Beanstalk多容器Docker在内部使用ECS,因此相关设置位于ECS文档中。 请阅读以下文档中的logConfiguration部分: http : logConfiguration

我已经给已经接受的答案添加了一个评论,只是添加了我用来使它为我工作的完整的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