这里有非常全的例子
http://www.aboutyun.com/thread-8917-1-1.html
这里是官方文档
http://flume.apache.org/
现在要实现一个flume发送数据到kafka的例子
1.启动zookeeper,kafka
2.配置文件
注意我用的是1.6 一定要和官方文档一致才行
配置文件
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
# Describe the sink
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
#send to kafka
a1.sinks.k1.brokerList = master:9092,slave1:9092,slave2:9092
a1.sinks.k1.serializer.class = kafka.serializer.StringEncoder
a1.sinks.k1.requiredAcks = 1
a1.sinks.k1.topic = test
# 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
2.启动
./bin/flume-ng agent --conf ./conf -f ./conf/flume-conf.properties -Dflume.root.logger=INFO,console -n a1 &
3.生产者
telnet 127.0.0.1 44444
4.消费
./bin/kafka-console-consumer.sh --zookeeper master:2181,slave1:2181,slave2:2181 --topic test --from-beginning