Flume 多個agent串聯


多個agent串聯

采集需求:比如業務系統使用log4j生成的日志,日志內容不斷增加,需要把追加到日志文件中的數據實時采集到hdfs,使用agent串聯

 

 

 

 

根據需求,首先定義以下3大要素

第一台flume agent

l  采集源,即source——監控文件內容更新 :        exec  ‘tail -F file’

l  下沉目標,即sink——數據的發送者,實現序列化  :  avro sink

l  Source和sink之間的傳遞通道——channel,可用file channel 也可以用 內存channel

第二台flume agent

l  采集源,即source——接受數據。並實現反序列化 : avro source

l  下沉目標,即sink——HDFS文件系統 :  HDFS sink

l  Source和sink之間的傳遞通道——channel,可用file channel 也可以用 內存channel

配置文件編寫:

Flume-agent1:tail-avro-avro-logger.conf

#tail-avro-avro-logger.conf

# Name the components on this agent

a1.sources = r1

a1.sinks = k1

a1.channels = c1

 

# Describe/configure the source

a1.sources.r1.type = exec

a1.sources.r1.command = tail -F

/home/hadoop/bigdatasoftware/datas/access.log

a1.sources.r1.channels = c1

 

# Describe the sink

##sink端的avro是一個數據發送者

a1.sinks.k1.type = avro

a1.sinks.k1.hostname = hadoop-001

a1.sinks.k1.port = 41414

a1.sinks.k1.batch-size = 10

 

# Use a channel which buffers events in memory

a1.channels.c1.type = memory

a1.channels.c1.capacity = 1000

a1.channels.c1.transactionCapacity = 100

 

# Bind the source and sink to the channel

a1.sources.r1.channels = c1

a1.sinks.k1.channel = c1

 

Flume-agent2: avro-hdfs.conf

a1.sources = r1

a1.sinks =s1

a1.channels = c1

 

##source中的avro組件是一個接收者服務

a1.sources.r1.type = avro

a1.sources.r1.bind = 0.0.0.0

a1.sources.r1.port = 41414

 

a1.sinks.s1.type=hdfs

a1.sinks.s1.hdfs.path=hdfs://hadoop-001:9000/logs/flume/

a1.sinks.s1.hdfs.filePrefix = access_log

a1.sinks.s1.hdfs.batchSize= 100

a1.sinks.s1.hdfs.fileType = DataStream

a1.sinks.s1.hdfs.writeFormat =Text

a1.sinks.s1.hdfs.rollSize = 10240

a1.sinks.s1.hdfs.rollCount = 1000

a1.sinks.s1.hdfs.rollInterval = 10

a1.sinks.s1.hdfs.round = true

a1.sinks.s1.hdfs.roundValue = 10

a1.sinks.s1.hdfs.roundUnit = minute

 

a1.channels.c1.type = memory

a1.channels.c1.capacity = 1000

a1.channels.c1.transactionCapacity = 100

 

a1.sources.r1.channels = c1

a1.sinks.s1.channel = c1

 

 輸入執行flume指令:

第一個終端:


 ./bin/flume-ng agent -c conf -f /home/hadoop/bigdatasoftware/flume-1.5.0/conf/avro-hdfs.conf -n a1 -Dflume.root.logger=INFO,console


 

 第二個終端:


./bin/flume-ng agent -c conf -f /home/hadoop/bigdatasoftware/flume-1.5.0/conf/tail-avro-avro-logger.conf -n a1 -Dflume.root.logger=INFO,console


 

第三個終端

在/home/hadoop/bigdatasoftware/datas/access.log文件中添加數據

 

 查看hdfs

cat一下

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM