全員:
いいです!水路とkafkaの接続については、を参照してください。
基本的に、Flumeはkafkaのプロデューサーとして使用され、ディレクトリを監視し、kafkaのコンシューマーが表示します
ステップ1:flumeのconfディレクトリにあるflume-kafka.shであるflume_kafkaの構成ファイルを編集します(スクリプトは後ろにあります)
注:このステップの前提は、最初にkafkaでkafkatestという名前のトピックを作成することです。
ステップ2:水路スクリプトを開始します
bin/flume-ng agent -c conf -f conf/flume-kafka.sh -n agent
注:次の-nはエージェントの名前です。一度踏んだことがあります。
水路を開始した後のスクリーンショットは次のとおりです。
入力待ちの状態を表示します
ステップ3:カフカの消費者プログラムを開始する
kafka-console-consumer.sh --topic kafkatest--zookeeper hadoop:2181
ステップ4:ログファイルにデータを追加し、kafkaクライアントが表示するかどうかを確認します
ログファイルにデータを追加するには、echoコマンド、crontab、またはazkabaを使用できます。
[root@hadoop test]# ll
total 40
-rw-r--r-- 1 root root 1 Mar 11 13:14 abc.log
-rw-r--r-- 1 root root 675 Aug 2 2018 derby.log
-rw-r--r-- 1 root root 85 Jul 9 2018 hbase.txt
drwxr-xr-x 5 root root 4096 Aug 2 2018 metastore_db
-rw-r--r-- 1 root root 36 Oct 20 2017 person.txt
-rw-r--r-- 1 root root 239 Jun 29 2018 stu.txt
-rw-r--r-- 1 root root 14246 Feb 22 16:59 zookeeper.out
[root@hadoop test]# echo " hello hai" >> abc.log
[root@hadoop test]# echo " hello hai1" >> abc.log
カフカが消費したかどうかを確認する
[root@hadoop ~]# kafka-console-consumer.sh --topic kafkatest --zookeeper hadoop:2181
hello hai
hello hai1
ご覧のとおり、Kafkaはすでに消費して検証しています
---flume-kafka.shのスクリプトは次のとおりです。
# 启动flume bin/flume-ng agent -c conf -f conf/flume-kafka.sh -n agent
agent.sources = s1
agent.channels = c1
agent.sinks = k1
agent.sources.s1.type=exec
agent.sources.s1.command=tail -F /root/test/abc.log
agent.sources.s1.channels=c1
agent.channels.c1.type=memory
agent.channels.c1.capacity=10000
agent.channels.c1.transactionCapacity=100
#设置一个kafka接收器
agent.sinks.k1.type= org.apache.flume.sink.kafka.KafkaSink
#设置kafka的broker地址和端口号(所有的)
agent.sinks.k1.brokerList=192.168.16.100:9092
#设置kafka的topic
agent.sinks.k1.topic=kafkatest
#设置一个序列化方式
agent.sinks.k1.serializer.class=kafka.serializer.StringEncoder
#组装
agent.sinks.k1.channel=c1