進(jìn)入flume目錄D:\apache-flume-1.9.0-bin\conf瞳别,創(chuàng)建配置文件kafka.conf
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = spooldir
a1.sources.r1.spoolDir = /test/flumeSpool
a1.sources.r1.fileHeader = true
# Describe the sink
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = test
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
保存配置文件房铭,在D:\apache-flume-1.9.0-bin\conf打開命令窗口吴攒,輸入
flume-ng agent --conf ../conf --conf-file kafka.conf --name a1
啟動(dòng)zookeeper環(huán)境以后,啟動(dòng)kafka
.\bin\windows\kafka-server-start.bat .\config\server.properties
啟動(dòng)kafka的消費(fèi)者
.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic test --from-beginning
這里的topic與D:\apache-flume-1.9.0-bin\conf下的配置文件kafka.conf里的sink組件中的topic一致
我們可以在D:\kafka_2.11-1.0.0\config下的server.properties文件內(nèi)找到log.dirs,log.dirs對應(yīng)的值就是kafka寫入文件所在的位置