【Docker】 Fluentd와 Elasticsearch와 Re:dash로 로그 관리

Docker에서 Fluentd, Elasticsearch 및 Re:dash를 시작하여 로그를 수집하고 분석합니다.

도커



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 웹 페이지
    http://[IP]:9200/_plugin/head/
    

    Re:dash



    자세한 내용은 아래를 참조
    Re:dash를 docker로 시작하기

    데이터 소스 추가



    Settings > DATA SOURCES > NEW DATA SOURCES

    Base URL은 이런 느낌
    http://[IP]:9200
    

    좋은 웹페이지 즐겨찾기