【问题标题】:How to config fluentd with docker?如何使用 docker 配置 fluentd?
【发布时间】:2015-11-09 02:58:54
【问题描述】:

我现在正在使用 Rails 应用程序。在我的应用程序配置文件中,我添加了这个:

config/application.rb

logger = Fluent::Logger::FluentLogger.new(nil, host: '127.0.0.1', port: '24224')

然后在 docker 中启动应用程序,看到这些错误日志:

$ docker-compose up

...
sidekiq_1 | E, [2015-11-09T02:45:44.857664 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
sidekiq_1 | E, [2015-11-09T02:45:44.860403 #1] ERROR -- : Connection will be retried.
sidekiq_1 | E, [2015-11-09T02:45:44.862926 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
sidekiq_1 | E, [2015-11-09T02:45:44.864514 #1] ERROR -- : Connection will be retried.
web_1     | E, [2015-11-09T02:45:48.512481 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
web_1     | E, [2015-11-09T02:45:48.512785 #1] ERROR -- : Connection will be retried.
web_1     | E, [2015-11-09T02:45:48.515245 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
web_1     | E, [2015-11-09T02:45:48.515571 #1] ERROR -- : Connection will be retried.
...

我的docker机器的ip:

$ docker-machine ip myapp
=> 192.168.99.100

我的码头工人ps:

$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
b5e980e1aa61        myapp_web         "bundle exec rails s "   About an hour ago   Up 6 minutes        0.0.0.0:3000->3000/tcp   myapp_web_1
43365dfb403f        myapp_sidekiq     "bundle exec sidekiq "   About an hour ago   Up 6 minutes                                 myapp_sidekiq_1
9570ee727f04        mysql               "/entrypoint.sh mysql"   About an hour ago   Up 6 minutes        0.0.0.0:3306->3306/tcp   myapp_db_1
e24495920c58        redis               "/entrypoint.sh redis"   2 days ago          Up 6 minutes        0.0.0.0:6379->6379/tcp   myapp_redis_1

为什么连接fluentd关于sidekiq和web图片失败?


编辑

将此添加到Dockerfile

RUN mkdir -p /fluentd/etc

将此添加到docker-compose.yml

fluentd:
  image: fluent/fluentd:latest
  ports:
    - "24224:24224"

启动应用时,日志显示:

fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: reading config file path="/fluentd/etc/fluent.conf"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: starting fluentd-0.12.16
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: gem 'fluentd' version '0.12.16'
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: adding match in @mainstream pattern="docker.**" type="file"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: adding match in @mainstream pattern="**" type="file"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: adding filter pattern="**" type="stdout"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: adding source type="forward"
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: using configuration file: <ROOT>
fluentd_1 |   <source>
fluentd_1 |     @type forward
fluentd_1 |     @id input1
fluentd_1 |     @label @mainstream
fluentd_1 |     port 24224
fluentd_1 |   </source>
fluentd_1 |   <filter **>
fluentd_1 |     @type stdout
fluentd_1 |   </filter>
fluentd_1 |   <label @mainstream>
fluentd_1 |     <match docker.**>
fluentd_1 |       @type file
fluentd_1 |       @id output_docker1
fluentd_1 |       path /fluentd/log/docker.*.log
fluentd_1 |       symlink_path /fluentd/log/docker.log
fluentd_1 |       append true
fluentd_1 |       time_slice_format %Y%m%d
fluentd_1 |       time_slice_wait 1m
fluentd_1 |       time_format %Y%m%dT%H%M%S%z
fluentd_1 |       buffer_path /fluentd/log/docker.*.log
fluentd_1 |     </match>
fluentd_1 |     <match **>
fluentd_1 |       @type file
fluentd_1 |       @id output1
fluentd_1 |       path /fluentd/log/data.*.log
fluentd_1 |       symlink_path /fluentd/log/data.log
fluentd_1 |       append true
fluentd_1 |       time_slice_format %Y%m%d
fluentd_1 |       time_slice_wait 10m
fluentd_1 |       time_format %Y%m%dT%H%M%S%z
fluentd_1 |       buffer_path /fluentd/log/data.*.log
fluentd_1 |     </match>
fluentd_1 |   </label>
fluentd_1 | </ROOT>
fluentd_1 | 2015-11-09 09:51:07 +0000 [info]: listening fluent socket on 0.0.0.0:24224
sidekiq_1 | E, [2015-11-09T09:51:11.887833 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
sidekiq_1 | E, [2015-11-09T09:51:11.888508 #1] ERROR -- : Connection will be retried.
sidekiq_1 | E, [2015-11-09T09:51:11.893544 #1] ERROR -- : Failed to connect fluentd: Connection refused - connect(2) for "127.0.0.1" port 24224
sidekiq_1 | E, [2015-11-09T09:51:11.893926 #1] ERROR -- : Connection will be retried.

ip 127.0.0.1 好像不对。 我现在正在使用 docker-machine。

【问题讨论】:

    标签: ruby-on-rails docker fluentd


    【解决方案1】:

    确保您的docker-compose.yml 有一个fluentd 部分(as this one),至少暴露了端口24224(除非您想直接从主机访问它,否则您没有顶部映射它)

    原始答案(2015 年)

    那么你的 rail docker-compose.yml sidekiq 部分应该有一个链接部分:

    links:
      - fluentd
    

    更新的答案(2021 年,在 battlecookcomment 之后) 由于links is obsolete,使用depends_on

    depends_on:
      - fluentd
    

    见“Difference between links and depends_on in docker_compose.yml”。
    示例:“How to use Dockerfile to link main container to a db container?”。

    【讨论】:

    • 感谢您的精彩回答。我已经按照你的建议做了。但是当我启动我的应用程序时,它显示:No such file or directory @ rb_sysopen - /fluentd/etc/fluent.conf (Errno::ENOENT).
    • @scho 看起来像一个尚未安装的卷 (docs.docker.com/compose/compose-file/#volumes-from)
    • 顺便问一下@scho,你在用github.com/GoCarrot/fluent-plugin-sidekiq吗?
    • 我现在没有使用fluent-plugin-sidekiq
    • 我更新了我的主题。可能问题出在 IP 地址上。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 2020-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    • 2020-02-11
    相关资源
    最近更新 更多