天天看點

Flume介紹、架構、安裝、及案例1、2、3

概述

日志采集工具----可靠性機制、故障轉移和恢複機制,容錯能力。可擴充資料模型,允許線上分析應用程式。

為什麼需要flume?

資料從哪裡來?

-》爬蟲

-》日志資料 flume

—》傳統型資料庫 sqoop

flume架構

source:資料源

産生資料流,同時source将産生的資料流傳輸到channel

channel:傳輸通道

用于橋接source和sinks

sinks:槽

從channel端收集資料

event:傳輸單元

Flume資料傳輸的基本單元,以事件的形式将資料送往目的地。

flume安裝

mv flume-env.sh.template flume-env.sh

export JAVA_HOME=

案例1–監聽端口

a1.sources = r1

a1.sinks = k1

a1.channels = c1

a1.sources.r1.type = netcat
a1.sources.r1.bind = bigdata
a1.sources.r1.port = 44444

a1.sinks.k1.type = logger

a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

bin/flume-ng agent --conf conf/ --name a1 --conf-file conf/text.conf -Dflume.root.logger==INFO,console

telnet bigdata 44444
           

案例2–監聽檔案

a1.sources = r1

a1.sinks = k1

a1.channels = c1

#exec執行一個指令的方式去檢視檔案 tail -F實時檢視
a1.sources.r1.type = exec
#要執行的腳本commond tail -F 預設10行 man tail 檢視幫助
a1.sources.r1.command = tail -F /root/logs/test.log
#執行這個command使用的是那個腳本 -C 制定使用什麼指令
#whereis bash,執行指令檢視bash的位址
a1.sources.r1.shell = /usr/bin/bash -c

a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://bigdata:9000/flume/%Y%m%d/%H
#上傳檔案的字首
a1.sinks.k1.hdfs.filePrefix = logs-
#是否按照時間滾動檔案夾
a1.sinks.k1.hdfs.round = true
#多少時間機關建立一個新的檔案夾 秒 (預設30s)
a1.sinks.k1.hdfs.roundValue = 1
#重新定義事件機關(每分鐘滾動一個檔案夾)
a1.sinks.k1.hdfs.roundUnit = minute
#是否使用本地時間戳
a1.sinks.k1.hdfs.useLoaclTimeStamp = true
#積攢多少個Event才flush到HDFS一次
a1.sinks.k1.hdfs.batchSize = 1000
#設定檔案類型,可支援壓縮
a1.sinks.k1.hdfs.fileType = DataStream
#多久生成一個新的檔案 秒
a1.sinks.k1.hdfs.rollInterval = 30
#設定每個檔案的滾動大小 位元組(最好128M)
a1.sinks.k1.hdfs.rollSize = 13421770
#檔案的滾動與Event數量圍觀
a1.sinks.k1.hdfs.rollCount = 0
#最小備援數(備份數,生成滾動功能則生效roll hadoop本身有此功能 無需配置) 1份 不用設定,
a1.sinks.k1.hdfs.minBlockReplicas = 1


a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
           

案例3–監聽檔案夾

# 定義

a1.sources = r1

a1.sinks = k1

a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = spooldir
# 監控的檔案夾
a1.sources.r1.spoolDir = /root/spooldir
# 上傳成功後顯示字尾名 
a1.sources.r1.fileSuffix = .COMPLETED
# 如論如何 加絕對路徑的檔案名 預設false
a1.sources.r1.fileHeader = true

#忽略所有以.tmp 結尾的檔案(正在被寫入),不上傳
# ^以任何開頭 出現無限次 以.tmp結尾的
a1.sources.r1.ignorePattern = ([^ ]*\.tmp)

# Describe the sink 
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://bigdata:9000/flume/spooldir/%Y%m%d/%H
#上傳檔案的字首
a1.sinks.k1.hdfs.filePrefix = spooldir-
#是否按照時間滾動檔案夾
a1.sinks.k1.hdfs.round = true
#多少時間機關建立一個新的檔案夾
a1.sinks.k1.hdfs.roundValue = 1
#重新定義時間機關
a1.sinks.k1.hdfs.roundUnit = hour
#是否使用本地時間戳
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#積攢多少個 Event 才 flush 到 HDFS 一次
a1.sinks.k1.hdfs.batchSize = 50

#設定檔案類型,可支援壓縮
a1.sinks.k1.hdfs.fileType = DataStream
#多久生成一個新的檔案
a1.sinks.k1.hdfs.rollInterval = 600
#設定每個檔案的滾動大小大概是 128M 
a1.sinks.k1.hdfs.rollSize = 134217700
#檔案的滾動與 Event 數量無關
a1.sinks.k1.hdfs.rollCount = 0
#最小副本數
a1.sinks.k1.hdfs.minBlockReplicas = 1

# 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
           

案例4----多channels,多sinks

需求:監控hive.log檔案,同時産生兩個Channel,一個channel對應的sink存儲到hdfs中,另外一個channel對應的sink存儲到本地中

# name the components on this agent 
a1.sources = r1
a1.sinks = k1 k2 
a1.channels = c1 c2
# 将資料流複制給多個 channel
a1.sources.r1.selector.type = replicating

# Describe/configure the source 
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /tmp/root/hive.log
a1.sources.r1.shell = /bin/bash -c


# Describe the sink
# 分兩個端口發送資料 
a1.sinks.k1.type = avro 
a1.sinks.k1.hostname = hd09-01 
a1.sinks.k1.port = 4141

a1.sinks.k2.type = avro 
a1.sinks.k2.hostname = hd09-01 
a1.sinks.k2.port = 4142

# Describe the channel 
a1.channels.c1.type = memory 
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

a1.channels.c2.type = memory 
a1.channels.c2.capacity = 1000
a1.channels.c2.transactionCapacity = 100

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


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

# Describe/configure the source
a2.sources.r1.type = avro 
# 端口抓取資料
a2.sources.r1.bind = hd09-01
a2.sources.r1.port = 4141

# Describe the sink 
a2.sinks.k1.type = hdfs
a2.sinks.k1.hdfs.path = hdfs://hd09-01:9000/flume2/%Y%m%d/%H

#上傳檔案的字首
a2.sinks.k1.hdfs.filePrefix = flume2-
#是否按照時間滾動檔案夾
a2.sinks.k1.hdfs.round = true
#多少時間機關建立一個新的檔案夾
a2.sinks.k1.hdfs.roundValue = 1
#重新定義時間機關
a2.sinks.k1.hdfs.roundUnit = hour
#是否使用本地時間戳
a2.sinks.k1.hdfs.useLocalTimeStamp = true
#積攢多少個 Event 才 flush 到 HDFS 一次
a2.sinks.k1.hdfs.batchSize = 100

#設定檔案類型,可支援壓縮
a2.sinks.k1.hdfs.fileType = DataStream
#多久生成一個新的檔案
a2.sinks.k1.hdfs.rollInterval = 600
#設定每個檔案的滾動大小大概是 128M 
a2.sinks.k1.hdfs.rollSize = 134217700
#檔案的滾動與 Event 數量無關
a2.sinks.k1.hdfs.rollCount = 0
#最小副本數
a2.sinks.k1.hdfs.minBlockReplicas = 1

# Describe the channel 
a2.channels.c1.type = memory 
a2.channels.c1.capacity = 1000
a2.channels.c1.transactionCapacity = 100

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




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

# Describe/configure the source 
a3.sources.r1.type = avro
a3.sources.r1.bind = hd09-01
a3.sources.r1.port = 4142

# Describe the sink 
a3.sinks.k1.type = file_roll
a3.sinks.k1.sink.directory = /root/flume2

# Describe the channel 
a3.channels.c1.type = memory 
a3.channels.c1.capacity = 1000
a3.channels.c1.transactionCapacity = 100


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

繼續閱讀