Flume的安裝與綜合使用

Flume + Kafka基本是日志實時采集的標(biāo)準(zhǔn)搭檔了。
本篇文章基于Flume-ng-1.6.0-cdh5.7.0 + CentOS6.7 + JDK1.6+

  • 下載,安裝JDK

1.解壓到 ~/app
2.將java配置系統(tǒng)環(huán)境變量中: vi ~/.bash_profile

export JAVA_HOME=/home/hadoop/app/jdk1.8.0_144
export PATH=$JAVA_HOME/bin:$PATH

3.source ~/.bash_profile下讓其配置生效,
4.檢測是否安裝JDK成功:java -version

  • 下載,安裝Flume

1.下載,解壓到 ~/app
2.將flume配置到系統(tǒng)環(huán)境變量中: ~/.bash_profile

export FLUME_HOME=/home/hadoop/app/apache-flume-1.6.0-cdh5.7.0-bin
export PATH=$FLUME_HOME/bin:$PATH

3.source ~/.bash_profile讓其配置生效,
4.修改flume-env.sh的配置:

cd  $FLUME_HOME/conf
cp flume-env.sh.template flume-env.sh
vi flume-env.sh
export JAVA_HOME=/home/hadoop/app/jdk1.8.0_144

5.檢測: flume-ng version:

Flume 1.6.0-cdh5.7.0
Source code repository: https://git-wip-us.apache.org/repos/asf/flume.git
Revision: 8f5f5143ae30802fe79f9ab96f893e6c54a105d1
Compiled by jenkins on Wed Mar 23 11:38:48 PDT 2016
From source with checksum 50b533f0ffc32db9246405ac4431872e

  • 從指定的網(wǎng)絡(luò)端口采集數(shù)據(jù)輸出到控制臺

A single-node Flume configuration

1.使用Flume的關(guān)鍵就是寫配置文件
A) 配置Source
B) 配置Channel
C) 配置Sink
D) 把以上三個組件串起來

a1: agent名稱 
r1: source的名稱
k1: sink的名稱
c1: channel的名稱

2.下面是一個簡單的配置文件范例,該例子通過netcat產(chǎn)生日志,
持續(xù)輸出到console中。

  • example.conf配置:
# 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 = hadoop
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

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

1個source可以指定多個channels,而1個sink只能接收來自1個channel的數(shù)據(jù)。

3.啟動agent

flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/example.conf \
-Dflume.root.logger=INFO,console

4.另開窗口,使用telnet進行測試: telnet hadoop 44444
5.輸入測試文字,在flume-ng agent啟動窗口看到telnet窗口輸入的文字,以Event形式顯示:
Event: { headers:{} body: 68 65 6C 6C 6F 0D hello. }
EventFLume數(shù)據(jù)傳輸?shù)幕締卧?br> Event = 可選的header + byte array

  • 監(jiān)控一個文件實時采集增量數(shù)據(jù)輸出到控制臺

1.首先新增exec-memory-logger.conf配置:

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command=tail -f /home/feiyue/data/flume-data.log
a1.sources.r1.shell=/bin/sh -c

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
a1.channels.c1.type = memory

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

2.啟動agent

flume-ng agent \
--name a1 \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/exec-memory-logger.conf \
-Dflume.root.logger=INFO,console

3.新開窗口echo hello >> flume-data.log,在flume-ng agent窗口看到監(jiān)視的日志文件內(nèi)容。

  • 監(jiān)控一個文件實時采集增量數(shù)據(jù)輸出到HDFS

與上面的做法類似,只是配置信息有些變化:

type    –   The component type name, needs to be hdfs
hdfs.path   –   HDFS directory path (eg hdfs://namenode/flume/webdata/)
  • 服務(wù)器A(Web APP)上的日志實時采集到服務(wù)器B(HDFS)上

1.技術(shù)選型:

日志服務(wù)器A:exec source + memory channel + avro sink
HDFS服務(wù)器B:avro source + memory channel + logger sink

跨節(jié)點以 avro文件形式傳輸較為普遍。

跨節(jié)點

2.新增配置文件exec-memory-avro.conf并修改內(nèi)容

exec-memory-avro.sources = exec-source
exec-memory-avro.sinks = avro-sink
exec-memory-avro.channels = memory-channel

exec-memory-avro.sources.exec-source.type = exec
exec-memory-avro.sources.exec-source.command = tail -F /home/hadoop/data/data.log
exec-memory-avro.sources.exec-source.shell = /bin/sh -c

exec-memory-avro.sinks.avro-sink.type = avro

# send to the configured hostname/port pair
exec-memory-avro.sinks.avro-sink.hostname = 192.168.199.151
exec-memory-avro.sinks.avro-sink.port = 44444

exec-memory-avro.channels.memory-channel.type = memory

exec-memory-avro.sources.exec-source.channels = memory-channel
exec-memory-avro.sinks.avro-sink.channel = memory-channel

3.新增配置文件avro-memory-logger.conf并修改內(nèi)容

avro-memory-logger.sources = avro-source
avro-memory-logger.sinks = logger-sink
avro-memory-logger.channels = memory-channel

avro-memory-logger.sources.avro-source.type = avro

# Listens on Avro IP and port 
avro-memory-logger.sources.avro-source.bind = 192.168.199.151  
avro-memory-logger.sources.avro-source.port = 44444

avro-memory-logger.sinks.logger-sink.type = logger

avro-memory-logger.channels.memory-channel.type = memory

avro-memory-logger.sources.avro-source.channels = memory-channel
avro-memory-logger.sinks.logger-sink.channel = memory-channel

4.先啟動avro-memory-logger,注意順序

flume-ng agent \
--name avro-memory-logger \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/avro-memory-logger.conf \
-Dflume.root.logger=INFO,console

5.再啟動exec-memory-avro,注意順序

flume-ng agent \
--name exec-memory-avro \
--conf $FLUME_HOME/conf \
--conf-file $FLUME_HOME/conf/exec-memory-avro.conf \
-Dflume.root.logger=INFO,console

6.在服務(wù)器A上開啟一個窗口,人工模擬往日志文件里輸入內(nèi)容

?  echo ccccc >> flume-data.log
?  echo 123456789 >> flume-data.log

7.在服務(wù)器B的flume-ng agent窗口將會看到Event形式的內(nèi)容輸出,可能略有延遲(內(nèi)存緩存有關(guān))

參考:

http://archive.cloudera.com/cdh5/cdh/5/flume-ng-1.6.0-cdh5.7.0/FlumeUserGuide.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Flume是一個分布式的、高可靠的、高可用的用于高效收集、聚合、移動大量日志數(shù)據(jù)的框架(Flume is a di...
    Sx_Ren閱讀 3,778評論 0 1
  • Flume的功能和架構(gòu)特點 ** 功能 **flume 是一個分布式的,可靠的,可用的,可以非常有效率的對大數(shù)據(jù)的...
    心_的方向閱讀 2,533評論 1 10
  • 博客原文 翻譯作品,水平有限,如有錯誤,煩請留言指正。原文請見 官網(wǎng)英文文檔 引言 概述 Apache Flume...
    rabbitGYK閱讀 11,532評論 13 34
  • 有的人用膠片定格一瞬的美好; 有的人用畫筆描繪奇思的妙想; 有的人用音符澎湃動人的節(jié)奏; 有的人用奔跑記錄生命的活...
    先生z閱讀 131評論 0 1
  • 上一章:我愿意為你再等一個七年 第一章 十點! 今天的夜像是一泓清水那般平靜,隔壁的貓叫聲奇跡地消失不見。春天的夜...
    第七感XL閱讀 294評論 0 0