Flume簡介與使用(三)——Kafka Sink消費資料之Kafka安裝

來源:互聯網
上載者:User

標籤:

  前面已經介紹了如何利用Thrift Source生產資料,今天介紹如何用Kafka Sink消費資料。

  其實之前已經在Flume設定檔裡設定了用Kafka Sink消費資料

agent1.sinks.kafkaSink.type = org.apache.flume.sink.kafka.KafkaSinkagent1.sinks.kafkaSink.topic = TRAFFIC_LOGagent1.sinks.kafkaSink.brokerList = 10.208.129.3:9092,10.208.129.4:9092,10.208.129.5:9092agent1.sinks.kafkaSink.metadata.broker.list = 10.208.129.3:9092,10.208.129.4:9092,10.208.129.5:9092agent1.sinks.kafkaSink.producer.type=syncagent1.sinks.kafkaSink.serializer.class=kafka.serializer.DefaultEncoderagent1.sinks.kafkaSink.channel = memoryChannel

  那麼當Flume的channel收到資料的時候,會根據設定檔主動把資料event發送到Kafka的broker上,所以只要安裝好Kafka就可以消費收據了。

Step 1: Download the code

下載安裝包並解壓

 > tar -xzf kafka_2.11-0.10.0.0.tgz

 > cd kafka_2.11-0.10.0.0

Step 2: Start the server

Kafka是基於Zookeeperl來實現分布式協同的,因此先啟動Zookeeper:

 > %Zookeeper_Home%/bin/zkServer.sh start

在設定檔server.properties中把下面一句前面的注釋去掉,然後啟動Kafka伺服器

 > #listeners=PLAINTEXT://:9092

 > bin/kafka-server-start.sh config/server.properties

接下來啟動其他兩個broker:

 > cp config/server.properties config/server-1.properties

 > cp config/server.properties config/server-2.properties

 修改設定檔,broker.id不能重複

config/server-1.properties:    broker.id=1
config/server-2.properties: broker.id=2
Step 3: Create a topic

建立一個TRAFFIC_LOG主題的broker,複製因子為3(因為有3個Kafka伺服器叢集),分區個數為1

 > bin/kafka-topics.sh --create --zookeeper 10.208.129.4:2181 --replication-factor 3 --partitions 1 --topic TRAFFIC_LOG

Step 5: Start a consumer > bin/kafka-console-consumer.sh --zookeeper 10.208.129.4:2181 --topic TRAFFIC_LOG --from-beginning
如果在終端看到之前接入的Thrift Source輸出,那麼整個Flume+Kafka算是跑通了

這裡已經引入了Flume和Kafka,下一篇將介紹Kafka以及Flume和Kafka的區別

Flume簡介與使用(三)——Kafka Sink消費資料之Kafka安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.