Flume-ng配置

1)簡介

Flume是一個分佈式、可靠、和高可用的海量日誌聚合的系統,支持在系統中定製各類數據發送方,用於收集數據;同時,Flume提供對數據進行簡單處理,並寫到各種數據接受方(可定製)的能力。

設計目標:
(1) 可靠性
當節點出現故障時,日誌能夠被傳送到其他節點上而不會丟失。Flume提供了三種級別的可靠性保障,從強到弱依次分別爲:end-to-end(收到數據agent首先將event寫到磁盤上,當數據傳送成功後,再刪除;如果數據發送失敗,可以重新發送。),Store on failure(當數據接收方crash時,將數據寫到本地,待恢復後,繼續發送),Best effort(數據發送到接收方後,不會進行確認)。
(2) 可擴展性
Flume採用了三層架構,分別爲agent,collector和storage,每一層均可以水平擴展。其中,所有agent和collector由master統一管理,這使得系統容易監控和維護,且master允許有多個(使用ZooKeeper進行管理和負載均衡),這就避免了單點故障問題。
(3) 可管理性
所有agent和colletor由master統一管理,這使得系統便於維護。多master情況,Flume利用ZooKeeper和gossip,保證動態配置數據的一致性。用戶可以在master上查看各個數據源或者數據流執行情況,且可以對各個數據源配置和動態加載。Flume提供了web 和shell script command兩種形式對數據流進行管理。
(4) 功能可擴展性
用戶可以根據需要添加自己的agent,collector或者storage。此外,Flume自帶了很多組件,包括各種agent(file, syslog等),collector和storage(File,HDFS,HBase等)。

2)配置

之前配置過Hadoop和hbase,所以需要先將hadoop和hbase啓動,才能將文件寫入hdfs和hbase。hadoop-2.2.0和hbase-0.96.0的配置分別參考《UbuntuCentOS中分佈式配置Hadoop-2.2.0》 http://www.linuxidc.com/Linux/2014-01/95799.htm 和《CentOS分佈式環境安裝HBase-0.96.0》 http://www.linuxidc.com/Linux/2014-01/95801.htm 。

本次配置環境爲兩臺裝有centos 的測試集羣。主機名爲master的機器負責收集日誌,主機名爲node的機器負責日誌的寫入,本次配置的寫入方式有三種:寫入普通目錄,寫入hdfs。

首先下載flume-ng的二進制壓縮文件。地址:http://flume.apache.org/download.html。下載好後,解壓文件。首先編輯/etc/profile文件,在其中添加如下幾行:

  1. export FLUME_HOME=/home/aaron/apache-flume-1.4.0-bin
  2. export FLUME_CONF_DIR=$FLUME_HOME/conf
  3. export PATH=$PATH:$FLUME_HOME/bin

添加好之後記得運行$ souce /etc/profile命令使修改生效。

在master的flume文件夾的conf目錄中,新建一個flume-master.conf文件,內容如下:

  1. agent.sources = seqGenSrc
  2. agent.channels = memoryChannel
  3. agent.sinks = remoteSink
  4. # For each one of the sources, the type is defined
  5. agent.sources.seqGenSrc.type = exec
  6. agent.sources.seqGenSrc.command = tail -F /home/aaron/test
  7. # The channel can be defined as follows.
  8. agent.sources.seqGenSrc.channels = memoryChannel
  9. # Each sink's type must be defined
  10. agent.sinks.loggerSink.type = logger
  11. #Specify the channel the sink should use
  12. agent.sinks.loggerSink.channel = memoryChannel
  13. # Each channel's type is defined.
  14. agent.channels.memoryChannel.type = memory
  15. # Other config values specific to each type of channel(sink or source)
  16. # can be defined as well
  17. # In this case, it specifies the capacity of the memory channel
  18. agent.channels.memoryChannel.capacity = 100
  19. agent.channels.memoryChannel.keep-alive = 100
  20. agent.sinks.remoteSink.type = avro
  21. agent.sinks.remoteSink.hostname = node
  22. agent.sinks.remoteSink.port = 23004
  23. agent.sinks.remoteSink.channel = memoryChannel

在node機器上也將/etc/profile文件添加上面的配置。然後,在conf中新建一個flume-node.conf文件,修改如下:

  1. agent.sources = seqGenSrc1
  2. agent.channels = memoryChannel
  3. #agent.sinks = fileSink
  4. agent.sinks = <SPANstyle="FONT-FAMILY: Arial, Helvetica, sans-serif">fileSink</SPAN>
  5. # For each one of the sources, the type is defined
  6. agent.sources.seqGenSrc1.type = avro
  7. agent.sources.seqGenSrc1.bind = node
  8. agent.sources.seqGenSrc1.port = 23004
  9. # The channel can be defined as follows.
  10. agent.sources.seqGenSrc1.channels = memoryChannel
  11. # Each sink's type must be defined
  12. agent.sinks.loggerSink.type = logger
  13. #Specify the channel the sink should use
  14. agent.sinks.loggerSink.channel = memoryChannel
  15. # Each channel's type is defined.
  16. agent.channels.memoryChannel.type = memory
  17. # Other config values specific to each type of channel(sink or source)
  18. # can be defined as well
  19. # In this case, it specifies the capacity of the memory channel
  20. agent.channels.memoryChannel.capacity = 100
  21. agent.channels.memoryChannel.keep-alive = 100
  22. agent.sources.flieSink.type = avro
  23. agent.sources.fileSink.channel = memoryChannel
  24. agent.sources.fileSink.sink.directory = /home/aaron/
  25. agent.sources.fileSink.serializer.appendNewline = true

在master上面運行命令:

  1. $ bin/flume-ng agent --conf ./conf/ -f conf/flume-maste.conf -Dflume.root.logger=DEBUG,console -n agent

在node上運行命令:

  1. $ bin/flume-ng agent --conf ./conf/ -f conf/flume-node.conf -Dflume.root.logger=DEBUG,console -n agent

啓動之後,就可以發現兩者之間可以相互通信,master上面的文件就能發送到node上,修改master上的test文件,在後面追加內容時,node也可以接收到。

如果想要將內容寫入hadoop,可以將node中的flume-node.conf文件做如下修改:

  1. agent.sinks = k2
  2. agent.sinks.k2.type = hdfs
  3. agent.sinks.k2.channel = memoryChannel
  4. agent.sinks.k2.hdfs.path = hdfs://master:8089/hbase
  5. agent.sinks.k2.hdfs.fileType = DataStream
  6. agent.sinks.k2.hdfs.writeFormat = Text

 

其中,hdfs://master:8089/hbase爲hadoop的hdfs文件路徑。

發佈了10 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章