0. 安裝
- 下載
wget http://apache.fayea.com/flume/1.7.0/apache-flume-1.7.0-bin.tar.gz
- 解壓
tar -zxvf apache-flume-1.7.0-bin.tar.gz
-
環(huán)境變量
- 建立符號(hào)連接 ln -s xxx /soft/flume
- 配置/etc/profile
啟動(dòng)
flume-ng agent -f /soft/flume/conf/nc2kafka.conf -n a1 -Dflume.root.logger=INFO,console
1. 自定義Interceptor
2. 配置文件
0. netcat 2 logger
# -----nc2log.conf
#netcat 2 logger
a1.sources = r1
a1.sinks = k1
a1.channels = c1
#netcat 8888 端口
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 8888
# Describe the sink
a1.sinks.k1.type = logger
# 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
1. netcat 2 kafka
# -----nc2kafka.conf
#netcat 2 kafka
a1.sources = r1
a1.sinks = k1
a1.channels = c1
#netcat 8888 端口
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 8888
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = hellokfk
a1.sinks.k1.kafka.bootstrap.servers = localhost:9092
a1.sinks.k1.kafka.flumeBatchSize = 20
a1.sinks.k1.kafka.producer.acks = 1
a1.channels.c1.type = memory
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
2. spool 2 logger
# -----sp2log.conf
#spool 2 logger
a1.sources = r1
a1.channels = c1
a1.sinks = k1
#source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /soft/log
a1.sources.r1.consumeOrder = youngest
a1.sources.r1.recursiveDirectorySearch = false
a1.sources.r1.deletePolicy = immediate
a1.sources.r1.pollDelay = 500
#自定義flume interceptor
#如果不需要可以去掉
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type = cn.dbboy.flume.LogInterceptor$Builder
a1.sources.r1.interceptors.i1.pattern = before:after
#channe1
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
#sink
a1.sinks.k1.type = logger
#package
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
3. spool 2 kafka
# -----sp2kafka.conf
#spool 2 logger
#agent
a1.sources = r1
a1.channels = c1
a1.sinks = k1
#source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /soft/log
a1.sources.r1.consumeOrder = youngest
a1.sources.r1.recursiveDirectorySearch = false
a1.sources.r1.deletePolicy = immediate
a1.sources.r1.pollDelay = 500
#自定義flume interceptor
#如果不需要可以去掉
a1.sources.r1.interceptors = i1
a1.sources.r1.interceptors.i1.type = cn.dbboy.flume.LogInterceptor$Builder
a1.sources.r1.interceptors.i1.pattern = before:after
#channe1
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
#sink
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = hellokfk
a1.sinks.k1.kafka.bootstrap.servers = localhost:9092
a1.sinks.k1.kafka.flumeBatchSize = 20
a1.sinks.k1.kafka.producer.acks = 1
#package
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1