搭建EFK

参见 fluentd官方集成docker-logging-efk-compose

docker-compose-efk
    ├── docker-compose.yml
    ├── fluentd
         ├── Dockerfile
         └── conf
            └── fluent.conf

docker-compose.yml

version: '2'
services:
  web:
    image: httpd
    ports:
      - "8080:80"
    links:
      - fluentd
    logging:
      driver: "fluentd"
      options:
        fluentd-address: localhost:24224
        tag: httpd.access

  fluentd:
    build: ./fluentd
    volumes:
      - ./fluentd/conf:/fluentd/etc
    links:
      - "elasticsearch:elasticsearch"
    ports:
      - "24224:24224"
      - "24224:24224/udp"

  elasticsearch:
    image: elasticsearch:5.6.12
    expose:
      - 9200
    ports:
      - "9200:9200"

  kibana:
    image: kibana:5.6.12
    links:
      - "elasticsearch"
    ports:
      - "5601:5601"

fluentd/Dockerfile

FROM fluent/fluentd:v0.12.43
RUN ["gem", "sources", "--remove", "https://rubygems.org/"]
RUN ["gem", "sources", "-a", "http://gems.ruby-china.com/"]
RUN ["gem", "install", "fluent-plugin-elasticsearch","--no-rdoc", "--no-ri", "--version", "1.9.2"]

fluentd/conf/fluent.conf

<source>
  @type forward
  port 24224
  bind 0.0.0.0
</source>
<match *.**>
  @type copy
  <store>
    @type elasticsearch
    host elasticsearch
    port 9200
    logstash_format true
    logstash_prefix fluentd
    logstash_dateformat %Y%m%d
    include_tag_key true
    type_name access_log
    tag_key @log_name
    flush_interval s
  </store>
  <store>
    @type stdout
  </store>
</match>

用个例子验证下
example/httpd.yml

version: '2'
services:
  web:
    image: httpd:2.2.32
    ports:
      - "80:80"
    depends_on:
      - fluentd
    logging:
      driver: "fluentd"
      options:
        fluentd-address: localhost:24224
        tag: httpd.access
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容