LoginSignup
9
9

More than 5 years have passed since last update.

【Docker】FluentdでとElasticsearchとRe:dashでログ管理

Last updated at Posted at 2016-07-22

DockerでFluentdとElasticsearchとRe:dashを起動してログの収集と解析を行います。

Docker

dockerとdocker-composeを導入

CentOSであれば下記を参照
CentOS6.5にdockerとdocker-composeをインストール

前提

  • ログは行にJSON
  • Fluentd & Elasticsearchは同じサーバ上に存在

ログ例

hoge_log
{ "type": "chatlog", "name": "hoge1", "text": "hoge1" }
{ "type": "chatlog", "name": "hoge2", "text": "hoge2" }
{ "type": "chatlog", "name": "hoge3", "text": "hoge3" }
{ "type": "chatlog", "name": "hoge4", "text": "hoge4" }
{ "type": "chatlog", "name": "hoge5", "text": "hoge5" }

Fluentd & Elasticsearch

$ mkdir ~/workspace
$ cd ~/workspace

Fluentd

$ mkdir fluentd
$ cd fluentd
$ mkdir plugins
$ vi Dockerfile
$ vi fluent.conf
Dockerfile
FROM fluent/fluentd:latest-onbuild

USER fluent

WORKDIR /home/fluent
ENV PATH /home/fluent/.gem/ruby/2.3.0/bin:$PATH
RUN gem install fluent-plugin-secure-forward
RUN gem install fluent-plugin-elasticsearch

EXPOSE 24284

CMD fluentd -c /fluentd/etc/fluent.conf -p /fluentd/plugins -vv
fluent.conf
<source>
  type tail
  path /var/log/hoge/[log file] # 収集するログファイル名を指定
  tag json.hoge
  pos_file /var/log/hoge/[log file].pos # 収集するログファイル名を指定
  format json
</source>

<match json.**>
  type copy

  <store>
    type stdout
  </store>

  <store>
    type elasticsearch
    host localhost   # elasticsearchのホスト
    port 9200        # elasticsearchのポート
    logstash_format true
  </store>
</match>

Elasticsearch

$ mkdir elasticsearch
$ cd elasticsearch
$ vi Dockerfile
Dockerfile
FROM elasticsearch

RUN bin/plugin install mobz/elasticsearch-head

EXPOSE 9200

CMD ["bin/elasticsearch", "-Des.insecure.allow.root=true"]

起動

$ cd ~/workspace
$ vi docker-compose.yml
docker-compose.yml
elasticsearch:
  build: elasticsearch
  ports:
    - 9200:9200
fluentd:
  build: fluentd
  ports:
    - 24284:24284
  volumes:
    - [log folder]:/var/log/hoge # 収集するログフォルダを指定
$ docker-compose up

ElasticsearchのWebページ

http://[IP]:9200/_plugin/head/

Re:dash

詳しくは下記を参照
Re:dashをdockerで起動する

データソースを追加

Settings > DATA SOURCES > NEW DATA SOURCES

Base URLはこんな感じ

http://[IP]:9200

スクリーンショット 2016-07-22 12.23.42.png

9
9
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
9
9