docker(10、日志管理3 )4、数据收集器 Fluentd

42 篇文章 0 订阅

ELK 中我们使用的是 Filebeat 收集Docker日志,利用的是默认的logging driver json-file。下面使用 fluentd 来收集容器的日志
Fluentd 是一个开源的数据收集器,他目前有超过500中的plugin,可以连接各种数据源和数据输出组件。
Fluentd会负责收集容器日志,然后发送给Elasticsearch。日志的处理流程如下:

用 Filebeat 将 Fluentd 收集到的日志转发给 Elasticsearch。这当然不是唯一的方案,Fluentd 有一个 plugin fluent-plugin-elasticsearch 可以直接将日志发送给 Elasticsearch

安装 Fluentd

运行一个 fluentd 容器

root@host1:/var/log# docker run -d -p 24224:24224 -p 24224:24224/udp -v /data:/fluentd/log fluent/fluentd

fluentd 会在 TCP/UDP 端口 24224 上接收日志数据,日志将保存在 Host 的 /data 目录中。

重新配置 Filebeat ,添加对 /data目录的监控 

root@host1:~# vim /etc/filebeat/filebeat.yml
#=========================== Filebeat inputs =============================
filebeat.inputs:
- type: log
  enabled: true
  paths:
     - /data/*.log
 
root@host1:~# systemctl restart filebeat.service

启动测试容器

docker run --name log-test-container-A -d \
    --log-driver=fluentd \
    --log-opt fluentd-address=localhost:24224 \
    --log-opt tag="log-test-container-A" \
    busybox sh -c 'while true; do echo "This is a log message from container A"; sleep 10; done;'
 
docker run --name log-test-container-B -d \
    --log-driver=fluentd \
    --log-opt fluentd-address=localhost:24224 \
    --log-opt tag="log-test-container-B" \
    busybox sh -c 'while true; do echo "This is a log message from container B"; sleep 10; done;'

--log-driver=fluentd

    告诉容器使用fluentd的logging driver

--log-opt fluentd-address=localhost:24224

    将容器的日志发送到Fluentd的数据接收端口

--log-opt tag="log-test-container-A"

    在日志中添加tag,用于区分不同的容器

容器启动后,在Kibana中查询容器日志

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值