万能日志数据收集器 Fluentd
前面的 ELK 中我們是用 Filebeat 收集 Docker 容器的日志,利用的是 Docker 默認的 logging driverjson-file,本節我們將使用fluentd來收集容器的日志。
Fluentd 是一個開源的數據收集器,它目前有超過 500 種的 plugin,可以連接各種數據源和數據輸出組件。在接下來的實踐中,Fluentd 會負責收集容器日志,然后發送給 Elasticsearch。日志處理流程如下:
這里我們用 Filebeat 將 Fluentd 收集到的日志轉發給 Elasticsearch。這當然不是唯一的方案,Fluentd 有一個 pluginfluent-plugin-elasticsearch可以直接將日志發送給 Elasticsearch。條條道路通羅馬,開源世界給予了我們多種可能性,可以根據需要選擇合適的方案。
安裝 Fluentd
同樣的,最高效的實踐方式是運行一個 fluentd 容器。
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 很快就能夠查詢到容器的日志。
Fluentd 咱們就討論到這里,下一節開始學習 Graylog。
書籍:
1.《每天5分鐘玩轉Docker容器技術》
https://item.jd.com/16936307278.html
2.《每天5分鐘玩轉OpenStack》
https://item.jd.com/12086376.html
總結
以上是生活随笔為你收集整理的万能日志数据收集器 Fluentd的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MLN 讨论 —— inference
- 下一篇: HBITMAP与BITMAP 的区别