協(xié)作框架之Flume
1.概念
Flume
Cloudera 公司開源的框架
高效的收集海量日志文件
官網(wǎng)
應(yīng)用場(chǎng)合
日志來(lái)源于apache/Nginx 應(yīng)用服務(wù)器的日志 --> HDFS
Flume+kafka ---> Storm /Spark Streaming
2.簡(jiǎn)單架構(gòu)(配置)
Agent --> 每臺(tái)應(yīng)用服務(wù)器日志的機(jī)器 運(yùn)行一個(gè)agent
source/channel/sink
source 應(yīng)用服務(wù)器的日志目錄或文件,數(shù)據(jù)源
channel source主動(dòng)將數(shù)據(jù)pash到管道中,內(nèi)存和磁盤
安全性,可靠性,借助管道寫道本地磁盤
sink: 寫到HDFS
Event是數(shù)據(jù)傳輸?shù)幕締卧? Flume以事件的形式將數(shù)據(jù)從源頭傳送到最終目的地
Event由可選的header和載有數(shù)據(jù)的一個(gè)byte array構(gòu)成
載有的數(shù)據(jù)flume是不透明的
Header是容納了key-value字符串對(duì)的無(wú)序集合,key在集合內(nèi)是唯一的。
Header可以在上下文路由中使用擴(kuò)展
企業(yè)中應(yīng)用時(shí),日志按日期生成,可以將服務(wù)器的時(shí)間放到頭里,數(shù)據(jù)真正放到byte array中
3. Flume的特點(diǎn)
3.1復(fù)雜流動(dòng)性
Flume允許用戶進(jìn)行多級(jí)流動(dòng)到最終目的地,也允許扇出流(一到多)、扇入流(多到一)的、故障轉(zhuǎn)移和失敗處理。fan-in fan-out
3.2可靠性
事務(wù)性的數(shù)據(jù)傳遞,保證了數(shù)據(jù)的可靠性。
3.3 可恢復(fù)性
通道可以以內(nèi)存或文件的方式實(shí)現(xiàn),內(nèi)存更快,但是不可恢復(fù),而文件雖然比較慢但提供了可恢復(fù)性。
*運(yùn)行在有日志的地方
*系統(tǒng):linux
*JVM/JDK
*輕量級(jí)的服務(wù)(e.g.:zk jn zkfc sqoop對(duì)硬件要求不是很高)
4.Flume的安裝和部署
下載上傳 cdh版本
1).解壓
$ tar -zxf flume-ng-1.5.0-cdh5.3.6.tar.gz -C /opt/modules/cdh/
2).配置${FLUME_HOME}/conf/
$ cp flume-env.sh.template flume-env.sh
修改flume-env.sh
3).拷貝HDFS依賴及配置的jar包到${FLUME_HOME}/lib
${HADOOP_HOME}/
$ cp share/hadoop/common/hadoop-common-2.5.0-cdh5.3.6.jar share/hadoop/common/lib/commons-configuration-1.6.jar share/hadoop/common/lib/hadoop-auth-2.5.0-cdh5.3.6.jar share/hadoop/hdfs/hadoop-hdfs-2.5.0-cdh5.3.6.jar /opt/modules/cdh/flume-1.5.0-cdh5.3.6/lib/
4).拷貝HDFS相關(guān)的配置文件到flume的conf
${HADOOP_HOME}/etc/hadoop --> ${FLUME_HOME}/conf
$ cp etc/hadoop/core-site.xml etc/hadoop/hdfs-site.xml /opt/modules/cdh/flume-1.5.0-cdh5.3.6/conf/
[案例一: source:telnet sink:生成日志文件,直接打印到控制臺(tái)]
1.生成agent模板
$ cp flume-conf.properties.template flume-conf.properties
$ cp flume-conf.properties a1.conf
2.編輯agent配置文件(source channel sink)
# Name the components on this agent
#a1指的是Agent的name,需要與啟動(dòng)agent的--name相對(duì)應(yīng)
a1.sources = r1 #當(dāng)前agent的sources名稱
a1.sinks = k1 #當(dāng)前agent的sinks名稱
a1.channels = c1 #當(dāng)前agent的channels名稱
# Describe/configure the source
a1.sources.r1.type = netcat #sources的類型
a1.sources.r1.bind = bigdata.ibeifeng.com #綁定的主機(jī)
a1.sources.r1.port = 44444 #監(jiān)聽的端口
# Describe the sink
a1.sinks.k1.type = logger #輸出到日志
# Use a channel which buffers events in memory
a1.channels.c1.type = memory #緩沖到內(nèi)存中
a1.channels.c1.capacity = 1000 #存儲(chǔ)到channels中的events的最大數(shù)據(jù)
a1.channels.c1.transactionCapacity = 100 數(shù)量##每次event在chnnel傳輸?shù)淖畲蟮?
# Bind the source and sink to the channel 將對(duì)應(yīng)的source和sink綁定到channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
3.yum 安裝 telnet
# yum -y install telnet
4.啟動(dòng)agent ${FLUME_HOME}/
$ bin/flume-ng agent --conf conf --conf-file conf/a1.conf --name a1 -Dflume.root.logger=INFO,console
--conf 指定配置文件所在目錄
--name 指定agent的名稱,與a1.conf文件指定的一致
--conf-file 指定agent配置文件名稱
-Dflume.root.logger=INFO,console 日志輸出到console
Event: { headers:{} body: 48 65 6C 6C 6F 20 77 6F 72 6C 64 21 0D Hello world!. }
5.啟動(dòng)telnet
$ telnet bigdata.ibeifeng.com 44444
【退出telnet】
Ctrl+]
telnet>quit
Connection closed.
6.停止agent
${FLUME_HOME}
Ctrl+c 退出flume agent同時(shí)也就退出了telnet
[案例二:flume抽取日志文件]
source: 類型exec
tail -f
channel:memchannel
sink:HDFS
//使用agent a1 作為模板生成a2 agent 的配置文件
${FLUME_HOME}/conf
$ cp a1.conf a2.conf
1.配置a2.conf
=================修改a2.conf
#a2:agent name
a2.sources = r2
a2.channels = c2
a2.sinks = k2
# define sources
#主動(dòng)獲取日志
a2.sources.r2.type = exec
#獲取日志的命令(注意要有權(quán)限)
a2.sources.r2.command = tail -F /var/log/httpd/access_log
#上一行命令所運(yùn)行的環(huán)境
a2.sources.r2.shell = /bin/bash -c
# define channels
a2.channels.c2.type = memory
a2.channels.c2.capacity = 1000
a2.channels.c2.transactionCapacity = 100
# define sinks
#目標(biāo)上傳到hdfs
a2.sinks.k2.type = hdfs
a2.sinks.k2.hdfs.path=hdfs://[hostname]:8020/flume/%Y%m%d/%H
a2.sinks.k2.hdfs.filePrefix = accesslog
#啟用按時(shí)間生成文件夾
a2.sinks.k2.hdfs.round=true
#設(shè)置roundValue:1,round單位:小時(shí)
a2.sinks.k2.hdfs.roundValue=1
a2.sinks.k2.hdfs.roundUnit=hour
#使用本地時(shí)間戳(這個(gè)必須設(shè)置不然會(huì)報(bào)錯(cuò))
a2.sinks.k2.hdfs.useLocalTimeStamp=true
#多少個(gè)events會(huì)flush to hdfs
a2.sinks.k2.hdfs.batchSize=1000
# File format: 默認(rèn)是SequenceFile(key:value對(duì)),DataStream是無(wú)壓縮的一般數(shù)據(jù)流
a2.sinks.k2.hdfs.fileType=DataStream
#序列化的格式Text
a2.sinks.k2.hdfs.writeFormat=Text
#設(shè)置解決文件過(guò)多、過(guò)小問題
#每600秒生成一個(gè)文件
a2.sinks.k2.hdfs.rollInterval=60
#當(dāng)達(dá)到128000000bytes時(shí),創(chuàng)建新文件 127*1024*1024(in bytes)
#實(shí)際環(huán)境中如果按照128M回滾文件,那么這里設(shè)置一般設(shè)置成127M
a2.sinks.k2.hdfs.rollSize=128000000
#設(shè)置文件的生成不和events數(shù)相關(guān)
a2.sinks.k2.hdfs.rollCount=0
#設(shè)置成1,否則當(dāng)有副本復(fù)制時(shí)就重新生成文件,上面三條則沒有效果
a2.sinks.k2.hdfs.minBlockReplicas=1
# bind the sources and sinks to the channels
a2.sources.r2.channels = c2
a2.sinks.k2.channel = c2
===================================
2.安裝Apache HTTP服務(wù)器程序用于生成網(wǎng)站日志文件
2.1 安裝Apache HTTP
# yum -y install httpd
2.2 啟動(dòng)httpd服務(wù)
# service httpd start
2.3 編輯一個(gè)靜態(tài)的html的頁(yè)面
# vi /var/www/html/index.html
this is a test html
2.4 瀏覽器輸入主機(jī)名訪問這個(gè)頁(yè)面
bigdata.ibeifeng.com
2.5 實(shí)時(shí)監(jiān)控httpd日志
# chmod -R 777 /var/log/httpd
$ tail -f /var/log/httpd/access_log
3.啟動(dòng)hadoop
$ sbin/start-dfs.sh
4.啟動(dòng)Flume-agent a2
$ bin/flume-ng agent --conf conf --conf-file conf/a2.conf --name a2 -Dflume.root.logger=INFO,console
5.刷新靜態(tài)頁(yè)面,觀察HDFS是否生成指定的目錄和文件
[案例三:flume抽取目錄]
source: 類型spooldir
channel:memchannel
sink:HDFS
//使用agent a2 作為模板生成a3 agent 的配置文件
${FLUME_HOME}/conf
$ cp a2.conf a3.conf
1.配置a3.conf
=================修改a3.conf
a3.sources = r3
a3.sinks = k3
a3.channels = c3
# Describe/configure the source
# 源是某個(gè)目錄使用spooldir
a3.sources.r3.type = spooldir
# 抽取的目錄
a3.sources.r3.spoolDir = /opt/modules/cdh/hadoop-2.5.0-cdh5.3.6/logs
# 抽取該目錄下符合包含.log結(jié)尾的文件
a3.sources.r3.includePattern = ^.log$
# Use a channel which buffers events in file
# 設(shè)置channel類型是file
a3.channels.c3.type = file
# 設(shè)置檢查點(diǎn)目錄,記錄已經(jīng)獲取哪些文件,一些元數(shù)據(jù)信息
a3.channels.c3.checkpointDir = /opt/modules/cdh/flume-1.5.0-cdh5.3.6/checkpoint
#設(shè)置緩存的數(shù)據(jù)存儲(chǔ)目錄
a3.channels.c3.dataDirs = /opt/modules/cdh/flume-1.5.0-cdh5.3.6/bufferdata
# Describe the sink
a3.sinks.k3.type = hdfs
# 啟用設(shè)置多級(jí)目錄,這里按年/月/日/時(shí) 2級(jí)目錄,每個(gè)小時(shí)生成一個(gè)文件夾
a3.sinks.k3.hdfs.path = hdfs://bigdata.ibeifeng.com:8020/flume2/%Y%m%d/%H
# 設(shè)置HDFS生成文件的的前綴
a3.sinks.k3.hdfs.filePrefix = accesslog
#啟用按時(shí)間生成文件夾
a3.sinks.k3.hdfs.round = true
#設(shè)置round單位:小時(shí)
a3.sinks.k3.hdfs.roundValue = 1
a3.sinks.k3.hdfs.roundUnit = hour
#使用本地時(shí)間戳
a3.sinks.k3.hdfs.useLocalTimeStamp = true
# 設(shè)置每次寫入的DFS的event的個(gè)數(shù)為100個(gè)
a3.sinks.k3.hdfs.batchSize = 100
# 寫入HDFS的方式
a3.sinks.k3.hdfs.fileType = DataStream
# 寫入HDFS的文件格式
a3.sinks.k3.hdfs.writeFormat = Text
#設(shè)置解決文件過(guò)多過(guò)小問題
#每600秒生成一個(gè)文件
a3.sinks.k3.hdfs.rollInterval = 60
#當(dāng)達(dá)到128000000bytes時(shí),創(chuàng)建新文件 127*1024*1024
#實(shí)際環(huán)境中如果按照128M回顧文件,那么這里設(shè)置一般設(shè)置成127M
a3.sinks.k3.hdfs.rollSize = 128000000
#設(shè)置文件的生成不和events數(shù)相關(guān),與時(shí)間和大小相關(guān)
a3.sinks.k3.hdfs.rollCount = 0
#設(shè)置成1,否則當(dāng)有副本復(fù)制時(shí)就重新生成文件,上面三條則沒有效果
a3.sinks.k3.hdfs.minBlockReplicas =1
# Bind the source and sink to the channel
a3.sources.r3.channels = c3
a3.sinks.k3.channel = c3
===================================
2.啟動(dòng)Flume-agent a3
$ bin/flume-ng agent --conf conf --conf-file conf/a3.conf --name a3 -Dflume.root.logger=INFO,console
[擴(kuò)展]
Flume
http://m.blog.csdn.net/article/details?id=51892945
flume
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- flume 使用 kafka作為 sink ,exec 執(zhí)行命令作為source 1.1 安裝kafka和flum...
- 轉(zhuǎn)自http://www.aboutyun.com/thread-8317-1-1.html 問題導(dǎo)讀: 1.Fl...
- 本文將會(huì)介紹如何使用 Flume、log4j、Kafka進(jìn)行規(guī)范的日志采集。 Flume 基本概念 Flume是一...
- 最近搞日志處理,注意是日志處理,如果用流計(jì)算處理一些金融數(shù)據(jù)比如交易所的行情數(shù)據(jù),是不能這么“粗魯”的,后者必須還...
- 句子翻譯 1. The team contends that these bear more than a pas...