--- tags: Fluentd --- # Fluentd introduction Fluentd是open-source的資料收集器(data collector),專為資料流設計,主要適用JSON作為資料格式,具備可擴充、高可用、高效能的資訊轉發,可乘載每日收集5000+臺伺服器上5T的日誌資料,每秒處理50000條訊息的效能. ### 基本概念 主要由Input plugin和output plugin組成( 主要定義在source block中 ),Log message可以在fluentd中被接收、傳遞、處理、過濾、再傳遞。 在使用上,可以將不同來源的資料,首先發送給自己local端的Fluentd,整理完後再透過fluentd output匯流到log server端的fluentd inupt,最後再由log server端的fluentd output會流到資料庫中,概念如下圖 (Fluentd根據配置通過不同的外掛把資訊轉發到不同的地方) Fluentd的功能 1)安裝方便 2)佔用空間小 3)半結構化資料日誌記錄 4)靈活的外掛機制 5)可靠的緩衝 (buffer) 6)日誌轉發 ### Installation step ``` $ curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh $ sudo systemctl start td-agent.service ``` 官方網站:https://docs.fluentd.org/ 配置檔案: /etc/td-agent/td-agent.conf Log 位置:/var/log/td-agent/td-agent.log --- Fluentd主要由三個部分組成: INPUT, BUFFER, OUTPUT * Input負責接收資料或者主動抓取資料。支援syslog,http,file tail * Buffer負責資料獲取的效能和可靠性,也有 file 或 memory 等不同型別的Buffer可以配置 * Output負責輸出資料到目的地例如檔案,AWS S3或者其它的Fluentd 配置文件主要可分三個部分: * **Source**:決定從哪裡讀取日誌,type指定啟用插件後配置相關係數 * **Match**:設定當指定條件滿足時,如何處理日誌的方法.在source指令追加的tag滿足match的條件時,該日誌將被指定的插件處理(條件可使用正則表達式) * **Include** (可存取其他的配置文件) ### For example. 兩個角色:Log Server, Log Client 傳輸速度需要一段時間,不會馬上出現 ``` ### td_agent.conf ### <source> @type tail path /var/log/nginx/access.log pos_file /var/log/td-agent/access.log.pos tag td.nginx <parse> @type nginx expression /^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^\"]*?)(?: +\S*)?)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)"(?:\s+(?<http_x_forwarded_for>[^ ]+))?)?$/ time_format %d/%b/%Y:%H:%M:%S %z </parse> </source> <match **> @type forward <server> name elastic-db host 192.168.43.25 port 24224 </server> </match> ‘'' # match** : 表示所有tag的log都進來 # http://127.0.0.1:9200/fluentd/_search ``` fluentd官網:https://docs.fluentd.org/ 操作參考資料:https://blog.toright.com/posts/5133/%E7%94%A8-elasticsearch-fluentd-%E6%89%93%E9%80%A0-log-%E7%A5%9E%E5%99%A8%E8%88%87%E6%95%B8%E6%93%9A%E5%88%86%E6%9E%90%E5%B7%A5%E5%85%B7.html 指令參考資料:https://51daiwei.net/fluentd-log-management-tool 概念參考資料:https://kknews.cc/zh-tw/code/l692ke9.html ### 數據採集工具比較 | Column 1 |Logstash |FileBeat | Fluentd | | -------- | -------- | -------- | -------- | | 使用場景 | 彈性 | 有限制 |彈性| | 資源消耗 | 大 | 輕量 | 輕量 | | 靈活性(提供多種差件)|高|低|高| | 數據傳遞可靠性 | 日誌服務器本身buffer| 日誌服務器本身buffer|高|
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up