文章目錄
一、Flume概述
1.1 Flume定義
Flume
是Cloudera
提供的一個高可用的,高可靠的,分佈式的海量日誌採集、聚合和傳輸的系統。Flume
基於流式架構,靈活簡單。
Flume
最主要的作用就是,實時讀取服務器本地磁盤的數據,將數據寫入到HDFS
。
1.2 Flume的優點
- 可以和任意存儲進程集成
- 輸入的的數據速率大於寫入目的存儲的速率,
Flume
會進行緩衝,減小HDFS
的壓力。 Flume
中的事務基於Channel
,使用了兩個事務模型(sender
+receiver
),確保消息被可靠發送。
Flume
使用兩個獨立的事務分別負責從soucrce
到channel
,以及從channel
到sink
的事件傳遞。一旦事務中所有的數據全部成功提交到channel
,那麼source
才認爲該數據讀取完成。同理,只有成功被sink
寫出去的數據,纔會從channel
中移除。
1.3 Flume組成架構
Put事務流程:
doPut
:將批數據先寫入臨時緩衝區putList
doCommit
:檢查channel
內存隊列是否足夠合併。doRollback
:channel
內存隊列空間不足,回滾數據
Take事務:
doTake
:先將數據取到臨時緩衝區takeList
doCommit
:如果數據全部發送成功,則清除臨時緩衝區takeList
doRollback
:數據發送過程中如果出現異常,rollback
將臨時緩衝區takeList
中的數據歸還給channel
內存隊列。
下面我們來詳細介紹一下Flume
架構中的組件。
①Agent
Agent
是一個JVM
進程,它以事件的形式將數據從源頭送至目的。
Agent
主要有3個部分組成:Source
、Channel
、Sink
。
②Source
Source
是負責接收數據到Flume Agent
的組件。Source
組件可以處理各種類型、各種格式的日誌數據,包括avro
、thrift
、exec
、jms
、spooling directory
、netcat
、sequence generator
、syslog
、http
、legacy
。
③Channel
Channel
是位於Source
和Sink
之間的緩衝區。因此,Channel
允許Source
和Sink
運作在不同的速率上。Channel
是線程安全的,可以同時處理幾個Source
的寫入操作和幾個Sink
的讀取操作。
Flume
自帶兩種Channel
:Memory Channel
和File Channel
。
Memory Channel
:內存中的隊列。Memory Channel
在不需要關心數據丟失的情景下適用。如果需要關心數據丟失,那麼Memory Channel
就不應該使用,因爲程序死亡、機器宕機或者重啓都會導致數據丟失。
File Channel
:將所有事件寫到磁盤。因此在程序關閉或機器宕機的情況下不會丟失數據。
④Sink
Sink
不斷地輪詢Channel
中的事件且批量地移除它們,並將這些事件批量寫入到存儲或索引系統、或者被髮送到另一個Flume Agent
。
Sink
是完全事務性的。在從Channel
批量刪除數據之前,每個Sink
用Channel
啓動一個事務。批量事件一旦成功寫出到存儲系統或下一個Flume Agent
,Sink
就利用Channel
提交事務。事務一旦被提交,該Channel
從自己的內部緩衝區刪除事件。
Sink
組件目的地包括hdfs
、logger
、avro
、thrift
、ipc
、file
、null
、HBase
、solr
、自定義
⑤Event
Flume
數據傳輸的基本單元,以事件的形式將數據從源頭送至目的地。Event
由可選的header
和載有數據的一個byte array
構成。Header
是容納了key-value
字符串對的HashMap
。
1.4 Flume拓撲結構
①Flume Agent連接
這種模式是將多個Flume
給順序連接起來了,從最初的Source
開始到最終Sink
傳送的目的存儲系統。此模式不建議橋接過多的Flume
數量,Flume
數量過多不僅會影響傳輸速率,而且一旦傳輸過程中某個節點Flume
宕機,會影響整個傳輸系統。
②單source,多channel、sink
Flume
支持將事件流向一個或者多個目的地。這種模式將數據源複製到多個Channel
中,每個Channel
都有相同的數據,Sink
可以選擇傳送的不同的目的地。
③Flume負載均衡
Flume
支持使用將多個Sink
邏輯上分到一個Sink
組,Flume
將數據發送到不同的Sink
,主要解決負載均衡和故障轉移問題。
④ Flume Agent聚合
這種模式是我們最常見的,也非常實用,日常web
應用通常分佈在上百個服務器,大者甚至上千個、上萬個服務器。產生的日誌,處理起來也非常麻煩。用Flume
的這種組合方式能很好的解決這一問題,每臺服務器部署一個Flume
採集日誌,傳送到一個集中收集日誌的Flume
,再由此Flume
上傳到hdfs
、hive
、hbase
、jms
等,進行日誌分析。
1.5 Flume Agent內部原理
1.6 Flume安裝
- 解壓
apache-flume-1.7.0-bin.tar.gz
到/opt/module/
目錄下
[root@hadoop100 software]$ tar -zxf apache-flume-1.7.0-bin.tar.gz -C
/opt/module/
2.複製conf
下的flume-env.sh.template
爲flume-env.sh
,並配置JAVA_HOME
[root@hadoop100 conf]$ mv flume-env.sh.template flume-env.sh
[root@hadoop100 conf]$ vi flume-env.sh
export JAVA_HOME=/opt/module/jdk1.8.0_144
二、企業開發案例
2.1 監控端口數據
案例需求: 首先啓動Flume
任務,監控本機44444端口,服務端;然後通過netcat
工具向本機44444端口發送消息,客戶端;最後Flume
將監聽的數據實時顯示在控制檯。
實現步驟:
① 創建Flume Agent
配置文件flume-netcat-logger.conf
- 在
Flume
目錄下創建Job
文件夾並進入Job
文件夾
[root@hadoop100 flume]# mkdir job
[root@hadoop100 flume]# cd job/
- 創建
Flume Agent
配置文件flume-netcat-logger.conf
[root@hadoop100 flume]# vim flume-netcat-logger.conf
# Name the components on this agent
# a1 :表示agent的名稱
a1.sources = r1 #r1 :表示a1的輸入源
a1.sinks = k1 #k1 :表示a1的輸出目的地
a1.channels = c1 #c1:表示a1的緩衝區
# Describe/configure the source
a1.sources.r1.type = netcat #表示a1的輸入源類型爲netcat端口類型
a1.sources.r1.bind = localhost #表示a1的監聽的主機
a1.sources.r1.port = 44444 #表示a1的監聽的端口號
# Describe the sink
a1.sinks.k1.type = logger #表示a1的輸出目的地是控制檯logger類型
# Use a channel which buffers events in memory
a1.channels.c1.type = memory #表示a1的channel類型是memory內存型
a1.channels.c1.capacity = 1000 #表示al的channel總容量1000個event
#表示a1的channel傳輸時收集到了100條event以後再去提交事務
a1.channels.c1.transactionCapacity = 100
# Bind the source and sink to the channel
a1.sources.r1.channels = c1 #表示將r1和c1連接起來
a1.sinks.k1.channel = c1 # 表示將k1和c1連接起來
②開啓Flume監聽端口
第一種寫法:
[root@hadoop100 flume]# bin/flume-ng agent --conf conf/ --name a1
--conf-file job/flume-netcat-logger.conf -Dflume.root.logger=INFO,console
第二種寫法:
[root@hadoop100 flume]$ bin/flume-ng agent -c conf/ -n a1 –f
job/flume-netcat-logger.conf -Dflume.root.logger=INFO,console
參數說明:
--conf conf/
:表示配置文件存儲在conf/
目錄--name a1
:表示給agent
起名爲a1
--conf-file job/flume-netcat.conf
:flume
本次啓動讀取的配置文件是在job
文件夾下的flume-telnet.conf
文件。-Dflume.root.logger==INFO,console
:-D
表示flume
運行時動態修改flume.root.logger
參數屬性值,並將控制檯日誌打印級別設置爲INFO
級別。日誌級別包括:log
、info
、warn
、error
。
③ 使用netcat工具向44444端口發送內容
[root@hadoop100 flume]$ nc localhost 44444
Hello Flume
④在Flume監聽頁面觀察接收數據情況
2.2 實時讀取本地文件到HDFS
案例需求: 實時監控Hive
日誌,並上傳到HDFS
中
實現步驟:
①Flume要想將數據輸出到HDFS,必須持有Hadoop相關jar包
將commons-configuration-1.6.jar
、hadoop-auth-2.7.2.jar
、hadoop-common-2.7.2.jar
、hadoop-hdfs-2.7.2.jar
、commons-io-2.4.jar
、htrace-core-3.1.0-incubating.jar
拷貝到/opt/module/flume/lib
文件夾下。
②創建flume-file-hdfs.conf文件
內容如下:
# Name the components on this agent
a2.sources = r2
a2.sinks = k2
a2.channels = c2
# Describe/configure the source
a2.sources.r2.type = exec
a2.sources.r2.command = tail -F /opt/module/hive-1.2.1/logs/hive.log
a2.sources.r2.shell = /bin/bash -c
# Describe the sink
a2.sinks.k2.type = hdfs
a2.sinks.k2.hdfs.path = hdfs://hadoop100:9000/flume/%Y%m%d/%H
#上傳文件的前綴
a2.sinks.k2.hdfs.filePrefix = logs-
#是否按照時間滾動文件夾
a2.sinks.k2.hdfs.round = true
#多少時間單位創建一個新的文件夾
a2.sinks.k2.hdfs.roundValue = 1
#重新定義時間單位
a2.sinks.k2.hdfs.roundUnit = hour
#是否使用本地時間戳
a2.sinks.k2.hdfs.useLocalTimeStamp = true
#積攢多少個Event才flush到HDFS一次
a2.sinks.k2.hdfs.batchSize = 1000
#設置文件類型,可支持壓縮
a2.sinks.k2.hdfs.fileType = DataStream
#多久生成一個新的文件
a2.sinks.k2.hdfs.rollInterval = 60
#設置每個文件的滾動大小
a2.sinks.k2.hdfs.rollSize = 134217700
#文件的滾動與Event數量無關
a2.sinks.k2.hdfs.rollCount = 0
# Use a channel which buffers events in memory
a2.channels.c2.type = memory
a2.channels.c2.capacity = 1000
a2.channels.c2.transactionCapacity = 100
# Bind the source and sink to the channel
a2.sources.r2.channels = c2
a2.sinks.k2.channel = c2
注意:對於所有與時間相關的轉義序列,Event Header
中必須存在以"timestamp"
的key
(除非hdfs.useLocalTimeStamp
設置爲true
,此方法會使用TimestampInterceptor
自動添加timestamp
),即設置a3.sinks.k3.hdfs.useLocalTimeStamp = true
。
③ 執行監控配置
[root@hadoop100 flume]# bin/flume-ng agent --conf conf/ --name a2
--conf-file job/flume-file-hdfs.conf
④開啓Hadoop和Hive並操作Hive產生日誌
[root@hadoop100 hadoop-2.7.2]$ sbin/start-dfs.sh
[root@hadoop101 hadoop-2.7.2]$ sbin/start-yarn.sh
[root@hadoop100 hive]$ bin/hive
hive (default)>
⑤在HDFS上查看文件
2.3 實時讀取目錄文件到HDFS
案例需求: 使用Flume
監聽整個目錄的文件
實現步驟:
① 創建配置文件flume-dir-hdfs.conf
a3.sources = r3
a3.sinks = k3
a3.channels = c3
# Describe/configure the source
a3.sources.r3.type = spooldir
#監控的地址
a3.sources.r3.spoolDir = /opt/module/flume-1.7.0/upload
a3.sources.r3.fileSuffix = .COMPLETED
a3.sources.r3.fileHeader = true
#忽略所有以.tmp結尾的文件,不上傳
a3.sources.r3.ignorePattern = ([^ ]*\.tmp)
# Describe the sink
a3.sinks.k3.type = hdfs
#文件上傳到hdfs的路徑
a3.sinks.k3.hdfs.path = hdfs://hadoop100:9000/flume/upload/%Y%m%d/%H
#上傳文件的前綴
a3.sinks.k3.hdfs.filePrefix = upload-
#是否按照時間滾動文件夾
a3.sinks.k3.hdfs.round = true
#多少時間單位創建一個新的文件夾
a3.sinks.k3.hdfs.roundValue = 1
#重新定義時間單位
a3.sinks.k3.hdfs.roundUnit = hour
#是否使用本地時間戳
a3.sinks.k3.hdfs.useLocalTimeStamp = true
#積攢多少個Event才flush到HDFS一次
a3.sinks.k3.hdfs.batchSize = 100
#設置文件類型,可支持壓縮
a3.sinks.k3.hdfs.fileType = DataStream
#多久生成一個新的文件
a3.sinks.k3.hdfs.rollInterval = 60
#設置每個文件的滾動大小大概是128M
a3.sinks.k3.hdfs.rollSize = 134217700
#文件的滾動與Event數量無關
a3.sinks.k3.hdfs.rollCount = 0
# Use a channel which buffers events in memory
a3.channels.c3.type = memory
a3.channels.c3.capacity = 1000
a3.channels.c3.transactionCapacity = 100
# Bind the source and sink to the channel
a3.sources.r3.channels = c3
a3.sinks.k3.channel = c3
②啓動監控文件夾命令
[root@hadoop100 flume]$ bin/flume-ng agent --conf conf/ --name a3 --conf-file job/flume-dir-hdfs.conf
說明:
加粗樣式
- 不要在監控目錄中創建並持續修改文件
- 上傳完成的文件會以
.COMPLETED
結尾 - 被監控文件夾每500毫秒掃描一次文件變動
②向upload文件夾中添加文件
[root@hadoop100 flume]$ mkdir upload
[root@hadoop100 upload]$ vim test.txt
123
456
③查看HDFS上的數據
、
④查看upload文件夾
2.4 單數據源多出口案例(選擇器)
案例需求: 使用Flume-1
監控文件變動,Flume-1
將變動內容傳遞給Flume-2
,Flume-2
負責存儲到HDFS
。同時Flume-1
將變動內容傳遞給Flume-3
,Flume-3
負責輸出到Local FileSystem
。
實現步驟:
①準備工作
在/opt/module/flume/job
目錄下創建group1
文件夾:
[root@hadoop100 job]# mkdir group1/
在/opt/module/data/
目錄下創建flume3
文件夾
[root@hadoop100 data]# mkdir flume3
②創建flume-file-flume.conf
配置1個接收日誌文件的source
和兩個channel
、兩個sink
,分別輸送給flume-flume-hdfs
和flume-flume-dir
。
# 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 /opt/module/hive-1.2.1/logs/hive.log
a1.sources.r1.shell = /bin/bash -c
# Describe the sink
# sink端的avro是一個數據發送者
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = hadoop100
a1.sinks.k1.port = 4141
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = hadoop100
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
注:Avro
是由Hadoop
創始人Doug Cutting
創建的一種語言無關的數據序列化和RPC
框架。
③創建flume-flume-hdfs.conf
配置上級Flume
輸出的Source
,輸出是到HDFS
的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 /opt/module/hive-1.2.1/logs/hive.log
a1.sources.r1.shell = /bin/bash -c
# Describe the sink
# sink端的avro是一個數據發送者
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = hadoop100
a1.sinks.k1.port = 4141
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = hadoop100
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
[root@hadoop100 group1]#
[root@hadoop100 group1]# cat flume-flume-hdfs.conf
# Name the components on this agent
a2.sources = r1
a2.sinks = k1
a2.channels = c1
# Describe/configure the source
# source端的avro是一個數據接收服務
a2.sources.r1.type = avro
a2.sources.r1.bind = hadoop100
a2.sources.r1.port = 4141
# Describe the sink
a2.sinks.k1.type = hdfs
a2.sinks.k1.hdfs.path = hdfs://hadoop100: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
# 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
④創建flume-flume-dir.conf
配置上級Flume
輸出的Source
,輸出是到本地目錄的Sink
。
# Name the components on this agent
a3.sources = r1
a3.sinks = k1
a3.channels = c2
# Describe/configure the source
a3.sources.r1.type = avro
a3.sources.r1.bind = hadoop100
a3.sources.r1.port = 4142
# Describe the sink
a3.sinks.k1.type = file_roll
a3.sinks.k1.sink.directory = /opt/module/data/flume3
# Describe the channel
a3.channels.c2.type = memory
a3.channels.c2.capacity = 1000
a3.channels.c2.transactionCapacity = 100
# Bind the source and sink to the channel
a3.sources.r1.channels = c2
a3.sinks.k1.channel = c2
⑤執行配置文件
[root@hadoop100 flume-1.7.0]$ bin/flume-ng agent --conf conf/ --name a3
--conf-file job/group1/flume-flume-dir.conf
[root@hadoop100 flume-1.7.0]$ bin/flume-ng agent --conf conf/ --name a2
--conf-file job/group1/flume-flume-hdfs.conf
[root@hadoop100 flume-1.7.0]$ bin/flume-ng agent --conf conf/ --name a1
--conf-file job/group1/flume-file-flume.conf
⑥執行Hive
命令
[root@hadoop100 hive]$ bin/hive
hive (default)> select * from stu;
⑦檢查數據
HDFS
:
本地:
2.5 單數據源多出口案例(Sink組)
案例需求: 使用Flume-1
監控控制檯實時輸入數據,Flume-1
將內容輪訓分別傳遞給Flume-2
,Flume-3
然後在控制檯打印。
實現步驟:
①準備工作
在/opt/module/flume/job
下group2
文件夾
[root@hadoop100 job]# mkdir group2
②創建flume-netcat-flume.conf
配置1個接收日誌文件的source
和1個channel
、兩個sink
,分別輸送給flume-flume-console1
和flume-flume-console2
。
# Name the components on this agent
a1.sources = r1
a1.channels = c1
a1.sinkgroups = g1
a1.sinks = k1 k2
# Describe/configure the source
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444
a1.sinkgroups.g1.processor.type = load_balance
a1.sinkgroups.g1.processor.backoff = true
a1.sinkgroups.g1.processor.selector = round_robin
a1.sinkgroups.g1.processor.selector.maxTimeOut=10000
# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = hadoop100
a1.sinks.k1.port = 4141
a1.sinks.k2.type = avro
a1.sinks.k2.hostname = hadoop100
a1.sinks.k2.port = 4142
# Describe the channel
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.sinkgroups.g1.sinks = k1 k2
a1.sinks.k1.channel = c1
a1.sinks.k2.channel = c1
③創建flume-flume-console1.conf和flume-flume-console2.conf
配置上級Flume
輸出的Source
,輸出是到本地控制檯。
flume-flume-console1.conf
:
# 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 = hadoop100
a2.sources.r1.port = 4141
# Describe the sink
a2.sinks.k1.type = logger
# 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
flume-flume-console2.conf
:
# Name the components on this agent
a3.sources = r1
a3.sinks = k1
a3.channels = c2
# Describe/configure the source
a3.sources.r1.type = avro
a3.sources.r1.bind = hadoop100
a3.sources.r1.port = 4142
# Describe the sink
a3.sinks.k1.type = logger
# Describe the channel
a3.channels.c2.type = memory
a3.channels.c2.capacity = 1000
a3.channels.c2.transactionCapacity = 100
# Bind the source and sink to the channel
a3.sources.r1.channels = c2
a3.sinks.k1.channel = c2
④執行配置文件
[root@hadoop100 flume-1.7.0]# bin/flume-ng agent --conf conf/ --name a3
--conf-file job/group2/flume-flume-console2.conf
-Dflume.root.logger=INFO,console
[root@hadoop100 flume-1.7.0]# bin/flume-ng agent --conf conf/ --name a2
--conf-file job/group2/flume-flume-console1.conf
-Dflume.root.logger=INFO,console
[root@hadoop100 flume-1.7.0]# bin/flume-ng agent --conf conf/ --name a1
--conf-file job/group2/flume-netcat-flume.conf
⑤查看Flume2及Flume3的控制檯打印日誌
2.6 多數據源彙總案例
案例需求:
Hadoop100
上的Flume-1
監控文件/opt/module/group.log
;
Hadoop101
上的Flume-2
監控某一個端口的數據流;
Flume-1
與Flume-2
將數據發送給hadoop102
上的Flume-3
,Flume-3
將最終數據打印到控制檯。
實現步驟:
①準備工作
在/opt/module/flume/job
下group3
文件夾
[root@hadoop100 job]# mkdir group3
②創建flume1-logger-flume.conf
Hadoop100
:配置Source
用於監控hive.log
文件,配置Sink
輸出數據到下一級Flume
。
# 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 /opt/module/hive-1.2.1/logs/hive.log
a1.sources.r1.shell = /bin/bash -c
# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = hadoop102
a1.sinks.k1.port = 4141
# Describe the channel
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
③創建flume2-netcat-flume.conf
Hadoop101
:配置Source
監控端口44444數據流,配置Sink
數據到下一級Flume
。
# Name the components on this agent
a2.sources = r1
a2.sinks = k1
a2.channels = c1
# Describe/configure the source
a2.sources.r1.type = netcat
a2.sources.r1.bind = hadoop101
a2.sources.r1.port = 44444
# Describe the sink
a2.sinks.k1.type = avro
a2.sinks.k1.hostname = hadoop102
a2.sinks.k1.port = 4141
# Use a channel which buffers events in memory
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
④創建flume3-flume-logger.conf
Hadoop102
:配置source
用於接收flume1
與flume2
發送過來的數據流,最終合併後sink
到控制檯。
# 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 = hadoop102
a3.sources.r1.port = 4141
# Describe the sink
# Describe the sink
a3.sinks.k1.type = logger
# 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
⑤執行配置文件
[root@hadoop102 flume-1.7.0]# bin/flume-ng agent --conf conf/ --name a3
--conf-file job/group3/flume3-flume-logger.conf
-Dflume.root.logger=INFO,console
[root@hadoop101 flume-1.7.0]# bin/flume-ng agent --conf conf/ --name a2
--conf-file job/group3/flume2-netcat-flume.conf
[root@hadoop100 flume-1.7.0]# bin/flume-ng agent --conf conf/ --name a1
--conf-file job/group3/flume1-logger-flume.conf