flume介绍与配置案例

 

->使用(解压即用)

安装Flume                                                                           

下载                                                                              
解压到~/app                                                                       
将java配置系统环境变量中: ~/.bash_profile                                         
export FLUME_HOME=/home/hadoop/app/apache-flume-1.6.0-cdh5.7.0-bin              
export PATH=$FLUME_HOME/bin:$PATH                                               
source下让其配置生效                                                             
flume-env.sh的配置:export JAVA_HOME=/home/hadoop/app/jdk1.8.0_144                
检测: flume-ng version                                                                                                                                                                                                                                                                                                                          
使用Flume的关键就是写配置文件                                                                                                                                           

A) 配置Source                                                                      
B) 配置Channel                                                                     
C) 配置Sink                                                                        
D) 把以上三个组件串起来                                                            
                                                                                    

a1: agent名称                                                                       
r1: source的名称                                                                    
k1: sink的名称                                                                      
c1: channel的名称                                                                   
                                                                                    
Agent选型:exec source + memory channel + logger sink
#example.conf: A single-node Flume configuration

# 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/data/data.log
a1.sources.r1.shell = /bin/sh -c

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
a1.channels.c1.type = memory

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

启动agent
flume-ng agent \
--name a1  \
--conf $FLUME_HOME/conf  \
--conf-file $FLUME_HOME/conf/exec-memory-logger.conf \
-Dflume.root.logger=INFO,console                                                                                                                                                                                                                                                   
Event: { headers:{} body: 68 65 6C 6C 6F 0D hello. }                                

Event是FLume数据传输的基本单元                                                      
Event =  可选的header + byte array            

->案例:

1.flume-kafka

----------------------------------------------------------vim kafka.conf------------------------------------------------------
exec-memory-kafka.sources = exec-source
exec-memory-kafka.sinks = kafka-sink
exec-memory-kafka.channels = memory-channel

exec-memory-kafka.sources.exec-source.type = exec
exec-memory-kafka.sources.exec-source.command = tail -F tail -F /root/data/data.log
exec-memory-kafka.sources.exec-source.shell = /bin/sh -c

exec-memory-kafka.channels.memory-channel.type = memory

exec-memory-kafka.sinks.kafka-sink.type = org.apache.flume.sink.kafka.KafkaSink
exec-memory-kafka.sinks.kafka-sink.brokerList = hdp01:9092
exec-memory-kafka.sinks.kafka-sink.topic = my-topic
exec-memory-kafka.sinks.kafka-sink.batchSize = 5
exec-memory-kafka.sinks.kafka-sink.requiredAcks = 1

exec-memory-kafka.sources.exec-source.channels = memory-channel
exec-memory-kafka.sinks.kafka-sink.channel = memory-channel
 

启动:flume-ng agent --name exec-memory-kafka --conf $FLUME_HOME/conf --conf-file /root/software/apache-flume-1.7.0-bin/conf/kafka-conf  -Dflume.root.logger=INFO,console

--------------------------------------------------------------------------------------------------------------------------------

--------------------------------------------------vim  flume-hdfs-------------------------------------------------------------

# 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 /root/data/data.log
a1.sources.r1.shell = /bin/sh -c

# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://hdp03:9000/test/data.log

# Use a channel which buffers events in memory
a1.channels.c1.type = memory

# Bind the source and sink to the channel

a1.sources.r1.channels = c1

a1.sinks.k1.channel = c1

启动:flume-ng agent --name a1 --conf $FLUME_HOME/conf --conf-file /root/software/apache-flume-1.7.0-bin/conf/hdfs-conf  -Dflume.root.logger=INFO,console

--------------------------------------------------------------------------------------------------------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值