很简单,大家不要感觉很高大上
写之前 小伙伴先确保自己的zk跟kafka集群可以用哈,不然运行下面的代码无效
在kafka/job/下创建文件 flumeTokafka.conf
job是我的一个文件夹,这个conf文件 放在哪都行
# 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 = logger
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.topic = test01
a1.sinks.k1.brokerList = es2:9092
a1.sinks.k1.requiredAcks = 1
a1.sinks.k1.batchSize = 20
# 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
kafka创建一个topic
./bin/kafka-topics.sh --create --zookeeper 192.168.244.160:2181,192.168.244.161:2181,192.168.244.162:2181 --partition 3 --replication-factor 3 --topic test01
然后开启消费者
./bin/kafka-console-consumer.sh --zookeeper 192.168.244.160:2181,192.168.244.161:2181,192.138.244.162:2181 --topic test01 --from-beginning
开启Flume
进入到flume的bin目录下
bin/flume-ng agent --conf conf/ --name a1 --conf-file job/flumeTokafka.conf
再打开一个这台机器的窗口
telnet localhost 44444模仿系统向flume输入数据
输入a s ds s s然后kafka会消费到,Ok测试完成