zoukankan      html  css  js  c++  java
  • 第 11 章 日志管理

    万能数据收集器 Fluentd

     

    ELK 中我们是用 Filebeat 收集 Docker 容器日志,利用的是 Docker 默认的 logging driver json-file。

     

    也可以使用 fluentd 来收集容器的日志。

    Fluentd 是一个开源的数据收集器,它目前有超过 500 种的 plugin,可以连接各种数据源和数据输出组件。

    在接下来的实践中,Fluentd 会负责收集容器日志,然后发送给 Elasticsearch。

    日志处理流程如下:

    这里用 Filebeat 将 Fluentd 收集到的日志转发给 Elasticsearch。

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

    条条道路通罗马,开源世界给予了我们多种可能性,可以根据需要选择合适的方案。

     

     

    安装 Fluentd

    同样的,最高效的实践方式是运行一个 fluentd 容器。

    先创建目录/data

    docker run -d -p 24224:24224 -p 24224:24224/udp -v /data:/fluentd/log fluent/fluentd

     

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

    重新配置 Filebeat

    编辑 Filebeat 的配置文件 /etc/filebeat/filebeat.yml,将 /data 添加到监控路径中。

    重启 Filebeat

    systemctl restart filebeat.service

     

    监控容器日志

    启动测试容器。

     

    docker run -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 -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 告诉 Docker 使用 Fluentd 的 logging driver。
    • --log-opt fluentd-address=localhost:24224 将容器日志发送到 Fluentd 的数据接收端口。
    • --log-opt tag="log-test-container-A" 和 --log-opt tag="log-test-container-B" 在日志中添加一个可选的 tag,用于区分不同的容器。

     

    容器启动后,Kibana 很快就能够查询到容器的日志

    ----------------------------------------------------引用来自----------------------------------------------------------

    https://mp.weixin.qq.com/s?__biz=MzIwMTM5MjUwMg==&mid=2653587991&idx=1&sn=4067b1d04e952942adf95ddb2e73bf56&chksm=8d30820eba470b182bc3dee276fb708caf470196aeb209d69f6eb156f768553c47168d651abc&scene=21#wechat_redirect

  • 相关阅读:
    CentOS 6.6 升级GCC G++ (当前最新版本为v6.1.0) (完整)
    telnet: Unable to connect to remote host: Connection refused
    bash: telnet: command not found (Linux安装telnet)
    telnet: Unable to connect to remote host: No route to host
    IP地址转换函数
    Linux 网络通信 API详解【转载】
    高效算法求解数独
    Java创建List、Map等集合对象的同时进行赋值操作
    根据先序遍历和中序遍历建立二叉树
    继承内部类时使用外部类对象.super()调用内部类的构造方法
  • 原文地址:https://www.cnblogs.com/gsophy/p/10867671.html
Copyright © 2011-2022 走看看