使用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

转载于:https://www.cnblogs.com/yjb007/p/9557968.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值