【四】Flume使用:監控檔案實時採集新增資料輸出到控制檯
阿新 • • 發佈:2019-01-09
agent選擇:exec source + memory channel + logger sink
exec source 執行一個給定的unix命令
memory channel channel中的資料放在記憶體中
logger sink 最終把採集到的資料列印到控制檯上
建立測試用的日誌檔案
mkdir /app/flume/testData
cd /app/flume/testData
touch testData.log
建立agent配置檔案
cd /app/flume/flume/conf
vi test-exec.conf
# example.conf: A single-node Flume configuration # Name the components on this agent # a1是agent的名稱 # r1是source的名稱 # k1是sink的名稱 # c1是channel的名稱 a1.sources = r1 a1.sinks = k1 a1.channels = c1 # Describe/configure the source # 配置source # 執行一個給定的Unix命令來採集資料 # 這裡是從testData.log檔案中採集資料 a1.sources.r1.type = exec a1.sources.r1.command = tail -f /app/flume/testData/testData.log a1.sources.r1.shell = /bin/sh -c # Describe the sink a1.sinks.k1.type = logger # Use a channel which buffers events in memory a1.channels.c1.type = memory # Bind the source and sink to the channel a1.sources.r1.channels = c1 a1.sinks.k1.channel = c1
執行
啟動agent
cd /app/flume/flume
bin/flume-ng agent --name a1 -c conf -f conf/test-exec.conf -Dflume.root.logger=INFO,console
其中
bin/flume-ng agent 啟動agent
--name agent的名字
-c conf 指定flume的conf路徑
-f 指定要啟動的agent的配置檔案
-Dflume.root.logger=INFO,console 把日誌資訊列印到控制檯
往監控的檔案中新增內容
cd /app/flume/testData
echo hello exce >> testData.log
檢視啟動的agent的控制檯資訊