有個測試環境, 爲了定位問題需要排查很多設備上的日誌,所以就想要搞一個日誌採集,將多個業務主機上的指定日誌文件同步到一個日誌服務器上,方便查看日誌。簡單看了一下Flume就能實現這個功能,如下圖:
業務主機上的Flume代理讀取日誌文件,發送到日誌主機的Flume代理,再寫入到指定文件。
下載flume後解壓,進入bin ,執行如下:
./flume-ng agent --conf ../conf/ -n agent_is -f ../conf/xxxx.properties -Dflume.root.logger=DEBUG,consle
業務主機的Flume配置
agent_is.sources = src_is
agent_is.channels = c_is
agent_is.sinks = k_isagent_is.sources.src_is.type = exec # 通過執行腳本獲取日誌內容
agent_is.sources.src_is.command = tailf /usr/local/xxx/all.log #跟刷日誌文件
agent_is.sources.src_is.channels = c_isagent_is.channels.c_is.type = memory
agent_is.channels.c_is.capacity = 1000
agent_is.channels.c_is.transactionCapacity = 1000agent_is.sinks.k_is.type = avro
agent_is.sinks.k_is.hostname = 192.168.1.200 #日誌主機IP
agent_is.sinks.k_is.port = 14900 #監聽端口
agent_is.sinks.k_is.channel = c_is
日誌主機的Flume配置
agent_is.sources = src_is
agent_is.channels = c_is
agent_is.sinks = k_isagent_is.sources.src_is.type = avro
agent_is.sources.src_is.bind = 0.0.0.0
agent_is.sources.src_is.port = 14900 #監聽端口
agent_is.sources.src_is.channels = c_isagent_is.channels.c_is.type = memory
agent_is.channels.c_is.capacity = 1000
agent_is.channels.c_is.transactionCapacity = 1000agent_is.sinks.k_is.type = file_roll
agent_is.sinks.k_is.sink.directory = /home/flume-log/ #存放日誌文件
agent_is.sinks.k_is.sink.rollInterval = 3600 #這裏是指定一個自動混動日誌文件的時間秒數,0爲不滾動,持續寫入一個文件中。
agent_is.sinks.k_is.channel = c_is
這裏有個官方說明,還挺詳細的。
http://flume.apache.org/releases/content/1.9.0/FlumeUserGuide.html
注意配置文件中的拼寫,且啓動腳本里的-n 要和配置文件中的名稱一致。