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終端顯示如下:
以上。