Spark Streaming(二)Flume
現(xiàn)狀分析
如何解決我們的數(shù)據(jù)從其他的server上移動(dòng)到Hadoop之上
Flume概述
Flume is a distributed, reliable, and available service for efficiently collecting, aggregating, and moving large amounts of log data.
主要包括收集(collecting)、聚合(aggregating)、移動(dòng)(moving)功能。
也就是說(shuō)webserver(源端)可以通過(guò)Flume移動(dòng)到HDFS(目的端)中。
Flume架構(gòu)
業(yè)界同類產(chǎn)品對(duì)比
(常用)Flume:Apache項(xiàng)目,采用java進(jìn)行開發(fā)
Scribe:Facebook項(xiàng)目,采用C/C++開發(fā),負(fù)載均衡與容錯(cuò)不是很好。目前不再維護(hù)。
Chukwa:Yahoo/Apache項(xiàng)目,采用java開發(fā),不再維護(hù)
Fluentd:與Flume類似,采用Ruby開發(fā)
(常用)Logstash:ELK(Elasticsearch+Logstash+Kibana)
安裝Flume
前置條件
下載安裝Flume
目錄結(jié)構(gòu):
配置Flume
在conf目錄下執(zhí)行cp flume-env.sh.template flume-env.sh
添加export JAVA_HOME=/home/iie4bu/app/jdk1.8.0_101
檢查運(yùn)行情況,在bin目錄下執(zhí)行:./flume-ng version
Flume實(shí)戰(zhàn)
需求1
從指定網(wǎng)絡(luò)端口采集數(shù)據(jù)輸出到控制臺(tái)。
配置
使用Flume的關(guān)鍵就是寫配置文件
A) 配置Source B) 配置Channel C) 配置Sink D) 把以上三個(gè)組件串起來(lái) a1: agent名稱 r1: source的名稱 k1: sink的名稱 c1: channel的名稱在conf目錄下新建一個(gè)example.conf, 內(nèi)容如下:
# 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# 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啟動(dòng)agent
bin/flume-ng agent --name a1 --conf $FLUME_HOME/conf --conf-file $FLUME_HOME/conf/example.conf -Dflume.root.logger=INFO,console
其中:
使用nc進(jìn)行測(cè)試
重新開一個(gè)窗口,使用nc命令在本地測(cè)試44444端口
在Flume中可以看到輸出結(jié)果:
在輸出的日志中可以看到Event:
Event: { headers:{} body: 61 62 63 abc }
這個(gè)Event就是Flume中數(shù)據(jù)傳輸?shù)幕締卧?/p>
需求2
監(jiān)控一個(gè)文件實(shí)時(shí)采集新增的數(shù)據(jù)輸出到控制臺(tái)
配置
Agent選型:exec source + memory channel + logger sink
在$FLUME_HOME/conf目錄下新建exec-memory-logger.conf配置文件,內(nèi)容如下:
啟動(dòng)agent
bin/flume-ng agent --name a1 --conf $FLUME_HOME/conf --conf-file /home/iie4bu/app/apache-flume-1.6.0-cdh5.15.1-bin/conf/exec-memory-logger.conf -Dflume.root.logger=INFO,console
這樣就實(shí)現(xiàn)了監(jiān)聽/home/iie4bu/data/hello.txt文件,并把里面的內(nèi)容輸出到控制臺(tái)。
需求3
將A服務(wù)器上的日志實(shí)時(shí)采集到B服務(wù)器。
Agent選型
機(jī)器A上的agent選型:exec source + memory channel + avro sink
機(jī)器B上的agent選型:avro source + memory channel + logger sink
配置Agent
新建exec-memory-avro.conf,內(nèi)容如下:
新建avro-memory-logger.conf,內(nèi)容如下:
avro-memory-logger.sources = avro-source avro-memory-logger.sinks = logger-sink avro-memory-logger.channels = memory-channel# Describe/configure the source avro-memory-logger.sources.avro-source.type = avro avro-memory-logger.sources.avro-source.bind = localhost avro-memory-logger.sources.avro-source.port = 44444# Describe the sink avro-memory-logger.sinks.logger-sink.type = logger# Use a channel which buffers events in memory avro-memory-logger.channels.memory-channel.type = memory avro-memory-logger.channels.memory-channel.capacity = 1000 avro-memory-logger.channels.memory-channel.transactionCapacity = 100# Bind the source and sink to the channel avro-memory-logger.sources.avro-source.channels = memory-channel avro-memory-logger.sinks.logger-sink.channel = memory-channel啟動(dòng)agent
這里要注意啟動(dòng)順序。
首先啟動(dòng)avro-memory-logger.conf:bin/flume-ng agent --name avro-memory-logger --conf $FLUME_HOME/conf --conf-file /home/iie4bu/app/apache-flume-1.6.0-cdh5.15.1-bin/conf/avro-memory-logger.conf -Dflume.root.logger=INFO,console
然后再啟動(dòng)exec-memory-avro.conf:bin/flume-ng agent --name exec-memory-avro --conf $FLUME_HOME/conf --conf-file /home/iie4bu/app/apache-flume-1.6.0-cdh5.15.1-bin/conf/exec-memory-avro.conf -Dflume.root.logger=INFO,console
當(dāng)我們給/home/iie4bu/data/hello.txt文件添加內(nèi)容時(shí),在avro-memory-logger.conf就會(huì)打印輸出響應(yīng):
延時(shí)
這里兩個(gè)Agent之間會(huì)有一定的延時(shí),因?yàn)閏hannel是基于內(nèi)存,有大小設(shè)置,到了一定的時(shí)間才會(huì)進(jìn)行相應(yīng)的操作。
總結(jié)日志收集過(guò)程
總結(jié)
以上是生活随笔為你收集整理的Spark Streaming(二)Flume的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 「重点」枇杷成熟的季节是几月
- 下一篇: 这款应用能让所有安卓手机与PC多屏协同安