Data Collection with Apache Flume(二)

來源:互聯網
上載者:User

標籤:

      今天繼續討論幾個agent的配置。

      第一個agent是從終端捕獲特定命令執行的輸出結果,並將檔案輸出到特定目錄。先看一下配置的代碼:      

agent2.sources = execsource      //指定為從命令擷取輸出的sourceagent2.sinks = filesink          //輸出到檔案的sinkagent2.channels = filechannel     //輸出到檔案的channelagent2.sources.execsource.type = exec  //類型agent2.sources.execsource.command = cat /home/leung/message   //指定命令agent2.sinks.filesink.type = FILE_ROLLagent2.sinks.filesink.sink.directory = /home/leung/flume/files     //輸出目錄agent2.sinks.filesink.sink.rollInterval = 0agent2.channels.filechannel.type = fileagent2.channels.filechannel.checkpointDir = /home/leung/flume/fc/checkpoint //檢查點agent2.channels.filechannel.dataDirs = /home/leung/flume/fc/data  //channel的資料目錄agent2.sources.execsource.channels = filechannelagent2.sinks.filesink.channel = filechannel

   OK,啟動agent2,然後查看結果。

      

      結果如。可以看到,執行 cat /home/leung/message命令之後,輸出的結果與files目錄中的檔案內容是一致的,證明已經成功寫入檔案。

      

      下一個agent是從網路連接埠 擷取資料然後寫到Hadoop叢集的HDFS中。先看看配置代碼:

agent4.sources = netsource agent4.sinks = hdfssink //HDFS sinkagent4.channels = memorychannelagent4.sources.netsource.type = netcatagent4.sources.netsource.bind = localhostagent4.sources.netsource.port = 3000agent4.sinks.hdfssink.type = hdfsagent4.sinks.hdfssink.hdfs.path = /flume  //寫出到HDFS上的檔案目錄,不需要提前建立agent4.sinks.hdfssink.hdfs.filePrefix = log  //指定寫出檔案的檔案名稱首碼agent4.sinks.hdfssink.hdfs.rollInterval = 0agent4.sinks.hdfssink.hdfs.rollCount = 3agent4.sinks.hdfssink.hdfs.fileType = DataStreamagent4.channels.memorychannel.type = memoryagent4.channels.memorychannel.capacity = 1000agent4.channels.memorychannel.transactionCapacity = 100agent4.sources.netsource.channels = memorychannelagent4.sinks.hdfssink.channel = memorychannel

    下面啟動agent4以及查看一下結果。 

     

       下面查看一下結果。發現在HDFS中已經建立了一個flume檔案夾,並且已經寫入了指定的內容。

      

      接著我們為檔案夾名加一個時間戳記。詳細看如下配置代碼。

agent5.sources = netsourceagent5.sinks = hdfssinkagent5.channels = memorychannelagent5.sources.netsource.type = netcatagent5.sources.netsource.bind = localhostagent5.sources.netsource.port = 3000agent5.sources.netsource.interceptors = tsagent5.sources.netsource.interceptors.ts.type = org.apache.flume.interceptor.TimestampInterceptor$Builder //引用這個類方法新增時間戳記agent5.sinks.hdfssink.type = hdfsagent5.sinks.hdfssink.hdfs.path = /flume-%Y-%m-%d //定義檔案夾名格式agent5.sinks.hdfssink.hdfs.filePrefix = log-agent5.sinks.hdfssink.hdfs.rollInterval = 0agent5.sinks.hdfssink.hdfs.rollCount = 3agent5.sinks.hdfssink.hdfs.fileType = DataStreamagent5.channels.memorychannel.type = memoryagent5.channels.memorychannel.capacity = 1000agent5.channels.memorychannel.transactionCapacity = 100agent5.sources.netsource.channels = memorychannelagent5.sinks.hdfssink.channel = memorychannel

  OK,下面啟動agent5。

     

     下面查看一下結果。可以看到檔案夾的名字被如期地加上了日期。

     

     

     OK,先到這裡,還有兩個稍微複雜一點點的agent下次再討論。本人水平有限,請各位不吝指正!謝謝!

Data Collection with Apache Flume(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.