Win7+Flume1.8.0 + Kafka1.0.0
1.目标
①使用Flume作为Kafka的Producer;
②使用Kafka作为Flume的Sink;
其实以上两点是同一个事情在Flume和Kafka两个立场上的不同描述而已,其实就是同一个事情。
2.运行Kafka
①运行Zookeeper
zkserver
②运行Kafka
这里注意一下是否正常运行了,如果日志报错则将日志文件夹删除后再让其自动重新生成。
.\bin\windows\kafka-server-start.bat .\config\server.properties
③创建一个名字为flume的Topic
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic flume
④打开这个Topic的一个Consumer
kafka-console-consumer.bat --zookeeper localhost:2181 --topic flume
具体可参看《Windows上搭建Kafka运行环境》
3.运行Flume
①创建一个kafka_sink.conf配置文件
# 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 = netcat a1.sources.r1.bind = localhost a1.sources.r1.port = 44444 # Describe the sink a1.sinks.k1.channel = c1 a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink a1.sinks.k1.kafka.topic = flume a1.sinks.k1.kafka.bootstrap.servers = localhost:9092 a1.sinks.k1.kafka.flumeBatchSize = 20 a1.sinks.k1.kafka.producer.acks = 1 a1.sinks.k1.kafka.producer.linger.ms = 1 a1.sinks.k1.kafka.producer.compression.type = snappy # 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
flume-ng agent --conf ../conf --conf-file ../conf/kafka_sink.conf --name a1 -property flume.root.logger=INFO,console
具体可参看《Windows上搭建Flume运行环境》
4.使用telnet连接并发送数据
①启动另外一个cmd,使用telnet连接到44444端口并发送信息Test Flume and Kafka!
(这里注意一下,在测试过程中,首条数据显示较慢!)
telnet localhost 44444
②在Kafka的Consumer终端显示如下:
以上。