Flume-使用AVRO进行级联采集数据
一、架构图
二、工作原理
Agent之间采用avro序列化方式进行数据传输。
三、示列代码
- 1、agent_1.conf文件
# nama the components on this agent
a1.sources = r1
a1.channels = c1
a1.sinks = k1
#配置source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /home/hadoop/data/flume_data/avrodir/test.log
a1.sources.r1.fileHeader = true
a1.sources.r1.channels = c1
#配置channel
a1.channels.c1.type = file
a1.channels.c1.checkpointDir = /home/hadoop/data/flume_checkpoint
a1.channels.c1.dataDir = /home/hadoop/data/flume_data
#配置sink
a1.sinks.k1.channel = c1
a1.sinks.k1.type = avro
# localhost 或者IP地址192.168.0.0
a1.sinks.k1.hostname = 192.168.200.22
a1.sinks.k1.port = 4141
- 2、agent_2.conf文件
# nama the components on this agent
a1.sources = r1
a1.channels = c1
a1.sinks = k1
#配置source
a1.sources.r1.type = avro
a1.sources.r1.bind = 0.0.0.0
a1.sources.r1.port =4141
a1.sources.r1.fileHeader = true
a1.sources.r1.channels = c1
#配置channel
a1.channels.c1.type = memory
a1.channels.c1.capacity = 10000
a1.channels.c1.transactionCapacity = 100
#配置sink
a1.sinks.k1.channel = c1
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://node1:9000/flume_data/avro_2_hdfs/files/%Y-%m-%d/%H%M
a1.sinks.k1.hdfs.filePrefix = event
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue =10
a1.sinks.k1.hdfs.roundUnit = minute
a1.sinks.k1.hdfs.rollInterval = 60
a1.sinks.k1.hdfs.rollSize = 50
a1.sinks.k1.hdfs.rollCount = 10
a1.sinks.k1.hdfs.useLocalTimeStamp=true
a1.sinks.k1.hdfs.fileType = DataStream
四、启动应用
启动的时候注意启动顺序,倒着逐个启动。
- 1、先启动Agent_2
flume-ng agent -n a1 -c /home/hadoop/my_conf -f /home/hadoop/my_conf/agent_2.conf -D flume.root.logger = info,console
- 2、再启动Agent_1
flume-ng agent -n a1 -c /home/hadoop/my_conf -f /home/hadoop/my_conf/agent_1.conf -D flume.root.logger = info,console