啟動(dòng)zookeeper、kafka并創(chuàng)建kafka主題
./bin/zkServer.sh start
./bin/kafka-server-start.sh -daemon ./config/server.properties
./bin/kafka-topic.sh --create --topic hunter --partitions 3 --replication-factor 1 --zookeeper localhost:9092
2、創(chuàng)建flume-kafka.conf配置文件
用于采集socket數(shù)據(jù)后存入kafka
在flume文件夾中的conf下新建flume-kafka.conf配置文件
vim flume-kafka.conf
a1.sources = s1
a1.channels = c1
a1.sinks = k1
a1.sources.s1.type = netcat
a1.sources.s1.bind = localhost
a1.sources.s1.port = 10050
a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = hunter
a1.sinks.k1.kafka.bootstrap.servers = master:9092
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100
a1.sources.s1.channels = c1
a1.sinks.k1.channel = c1
設(shè)置監(jiān)聽本地端口10050 netcat發(fā)送的socket數(shù)據(jù),講采集到的數(shù)據(jù)存入kafka的hunter主題中
3、啟動(dòng)flume
./bin/flue-ng agent -n a1 -c conf -f ./conf/flume-kafka.conf -Dflume.root.logger=INFO,console
./bin/flume-ng:啟動(dòng)Flume-ng二進(jìn)制文件。
agent:指定要啟動(dòng)的Flume組件類型為代理。
-c conf:設(shè)置Flume配置文件所在的目錄為當(dāng)前目錄下的conf目錄。
-f ./conf/flume_kafka.conf:指定Flume代理使用的配置文件路徑和名稱。
-n a1:給Flume代理指定一個(gè)名稱為a1。
-Dflume.root.logger=INFO,console:設(shè)置Flume代理的日志級(jí)別為INFO,并將日志輸出到控制臺(tái)。
4、創(chuàng)建kafka消費(fèi)者
./bin/kafka-console-consumer.sh --from-beginning --topic hunter --bootstrap-server localhost:9092
/bin/kafka-console-consumer.sh:啟動(dòng) Kafka 控制臺(tái)消費(fèi)者。
--from-beginning:從該主題的開始位置讀取消息。
--topic hunter:指定要消費(fèi)的主題名稱為 "hunter"。
--bootstrap-server 集群各個(gè)主機(jī):端口:指定連接到 Kafka 集群的所有 broker 的主機(jī)名和端口號(hào)文章來源:http://www.zghlxwxcb.cn/news/detail-435230.html
5、netcat向本地10050端口發(fā)送socket數(shù)據(jù)
先開啟flume,這里就會(huì)直接進(jìn)入輸入模式文章來源地址http://www.zghlxwxcb.cn/news/detail-435230.html
nc localhost 10050
讀取成功示例

flume讀取接口存入hdfs見該文
https://blog.csdn.net/HaveAGoodDay428/article/details/129569014?spm=1001.2014.3001.5501
到了這里,關(guān)于Flume學(xué)習(xí)-采集端口數(shù)據(jù)存入kafka的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!