1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Dockerを試すサンプルメモ③(Fluentd編)

Last updated at Posted at 2020-03-11

メモ

  • やってる内容は参考リンクの公式ドキュメントと全く同じなので本来そちらを参照するべき
  • 本記事は自分の環境での実行メモ
  • 収集元:https://qiita.com/kure/items/832148a161b172039bf3hoge を定期出力するだけのイメージ
    • DockerのFluentd ログドライバを用いる
  • 収集先:FluentdのDockerイメージ
    - @type forward で受け取って @type stdout で標準出力にそのまま表示する

まずfluentedの設定ファイルを準備

ターミナルA
 % cat test.conf                                                                   (git)-[develop] 
<source>
  @type forward
</source>

<match *>
  @type stdout
</match>

受け用のFluentedのDockerコンテナを立ち上げる

ターミナルA
% docker run -it -p 24224:24224 -v [test.confへの絶対パス]:/fluentd/etc/test.conf -e FLUENTD_CONF=test.conf fluent/fluentd:latest

送る用のコンテナを立ち上げる

ターミナルB
% docker run --log-driver=fluentd [IMAGE ID]

そうするとターミナルAの方でログが逐次出力される

ターミナルA
 % docker run -it -p 24224:24224 -v /home/kure/repo/kanrinmaru-worker/kure-docker-ubuntu/test.conf:/fluentd/etc/test.conf -e FLUENTD_CONF=test.conf fluent/fluentd:latest
2020-03-11 14:37:33 +0000 [info]: parsing config file is succeeded path="/fluentd/etc/test.conf"
2020-03-11 14:37:33 +0000 [info]: using configuration file: <ROOT>
  <source>
    @type forward
  </source>
  <match *>
    @type stdout
  </match>
</ROOT>
2020-03-11 14:37:33 +0000 [info]: starting fluentd-1.3.2 pid=7 ruby="2.5.2"
2020-03-11 14:37:33 +0000 [info]: spawn command to main:  cmdline=["/usr/bin/ruby", "-Eascii-8bit:ascii-8bit", "/usr/bin/fluentd", "-c", "/fluentd/etc/test.conf", "-p", "/fluentd/plugins", "--under-supervisor"]
2020-03-11 14:37:34 +0000 [info]: gem 'fluentd' version '1.3.2'
2020-03-11 14:37:34 +0000 [info]: adding match pattern="*" type="stdout"
2020-03-11 14:37:34 +0000 [info]: adding source type="forward"
2020-03-11 14:37:34 +0000 [info]: #0 starting fluentd worker pid=17 ppid=7 worker=0
2020-03-11 14:37:34 +0000 [info]: #0 listening port port=24224 bind="0.0.0.0"
2020-03-11 14:37:34 +0000 [info]: #0 fluentd worker is now running worker=0


2020-03-11 14:38:17.000000000 +0000 804fc5e3c34d: {"container_id":"804fc5e3c34d04fe5019019a95605dd5916bfd38fec688b8a0d13f008069a614","container_name":"/eloquent_liskov","source":"stdout","log":"hoge"}
2020-03-11 14:38:18.000000000 +0000 804fc5e3c34d: {"container_name":"/eloquent_liskov","source":"stdout","log":"hoge","container_id":"804fc5e3c34d04fe5019019a95605dd5916bfd38fec688b8a0d13f008069a614"}
2020-03-11 14:38:19.000000000 +0000 804fc5e3c34d: {"container_id":"80

参考

Fluentd logging driver | Docker Documentation https://docs.docker.com/config/containers/logging/fluentd/

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?