標籤:flume.kafka zookeeper
1,安裝並成功能運行flume
2,安裝並成功能運行kafka
3,安裝並成功能運行zookeeper
4,開始整合flume收集的資料,寫入kafka
a,修改flume的配置文加:
vim flume_kafka.conf
agent1.sources = r1
agent1.sinks = k1
agent1.channels = c1
# Describe/configure the source
agent1.sources.r1.type = exec
agent1.sources.r1.command=tail -f /opt/logs/usercenter.log
# Use a channel which buffers events in memory
agent1.channels.c1.type = memory
agent1.channels.c1.capacity = 1000
agent1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
agent1.sources.r1.channels = c1
agent1.sinks.k1.channel = c1
# # Describe the sink 這部分就是輸入到kafka的寫法
##############################################
agent1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
agent1.sinks.k1.topic = test
agent1.sinks.k1.brokerList = hadoop1:9092,hadoop2:9092,hadoop3:9092
agent1.sinks.k1.requiredAcks = 1
agent1.sinks.k1.batchSize = 20
##############################################
b,下載第三方外掛程式
下載flume-kafka-plus:https://github.com/beyondj2ee/flumeng-kafka-plugin
把lib目錄下的
650) this.width=650;" src="http://img.blog.csdn.net/20150416170518367?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3p3Njk4/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" style="border:none;" />
和package下的
650) this.width=650;" src="http://img.blog.csdn.net/20150416170609628?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3p3Njk4/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" style="border:none;" />
都放到flume的lib目錄
如果,報錯,請看這個文檔
http://wenda.chinahadoop.cn/question/4079?notification_id=290954&rf=false&item_id=10382#!answer_10382
修改原有的flume-conf檔案
在外掛程式包裡有一個flume-conf.properties,把這個檔案放到flume的conf檔案夾裡
然後修改以下內容
producer.sources.s.type = exec producer.sources.s.command = tail -f -n+1 /opt/logs/test.log producer.sources.s.channels = c……producer.sinks.r.custom.topic.name=test……consumer.sources.s.custom.topic.name=test
c:啟動服務
啟動zookeeper叢集
zkServer.sh start
zkServer.sh start
zkServer.sh start
還需要建立一個新的地址
zookeeper/bin/zkCli.sh
create /kafka test
啟動kafka broker 叢集
bin/kafka-server-start.sh config/server.properties
bin/kafka-server-start.sh config/server.properties
bin/kafka-server-start.sh config/server.properties
建立kafka topic
bin/kafka-topics.sh --create --zookeeper localhost:2181/kafka --replication-factor 1 --partitions 1 --topic test
啟動kafka consumer
bin/kafka-console-consumer.sh --zookeeper localhost:2181/kafka --topic test --from-beginning
啟動flume
bin/flume-ng agent --conf conf --conf-file conf/flume_kafka.properties --name producer -Dflume.root.logger=INFO,console
測試
echo "this is a test" >> /opt/logs/test.log
此時只要能在consumer裡現“this is a test”就表示成功
錯誤總結:
http://472053211.blog.51cto.com/3692116/1655844
本文出自 “crazy_sir” 部落格,請務必保留此出處http://douya.blog.51cto.com/6173221/1860896
flume 整合kafka