1. 程式人生 > >Flume 配置和讀取tomcat檔案到指定位置

Flume 配置和讀取tomcat檔案到指定位置

需要交流請進群-- 494831900 --我和群中朋友會及時回答

1:去官網下載 flume 1.5  網址是:flume.apache.org

2: 解壓對應的tar 包 

3:進去flume的conf目錄 建立一個檔案 vi  example.conf 

# Define a memory channel called ch1 on agent1 agent1.channels.ch1.type = memory # Define an Avro source called avro-source1 on agent1 and tell it # to bind to 0.0
.0.0:41414. Connect it to channel ch1. agent1.sources.avro-source1.channels = ch1 agent1.sources.avro-source1.type = avro agent1.sources.avro-source1.bind = 0.0.0.0 agent1.sources.avro-source1.port = 41414 # Define a logger sink that simply logs all events it receives # and connect it to the other end of the same channel.
agent1.sinks.log-sink1.channel = ch1 agent1.sinks.log-sink1.type = logger # Finally, now that we've defined all of our components, tell # agent1 which ones we want to activate. agent1.channels = ch1 agent1.sources = avro-source1 agent1.sinks = log-sink1 _____________________________________________________________
把內容拷貝進去  mv  flume-env.sh.template  flume-env.sh 然後更改  flume-env.sh 裡面的java_home 變成你自己的  執行命令  --進入bin目錄後 如果配置了環境變數 不需要進去bin目錄執行次命令否則進入bin執行此命令 flume-ng agent --conf conf/ -f example.conf  -Dflume.root.logger=DEBUG,console -n agent1
--name,-n <agentname>
是指配置檔案中的 agent的名字 我這個裡叫 agent1
--conf-file,-f <file>  這個是指配置檔案的目錄 和要指定的配置檔案
flume-ng avro-client --conf /usr/local/flume/conf -H localhost -p 41414-F /etc/passwd -Dflume.root.logger=DEBUG,console
會打印出內容 ----------------------讀取tomcat logs ------------------------------------------------ 在配置檔案中 新建一個 tomcat.conf 內容如下 agent1.channels.ch1.type = file
 
agent1.sources.avro-source1.channels = ch1
agent1.sources.avro-source1.type = exec
agent1.sources.avro-source1.bind = 0.0.0.0
agent1.sources.avro-source1.port = 41414
agent1.sources.avro-source1.command = t
ail -n +0 -F /usr/local/tomcat/logs/catalina.out  #linux命令的輸出接受 
 
agent1.sinks.log-sink1.channel = ch1
agent1.sinks.log-sink1.type = file_rol
l   #是指輸入型別 讀取檔案時的
agent1.sinks.log-sink1.directory=/var/log/d
ata     #這個是指讀取tomcat的日誌到什麼目錄下
 
agent1.channels = ch1
agent1.sources = avro-source1
agent1.sinks = log-sink1
a          配置好後,執行命令:flume-ng agent --conf conf --conf-file conf/tomcat.conf --name agent1 -Dflume.root.logger=INFO,console 啟動tomcat  進入 cd /var/log/data 就會看到如下圖
大功告成!!! 下面是一篇詳細介紹flume的文章連結 http://www.jb51.net/article/53542.htm