標籤:flume hdfs hadoop
一、概述
1、現在有三台機器,分別是:Hadoop1,Hadoop2,Hadoop3,以Hadoop1為日誌匯總
2、Hadoop1匯總的同時往多個目標進行輸出
3、Flume一個資料來源對應多個channel,多個sink,是在consolidation-accepter.conf檔案裡配置的
二、部署Flume來採集日誌和匯總日誌
1、在Hadoop1上運行
flume-ng agent --conf ./ -f consolidation-accepter.conf -n agent1 -Dflume.root.logger=INFO,console
其指令碼(consolidation-accepter.conf)內容如下
# Finally, now that we've defined all of our components, tell# agent1 which ones we want to activate.agent1.channels = ch1 ch2agent1.sources = source1agent1.sinks = hdfssink1 sink2agent1.source.source1.selector.type = replicatingagent1.source.source1.selector.optional = ch1# Define a memory channel called ch1 on agent1agent1.channels.ch1.type = memoryagent1.channels.ch1.capacity = 1000000agent1.channels.ch1.transactionCapacity = 1000000agent1.channels.ch1.keep-alive = 10agent1.channels.ch2.type = memoryagent1.channels.ch2.capacity = 1000000agent1.channels.ch2.transactionCapacity = 100000agent1.channels.ch2.keep-alive = 10# 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.source1.channels = ch1 ch2agent1.sources.source1.type = avroagent1.sources.source1.bind = conagent1.sources.source1.port = 44444agent1.sources.source1.threads = 5# Define a logger sink that simply logs all events it receives# and connect it to the other end of the same channel.agent1.sinks.hdfssink1.channel = ch1agent1.sinks.hdfssink1.type = hdfsagent1.sinks.hdfssink1.hdfs.path = hdfs://mycluster/flume/%Y-%m-%d/%H%Magent1.sinks.hdfssink1.hdfs.filePrefix = S1PA124-consolidation-accesslog-%H-%M-%Sagent1.sinks.hdfssink1.hdfs.useLocalTimeStamp = trueagent1.sinks.hdfssink1.hdfs.writeFormat = Textagent1.sinks.hdfssink1.hdfs.fileType = DataStreamagent1.sinks.hdfssink1.hdfs.rollInterval = 1800agent1.sinks.hdfssink1.hdfs.rollSize = 5073741824agent1.sinks.hdfssink1.hdfs.batchSize = 10000agent1.sinks.hdfssink1.hdfs.rollCount = 0agent1.sinks.hdfssink1.hdfs.round = trueagent1.sinks.hdfssink1.hdfs.roundValue = 60agent1.sinks.hdfssink1.hdfs.roundUnit = minuteagent1.sinks.sink2.type = loggeragent1.sinks.sink2.sink.batchSize=10000agent1.sinks.sink2.sink.batchTimeout=600000agent1.sinks.sink2.sink.rollInterval = 1000agent1.sinks.sink2.sink.directory=/root/data/flume-logs/agent1.sinks.sink2.sink.fileName=accesslogagent1.sinks.sink2.channel = ch2
2、分別在Hadoop2和Hadoop3運行如下命令
flume-ng agent --conf ./ --conf-file collect-send.conf --name agent1
Flume資料發送器設定檔collect-send.conf內容如下
agent2.sources = source2agent2.sinks = sink1agent2.channels = ch2agent2.sources.source2.type = execagent2.sources.source2.command = tail -F /root/data/flume.logagent2.sources.source2.channels = ch2#channels configurationagent2.channels.ch2.type = memoryagent2.channels.ch2.capacity = 10000agent2.channels.ch2.transactionCapacity = 10000agent2.channels.ch2.keep-alive = 3#sinks configurationagent2.sinks.sink1.type = avroagent2.sinks.sink1.hostname=consolidationIpAddressagent2.sinks.sink1.port = 44444agent2.sinks.sink1.channel = ch2
三、總結
1、啟動Flume匯總進程 flume-ng agent --conf ./ -f consolidation-accepter.conf -n agent1 -Dflume.root.logger=INFO,console2、啟動Flume採集進程 flume-ng agent --conf ./ --conf-file collect-send.conf --name agent13、配置參數說明(以下兩個條件是or的關係,也就是當一個條件滿足就觸發)(1)每半小時把channel裡的資料沖刷到sink中去,並且另起新的檔案來儲存 agent1.sinks.hdfssink1.hdfs.rollInterval = 1800(2)當檔案大小為5073741824位元組時,另起新的檔案來儲存 agent1.sinks.hdfssink1.hdfs.rollSize = 5073741824
Flume一個資料來源對應多個channel,多個sink