使用Docker搭建ELK日志搜集系统(三)

导读:上篇文章介绍了使用Fluentd搜集docker容器控制台日志的配置方法,这篇文章介绍一下使用Fluentd搜集来自文件的日志

Fluentd是用Ruby编写的,具有灵活性,对性能敏感的部分是用c编写的

这就是为什么Treasure Data, Inc提供稳定的Fluentd (td-agent)的原因。Fluentd和td-agent的区别在这里。

使用Fluentd搜集来自文件的日志配置

  • 搜集来自linux目录下日志的方法

1.安装Fluentd的td-agent

curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh
systemctl start td-agent.service
systemctl status td-agent.service
ll /etc/td-agent/td-agent.conf
#td-agent的配置文件
ll /var/log/td-agent/td-agent.log
#td-agent的标准日志输出文件
/usr/sbin/td-agent --dry-run -c /etc/td-agent/td-agent.conf
#配置文件语法检查

这里是针对Cent OS的安装
其他系统请参考:https://docs.fluentd.org/v1.0/articles/install-by-rpm

2.td-agent的示例配置文件

cat > td-agent.conf << 'EOF'
<source>
  @type tail
  <parse>
    @type json
  </parse>
  path /tmp/access.log,/tmp/error.log
  pos_file /tmp/log.pos
  tag docker.access
</source>

#<match docker.**>
#  @type stdout
#</match>

<match docker.**>
  @type elasticsearch
  hosts 10.1.1.225:9200
  user elastic
  password changeme

  target_index_key target_index
  index_name default_index
  type_name fluentd

  include_tag_key true
  tag_key DockerName

  flush_interval 1s
  request_timeout 15s
  reload_connections false
  reconnect_on_error true
  resurrect_after 5s

  buffer_type memory
  num_threads 2
</match>
EOF

可以指定多个路径或排除某些路径
请参考: https://docs.fluentd.org/v1.0/articles/in_tail#path

  • 搜集来自windows目录下日志的方法

下载地址:https://www.fluentd.org/download
安装配置方法:https://docs.fluentd.org/v1.0/articles/install-by-msi
默认配置文件地址:C:/opt/td-agent/etc/td-agent/td-agent.conf

posted @ 2016-06-30 06:26  灰色渡鹤影  阅读(241)  评论(0编辑  收藏  举报