flume的使用

來源:互聯網
上載者:User

標籤:

1.flume的安裝和配置

  1.1 配置java_home,修改/opt/cdh/flume-1.5.0-cdh5.3.6/conf/flume-env.sh檔案

    

  1.2 配置hdfs整合

    1.2.1添加hdfs的jar包到/opt/cdh/flume-1.5.0-cdh5.3.6/lib目錄下

      commons-configuration-1.6.jar

      hadoop-common-2.5.0-cdh5.3.6.jar

      hadoop-hdfs-2.5.0-cdh5.3.6.jar

      hadoop-auth-2.5.0-cdh5.3.6.jar

  1.3 查看flume版本 bin/flume-ng version

    

2.編寫第一個agent案例,source使用 netCat Source,channel使用 memory channel,sink使用 logger sink

  2.1 編寫/opt/cdh/flume-1.5.0-cdh5.3.6/conf/a1-conf.properties

    

# The configuration file needs to define the sources, # the channels and the sinks.# Sources, channels and sinks are defined per agent, # in this case called ‘agent‘#定義agent的三要素:source、channel、sinka1.sources = s1a1.channels = c1a1.sinks = k1#定義sourcea1.sources.s1.type=netcata1.sources.s1.bind=life-hadoop.life.coma1.sources.s1.port=44444#定義channela1.channels.c1.type=memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100#定義sinka1.sinks.k1.type=logger#定義三者之間的關係a1.sources.s1.channels=c1a1.sinks.k1.channel=c1

  2.2 安裝telnet

    sudo rpm -ivh xinetd-2.3.14-38.el6.x86_64.rpm telnet-0.17-47.el6_3.1.x86_64.rpm telnet-server-0.17-47.el6_3.1.x86_64.rpm

    sudo /etc/rc.d/init.d/xinetd restart

    

  2.3 啟動agent

    bin/flume-ng agent --conf conf/ --name a1 --conf-file conf/a1-conf.properties -Dflume.root.logger=DEBUG,console

    

  2.4 串連telnet並進行測試

    telnet life-hadoop.life.com 44444

    

    

3.編寫第二個agent,即時收集hive的日誌到hdfs上

  3.1 編寫/opt/cdh/flume-1.5.0-cdh5.3.6/conf/hive-tail-conf.properties

    

# The configuration file needs to define the sources, # the channels and the sinks.# Sources, channels and sinks are defined per agent, # in this case called ‘agent‘# 即時收集hive的日誌到hdfs檔案系統#定義agent的三要素:source、channel、sinka2.sources = s2a2.channels = c2a2.sinks = k2#定義sourcea2.sources.s2.type=execa2.sources.s2.command=tail -f /opt/cdh/hive-0.13.1-cdh5.3.6/logs/hive.log#定義channela2.channels.c2.type=memorya2.channels.c2.capacity = 1000a2.channels.c2.transactionCapacity = 100#定義sinka2.sinks.k2.type=hdfsa2.sinks.k2.hdfs.path = hdfs://life-hadoop.life.com:8020/user/yanglin/flume/hive-tail#每次重新整理多少個event到hdfs,預設:100a2.sinks.k2.hdfs.batchSize=10#修改檔案類型,預設:SequenceFilea2.sinks.k2.hdfs.fileType=DataStream#修改檔案的寫入格式,預設:Writablea2.sinks.k2.hdfs.writeFormat=Text#定義三者之間的關係a2.sources.s2.channels=c2a2.sinks.k2.channel=c2

  3.2 啟動flume用戶端開始收集

    bin/flume-ng agent --conf conf/ --name a2 --conf-file conf/hive-tail-conf.properties -Dflume.root.logger=DEBUG,console

  3.3 啟動hive用戶端,並查看hdfs系統user/yanglin/flume/hive-tail目錄下的變化

    

  3.4 對於配置ha的hadoop叢集,我們需要把core-site.xml和hdfs-site.xml拷貝到flume安裝目錄的conf目錄下

  3.5 如果需要在hdfs根據時間自動建立不同的目錄,可以在 a2.sinks.k2.hdfs.path 中使用Regex

    hdfs://life-hadoop.life.com:8020/user/yanglin/flume/hive-tail-time/%Y%m%d

    同時,必須指定:a2.sinks.k2.hdfs.useLocalTimeStamp=true

4.第三個agent案例,使用spooling source即時監測某個目錄下的檔案,經合格檔案抽取到hdfs系統中

  4.1 編寫/opt/cdh/flume-1.5.0-cdh5.3.6/conf/spooling-conf.properties

# The configuration file needs to define the sources, # the channels and the sinks.# Sources, channels and sinks are defined per agent, # in this case called ‘agent‘# 即時查看指定目錄下的檔案變化進行收集合格檔案到hdfs檔案系統#定義agent的三要素:source、channel、sinka3.sources = s3a3.channels = c3a3.sinks = k3#定義sourcea3.sources.s3.type=spooldira3.sources.s3.spoolDir=/opt/cdh/flume-1.5.0-cdh5.3.6/spooling/logs#設定收集完成之後檔案的尾碼名,預設:.COMPLETEDa3.sources.s3.fileSuffix=.delete#設定在指定目錄下的那些檔案不進行收集,預設:全部進行收集a3.sources.s3.ignorePattern=^(.)*\\.log$#定義channela3.channels.c3.type=filea3.channels.c3.capacity = 1000a3.channels.c3.transactionCapacity = 100a3.channels.c3.checkpointDir = /opt/cdh/flume-1.5.0-cdh5.3.6/spooling/checkpointa3.channels.c3.dataDirs = /opt/cdh/flume-1.5.0-cdh5.3.6/spooling/data#定義sinka3.sinks.k3.type=hdfsa3.sinks.k3.hdfs.path = hdfs://life-hadoop.life.com:8020/user/yanglin/flume/spooling-logs/%Y%m%d#每次重新整理多少個event到hdfs,預設:100a3.sinks.k3.hdfs.batchSize=10#修改檔案類型,預設:SequenceFilea3.sinks.k3.hdfs.fileType=DataStream#修改檔案的寫入格式,預設:Writablea3.sinks.k3.hdfs.writeFormat=Text#設定頭部帶有時間戳記a3.sinks.k3.hdfs.useLocalTimeStamp=true#定義三者之間的關係a3.sources.s3.channels=c3a3.sinks.k3.channel=c3

  4.2 啟動flume用戶端進行監測搜集

    bin/flume-ng agent --conf conf/ --name a3 --conf-file conf/spooling-conf.properties -Dflume.root.logger=DEBUG,console

  4.3 查看收集結果

    

    

    

    

    

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.